Skip to content

Commit

Permalink
Add support to decrypt params (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomr86 committed Jan 8, 2023
1 parent 856d6f2 commit 0a0a4d6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This package allows you to configure your NestJS application by loading the conf
```bash
npm install nestjs-param-store @aws-sdk/client-ssm
```

## Configuration

### Static configuration
Expand All @@ -19,6 +20,7 @@ import { PSConfigModule } from 'nestjs-param-store';
imports: [
PSConfigModule.register({
ssmParamStorePath: '/production/services/my-service',
ssmDecryptParams: true,
ssmClientOptions: {
region: 'us-east-1',
},
Expand All @@ -45,6 +47,7 @@ import { PSConfigModule } from 'nestjs-param-store';
imports: [ConfigModule],
useFactory: async (config: ConfigService<EnvironmentVariables>) => ({
ssmParamStorePath: config.get<string>('APP_CONFIG_PATH'),
ssmDecryptParams: true,
ssmClientOptions: {
region: config.get<string>('AWS_REGION'),
},
Expand Down
1 change: 1 addition & 0 deletions lib/interfaces/config-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { SSMClientConfig } from '@aws-sdk/client-ssm';

export interface PSConfigOptions {
ssmParamStorePath: string;
ssmDecryptParams?: boolean;
ssmClientOptions?: SSMClientConfig;
}
5 changes: 4 additions & 1 deletion lib/providers/config-parameters.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export const configParametersProvider: FactoryProvider<PSConfigParameters> = {
configOptions: PSConfigOptions,
psService: ParameterStoreService,
): Promise<PSConfigParameters> => {
return psService.getParametersByPath(configOptions.ssmParamStorePath);
return psService.getParametersByPath(
configOptions.ssmParamStorePath,
configOptions.ssmDecryptParams ?? false,
);
},
inject: [PS_CONFIG_OPTIONS, ParameterStoreService],
};
6 changes: 5 additions & 1 deletion lib/services/parameter-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export class ParameterStoreService {
@Inject(SSM_PS_CLIENT) private readonly client: SSMClient,
) {}

public async getParametersByPath(path: string): Promise<Parameter[]> {
public async getParametersByPath(
path: string,
decrypt = false,
): Promise<Parameter[]> {
const getParameters = new GetParametersByPathCommand({
Path: path,
WithDecryption: decrypt,
});

const { Parameters = [] } = await this.client.send(getParameters);
Expand Down
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.0.0",
"version": "1.1.0",
"description": "Configure your NestJS application with AWS Parameter Store",
"author": "Alberto Menendez Romero <[email protected]>",
"keywords": [
Expand Down

0 comments on commit 0a0a4d6

Please sign in to comment.