-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* making configs module global making configs import as dynamic aws removing configs imports everywhere else * support multi aws config sources, add tests * updating config split for the rest of the envs * linter
- Loading branch information
Showing
20 changed files
with
158 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
export default { | ||
aws: { | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-pre-prod', | ||
}, | ||
aws: [ | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-pre-prod', | ||
}, | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-configs-pre-prod', | ||
}, | ||
], | ||
//don't add anything else here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
export default { | ||
aws: { | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-prod', | ||
}, | ||
aws: [ | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-prod', | ||
}, | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-configs-prod', | ||
}, | ||
], | ||
//don't add anything else here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
export default { | ||
aws: { | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-staging', | ||
}, | ||
aws: [ | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-secrets-staging', | ||
}, | ||
{ | ||
region: 'us-east-2', | ||
secretID: 'eco-solver-configs-staging', | ||
}, | ||
], | ||
//don't add anything else here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
import { Module } from '@nestjs/common' | ||
import { DynamicModule, FactoryProvider, Global, Module, Provider } from '@nestjs/common' | ||
import { EcoConfigService } from './eco-config.service' | ||
import { AwsConfigService } from './aws-config.service' | ||
|
||
@Global() | ||
@Module({ | ||
providers: [ | ||
{ | ||
providers: [EcoConfigModule.createBaseProvider(), AwsConfigService], | ||
exports: [EcoConfigService, AwsConfigService], | ||
}) | ||
export class EcoConfigModule { | ||
static withAWS(): DynamicModule { | ||
return { | ||
global: true, | ||
module: EcoConfigModule, | ||
providers: [EcoConfigModule.createAwsProvider()], | ||
exports: [EcoConfigService], | ||
} | ||
} | ||
|
||
static base(): DynamicModule { | ||
return { | ||
global: true, | ||
module: EcoConfigModule, | ||
providers: [EcoConfigModule.createBaseProvider()], | ||
exports: [EcoConfigService], | ||
} | ||
} | ||
|
||
static createAwsProvider(): Provider { | ||
const dynamicConfig: FactoryProvider<EcoConfigService> = { | ||
provide: EcoConfigService, | ||
useFactory: async (awsConfigService: AwsConfigService) => { | ||
await awsConfigService.initConfigs() | ||
return new EcoConfigService(awsConfigService) | ||
return new EcoConfigService([awsConfigService]) | ||
}, | ||
inject: [AwsConfigService], | ||
}, | ||
AwsConfigService, | ||
], | ||
exports: [EcoConfigService, AwsConfigService], | ||
}) | ||
export class EcoConfigModule {} | ||
} | ||
return dynamicConfig | ||
} | ||
|
||
static createBaseProvider(): Provider { | ||
return EcoConfigService | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const mockConfigGet = jest.fn() | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
import { AwsConfigService } from '../aws-config.service' | ||
import { merge } from 'lodash' | ||
|
||
jest.mock('config', () => { | ||
return { | ||
get: mockConfigGet, | ||
} | ||
}) | ||
|
||
describe('Aws Config Helper Tests', () => { | ||
let awsConfigService: AwsConfigService | ||
let mockLog: jest.Mock | ||
let mockAwsGet: jest.Mock | ||
const awsConfigSingle = { region: 'us-florida', secretID: 'secrets' } | ||
const awsConfigSingleData = { key: 1, value: 'value1' } | ||
const awsConfigArray = [awsConfigSingle, { region: 'us-california', secretID: 'configs' }] | ||
const awsConfigArrayData = [awsConfigSingleData, { key: 3, value_second: 'value3' }] | ||
beforeEach(async () => { | ||
const configMod: TestingModule = await Test.createTestingModule({ | ||
providers: [AwsConfigService], | ||
}).compile() | ||
|
||
awsConfigService = configMod.get<AwsConfigService>(AwsConfigService) | ||
mockLog = jest.fn() | ||
mockAwsGet = jest.fn() | ||
}) | ||
|
||
it('should read single aws credential', async () => { | ||
mockConfigGet.mockReturnValue(awsConfigSingle) | ||
awsConfigService['getAwsSecrets'] = mockAwsGet.mockResolvedValue(awsConfigSingleData) | ||
await awsConfigService.initConfigs() | ||
expect(awsConfigService.getConfig()).toEqual(awsConfigSingleData) | ||
}) | ||
|
||
it('should read array of aws credentials', async () => { | ||
mockConfigGet.mockReturnValue(awsConfigArray) | ||
let index = 0 | ||
awsConfigService['getAwsSecrets'] = mockAwsGet.mockImplementation(() => { | ||
return awsConfigArrayData[index++] | ||
}) | ||
const me = {} | ||
awsConfigArrayData.forEach((data) => { | ||
merge(me, data) | ||
}) | ||
merge({}, ...awsConfigArrayData) | ||
|
||
await awsConfigService.initConfigs() | ||
expect(awsConfigService.getConfig()).toEqual(me) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.