-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply tags on create and push nested stack (#6321)
* fix: apply tags on create and push nested stack
- Loading branch information
1 parent
9bf8b16
commit 4faa3e5
Showing
11 changed files
with
138 additions
and
62 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/amplify-cli-core/src/__tests__/statemanager.getTags.test.ts
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,35 @@ | ||
import { stateManager } from '../state-manager'; | ||
import { Tag } from '../tags'; | ||
describe('getTags', () => { | ||
const mockedTags: Tag[] = [ | ||
{ | ||
Key: 'projectName', | ||
Value: '{project-name}', | ||
}, | ||
{ | ||
Key: 'projectenv', | ||
Value: '{project-env}', | ||
}, | ||
]; | ||
const mockConfig = { | ||
projectConfig: { | ||
projectName: 'foo', | ||
}, | ||
localEnvInfo: { | ||
envName: 'bar', | ||
}, | ||
}; | ||
const mockGetProjectTags = jest.spyOn(stateManager, 'getProjectTags').mockReturnValue(mockedTags); | ||
const mockgetProjectConfig = jest.spyOn(stateManager, 'getProjectConfig').mockReturnValue(mockConfig.projectConfig); | ||
const mockgetLocalEnvInfo = jest.spyOn(stateManager, 'getLocalEnvInfo').mockReturnValue(mockConfig.localEnvInfo); | ||
|
||
it('test for values', () => { | ||
const readTags = stateManager.getHydratedTags(undefined); | ||
expect(readTags).toBeDefined(); | ||
expect(readTags.filter(r => r.Key === 'projectName')[0].Value).toEqual(mockConfig.projectConfig.projectName); | ||
expect(readTags.filter(r => r.Key === 'projectenv')[0].Value).toEqual(mockConfig.localEnvInfo.envName); | ||
expect(mockGetProjectTags).toBeCalled(); | ||
expect(mockgetProjectConfig).toBeCalled(); | ||
expect(mockgetLocalEnvInfo).toBeCalled(); | ||
}); | ||
}); |
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
36 changes: 11 additions & 25 deletions
36
packages/amplify-cli/src/extensions/amplify-helpers/get-tags.ts
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,27 +1,13 @@ | ||
import { stateManager, Tag } from 'amplify-cli-core'; | ||
import { getProjectDetails } from './get-project-details'; | ||
export function getTags(): Tag[] { | ||
const projectDetails = getProjectDetails(); | ||
const { projectName } = projectDetails.projectConfig; | ||
const { envName } = projectDetails.localEnvInfo; | ||
return HydrateTags(stateManager.getProjectTags(), { envName, projectName }); | ||
} | ||
import { stateManager, Tag, HydrateTags } from 'amplify-cli-core'; | ||
import { Context } from '../../domain/context'; | ||
|
||
function HydrateTags(tags: Tag[], tagVariables: TagVariables): Tag[] { | ||
const { envName, projectName } = tagVariables; | ||
const replace = { | ||
'{project-name}': projectName, | ||
'{project-env}': envName, | ||
}; | ||
return tags.map(tag => { | ||
return { | ||
...tag, | ||
Value: tag.Value.replace(/{project-name}|{project-env}/g, (matched: string) => replace[matched]), | ||
}; | ||
}); | ||
export function getTags(context: Context): Tag[] { | ||
if (stateManager.isTagFilePresent()) { | ||
return stateManager.getHydratedTags(); | ||
} else { | ||
const tags = context.exeInfo.initialTags; | ||
const { envName } = context.exeInfo.localEnvInfo; | ||
const { projectName } = context.exeInfo.projectConfig; | ||
return HydrateTags(tags, { envName, projectName }); | ||
} | ||
} | ||
|
||
type TagVariables = { | ||
envName: string; | ||
projectName: string; | ||
}; |
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