Skip to content

Commit 769537d

Browse files
authored
Handle AWS Account IDs with leading zeros (#295)
* Handle AWS Account IDs with leading zeros - Fixes #294 * Do not set Account ID if not known * More account ID fixes
1 parent 73d9802 commit 769537d

File tree

18 files changed

+39
-38
lines changed

18 files changed

+39
-38
lines changed

packages/microapps-deployer/src/config/Config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IConfig {
1515
readonly apigwy: IAPIGateway;
1616
readonly filestore: IFileStore;
1717

18-
readonly awsAccountID: number;
18+
readonly awsAccountID: string;
1919
readonly awsRegion: string;
2020

2121
readonly uploadRoleName: string;
@@ -95,10 +95,10 @@ export class Config implements IConfig {
9595

9696
@convict.Property({
9797
doc: 'AWS Account ID for app Lambda function',
98-
default: 0,
98+
default: '',
9999
env: 'AWS_ACCOUNT_ID',
100100
})
101-
public awsAccountID!: number;
101+
public awsAccountID!: string;
102102

103103
@convict.Property({
104104
doc: 'AWS Region for app Lambda function',

packages/microapps-deployer/src/controllers/VersionController.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Config, IConfig } from '../config/Config';
55
jest.mock('../config/Config');
66
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
77
const theConfig: Writeable<IConfig> = {
8-
awsAccountID: 123456789,
8+
awsAccountID: '00123456789',
99
awsRegion: 'mock',
1010
db: {
1111
tableName: 'microapps',

packages/microapps-deployer/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export async function handler(
5353
}
5454

5555
// Get the current AWS Account ID, once, if not set as env var
56-
if (config.awsAccountID === 0 && context?.invokedFunctionArn !== undefined) {
56+
if (config.awsAccountID === '' && context?.invokedFunctionArn !== undefined) {
5757
const parts = context.invokedFunctionArn.split(':');
5858
const accountIDStr = parts[4];
5959
if (accountIDStr !== '') {
6060
// @ts-expect-error we want to overwrite this config value
61-
config.awsAccountID = parseInt(accountIDStr, 10);
61+
config.awsAccountID = accountIDStr;
6262
}
6363
}
6464

packages/microapps-edge-to-origin/src/config/config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type IPartialConfig = Partial<Config>;
1010
describe('config', () => {
1111
it('handles funky string enum', () => {
1212
const rawConfig: IConfig = {
13-
awsAccountID: 123,
13+
awsAccountID: '123',
1414
awsRegion: 'us-east-1',
1515
originRegion: 'us-east-2',
1616
addXForwardedHostHeader: true,
@@ -23,7 +23,7 @@ describe('config', () => {
2323
const config = loader.load(rawConfig);
2424

2525
expect(config).toBeDefined();
26-
expect(config.awsAccountID).toBe(123);
26+
expect(config.awsAccountID).toBe('123');
2727
expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-1');
2828
expect(config.originRegion).toBe('us-east-2');
2929
expect(config.addXForwardedHostHeader).toBe(true);
@@ -37,7 +37,7 @@ describe('config', () => {
3737
const config = loader.load(rawConfig);
3838

3939
expect(config).toBeDefined();
40-
expect(config.awsAccountID).toBe(0);
40+
expect(config.awsAccountID).toBe('');
4141
expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-1');
4242
expect(config.originRegion).toBe('us-east-2');
4343
expect(config.addXForwardedHostHeader).toBe(true);
@@ -50,7 +50,7 @@ describe('config', () => {
5050
const config = loader.load(path.join(__dirname, './config.test.yml'));
5151

5252
expect(config).toBeDefined();
53-
expect(config.awsAccountID).toBe(0);
53+
expect(config.awsAccountID).toBe('00123456');
5454
expect(config.awsRegion).toBe(process.env.AWS_REGION || 'us-east-2');
5555
expect(config.originRegion).toBe('us-east-2');
5656
expect(config.addXForwardedHostHeader).toBe(true);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
awsRegion: us-east-2
22
originRegion: us-east-2
33
signingMode: sign
4-
replaceHostHeader: true
4+
replaceHostHeader: true
5+
awsAccountID: '00123456'

packages/microapps-edge-to-origin/src/config/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FilesExist } from '../lib/files-exist';
77
* Represents a Config
88
*/
99
export interface IConfig {
10-
readonly awsAccountID: number;
10+
readonly awsAccountID: string;
1111
readonly awsRegion: string;
1212

1313
/**
@@ -112,10 +112,10 @@ export class Config implements IConfig {
112112

113113
@convict.Property({
114114
doc: 'AWS Account ID for app Lambda function',
115-
default: 0,
115+
default: '',
116116
env: 'AWS_ACCOUNT_ID',
117117
})
118-
public awsAccountID!: number;
118+
public awsAccountID!: string;
119119

120120
@convict.Property({
121121
doc: 'AWS Region for app Lambda function',

packages/microapps-edge-to-origin/src/index.route.prefix.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
88
jest.mock('./config/config');
99
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
1010
const theConfig: Writeable<IConfig> = {
11-
awsAccountID: 123456,
11+
awsAccountID: '00123456',
1212
awsRegion: 'mock',
1313
addXForwardedHostHeader: false,
1414
originRegion: 'us-west-1',

packages/microapps-edge-to-origin/src/index.route.root.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
88
jest.mock('./config/config');
99
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
1010
const theConfig: Writeable<IConfig> = {
11-
awsAccountID: 123456,
11+
awsAccountID: '00123456',
1212
awsRegion: 'mock',
1313
addXForwardedHostHeader: false,
1414
originRegion: 'us-west-1',

packages/microapps-edge-to-origin/src/index.route.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Config, IConfig } from './config/config';
88
jest.mock('./config/config');
99
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
1010
const theConfig: Writeable<IConfig> = {
11-
awsAccountID: 123456,
11+
awsAccountID: '00123456',
1212
awsRegion: 'mock',
1313
addXForwardedHostHeader: false,
1414
originRegion: 'us-west-1',

packages/microapps-edge-to-origin/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Config, IConfig } from './config/config';
55
jest.mock('./config/config');
66
type Writeable<T> = { -readonly [P in keyof T]: T[P] };
77
const theConfig: Writeable<IConfig> = {
8-
awsAccountID: 123456,
8+
awsAccountID: '00123456',
99
awsRegion: 'mock',
1010
addXForwardedHostHeader: false,
1111
originRegion: 'us-west-1',

0 commit comments

Comments
 (0)