Skip to content

Commit

Permalink
feature/add support to fetch recursively (#6)
Browse files Browse the repository at this point in the history
* Support recursive option
* Enhance documentation
  • Loading branch information
albertomr86 committed Sep 23, 2023
1 parent e37bc52 commit 0755b98
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PSConfigModule } from 'nestjs-param-store';
PSConfigModule.register({
ssmParamStorePath: '/production/services/my-service',
ssmDecryptParams: true,
ssmRecursive: false,
ssmClientOptions: {
region: 'us-east-1',
},
Expand Down Expand Up @@ -48,6 +49,7 @@ import { PSConfigModule } from 'nestjs-param-store';
useFactory: async (config: ConfigService<EnvironmentVariables>) => ({
ssmParamStorePath: config.get<string>('APP_CONFIG_PATH'),
ssmDecryptParams: true,
ssmRecursive: false,
ssmClientOptions: {
region: config.get<string>('AWS_REGION'),
},
Expand All @@ -59,6 +61,15 @@ import { PSConfigModule } from 'nestjs-param-store';
export class AppModule {}
```

## Options

| Option | Required | Default | Description |
|------------------- |---------- |------------- |------------------------------------------------------------------- |
| ssmParamStorePath | Yes | | The hierarchy for the parameter |
| ssmDecryptParams | No | `false` | Retrieve all parameters in a hierarchy with their value decrypted |
| ssmRecursive | No | `false` | Retrieve all parameters within a hierarchy |
| ssmClientOptions | No | `undefined` | Options to pass to the underlying SSM client |

## Services

This module exposes the following services.
Expand Down Expand Up @@ -172,3 +183,26 @@ Example of output:
}
]
```

## Troubleshooting

### Empty list of parameters returned

This happens when `recursive` is `false` and the specified path does not resolve the final level in the hierarchy.

[Reference: GetParametersByPath](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetParametersByPath.html#API_GetParametersByPath_RequestSyntax)

```typescript
import { Module } from '@nestjs/common';
import { PSConfigModule } from 'nestjs-param-store';

@Module({
imports: [
PSConfigModule.register({
ssmParamStorePath: '/production',
ssmRecursive: true, // <-- specify recursively
}),
],
})
export class AppModule {}
```
1 change: 1 addition & 0 deletions lib/interfaces/config-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { SSMClientConfig } from '@aws-sdk/client-ssm';
export interface PSConfigOptions {
ssmParamStorePath: string;
ssmDecryptParams?: boolean;
ssmRecursive?: boolean;
ssmClientOptions?: SSMClientConfig;
}
1 change: 1 addition & 0 deletions lib/providers/config-parameters.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const configParametersProvider: FactoryProvider<PSConfigParameters> = {
return psService.getParametersByPath(
configOptions.ssmParamStorePath,
configOptions.ssmDecryptParams ?? false,
configOptions.ssmRecursive ?? false,
);
},
inject: [PS_CONFIG_OPTIONS, ParameterStoreService],
Expand Down
2 changes: 2 additions & 0 deletions lib/services/parameter-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ParameterStoreService {
public async getParametersByPath(
path: string,
decrypt = false,
recursive = false,
): Promise<Parameter[]> {
let allParameters: Parameter[] = [];
let nextParametersToken: string | undefined;
Expand All @@ -23,6 +24,7 @@ export class ParameterStoreService {
Path: path,
WithDecryption: decrypt,
NextToken: nextParametersToken,
Recursive: recursive,
});

const { Parameters = [], NextToken } = await this.client.send(
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestjs-param-store",
"version": "1.1.0",
"version": "1.2.0",
"description": "Configure your NestJS application with AWS Parameter Store",
"author": "Alberto Menendez Romero <[email protected]>",
"keywords": [
Expand Down

0 comments on commit 0755b98

Please sign in to comment.