This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
393 additions
and
54 deletions.
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
...ckages/base-raas-appstream-services/lib/plugins/__tests__/aws-account-mgmt-plugin.test.js
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,165 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
const ServicesContainer = require('@aws-ee/base-services-container/lib/services-container'); | ||
|
||
// Mocked dependencies | ||
jest.mock('@aws-ee/base-services/lib/plugin-registry/plugin-registry-service'); | ||
const PluginRegistryService = require('@aws-ee/base-services/lib/plugin-registry/plugin-registry-service'); | ||
|
||
jest.mock('@aws-ee/base-services/lib/settings/env-settings-service'); | ||
const SettingsServiceMock = require('@aws-ee/base-services/lib/settings/env-settings-service'); | ||
|
||
jest.mock('@aws-ee/base-raas-services/lib/environment/service-catalog/environment-sc-service'); | ||
const EnvironmentScServiceMock = require('@aws-ee/base-raas-services/lib/environment/service-catalog/environment-sc-service'); | ||
|
||
jest.mock('@aws-ee/base-raas-services/lib/indexes/indexes-service'); | ||
const IndexesServiceMock = require('@aws-ee/base-raas-services/lib/indexes/indexes-service'); | ||
|
||
const plugin = require('../aws-account-mgmt-plugin'); | ||
|
||
// CHECKed Functions: getActiveNonAppStreamEnvs | ||
describe('awsAccountMgmtPlugin', () => { | ||
let container; | ||
let settings; | ||
let environmentScService; | ||
let indexesService; | ||
beforeEach(async () => { | ||
// Initialize services container and register dependencies | ||
container = new ServicesContainer(); | ||
container.register('pluginRegistryService', new PluginRegistryService()); | ||
container.register('settings', new SettingsServiceMock()); | ||
container.register('environmentScService', new EnvironmentScServiceMock()); | ||
container.register('indexesService', new IndexesServiceMock()); | ||
|
||
await container.initServices(); | ||
settings = await container.find('settings'); | ||
environmentScService = await container.find('environmentScService'); | ||
indexesService = await container.find('indexesService'); | ||
}); | ||
|
||
describe('getActiveNonAppStreamEnvs', () => { | ||
const requestContext = { principalIdentifier: { uid: 'u-testuser' } }; | ||
it('should return empty list if AppStream is disabled', async () => { | ||
// BUILD | ||
const awsAccountId = 'sampleAwsAccountId'; | ||
settings.getBoolean = jest.fn(() => { | ||
return false; | ||
}); | ||
const expected = []; | ||
|
||
// OPERATE | ||
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }); | ||
|
||
// CHECK | ||
expect(retVal).toEqual(expected); | ||
}); | ||
|
||
it('should return a list of active non-AppStream environments for an account if AppStream is enabled', async () => { | ||
// BUILD | ||
const awsAccountId = 'sampleAwsAccountId'; | ||
settings.getBoolean = jest.fn(() => { | ||
return true; | ||
}); | ||
const scEnvs = [ | ||
{ id: 'env1', indexId: 'index1', isAppStreamConfigured: true, status: 'COMPLETED' }, | ||
{ id: 'env2', indexId: 'index1', isAppStreamConfigured: false, status: 'COMPLETED' }, // This will be returned | ||
{ id: 'env3', indexId: 'index1', isAppStreamConfigured: false, status: 'FAILED' }, | ||
{ id: 'env4', indexId: 'index1', isAppStreamConfigured: false, status: 'TERMINATED' }, | ||
{ id: 'env5', indexId: 'index1', isAppStreamConfigured: false, status: 'UNKNOWN' }, | ||
]; | ||
const indexes = [ | ||
{ id: 'index1', awsAccountId }, | ||
{ id: 'index2', awsAccountId: 'someOtherAccount' }, | ||
]; | ||
environmentScService.list = jest.fn(() => { | ||
return scEnvs; | ||
}); | ||
indexesService.list = jest.fn(() => { | ||
return indexes; | ||
}); | ||
|
||
const expected = [{ id: 'env2', indexId: 'index1', isAppStreamConfigured: false, status: 'COMPLETED' }]; | ||
|
||
// OPERATE | ||
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }); | ||
|
||
// CHECK | ||
expect(retVal).toEqual(expected); | ||
}); | ||
|
||
it('should return an empty list if no active non-AppStream environments for an account are found', async () => { | ||
// BUILD | ||
const awsAccountId = 'sampleAwsAccountId'; | ||
settings.getBoolean = jest.fn(() => { | ||
return true; | ||
}); | ||
const scEnvs = [ | ||
{ id: 'env1', indexId: 'index1', isAppStreamConfigured: true, status: 'COMPLETED' }, | ||
{ id: 'env2', indexId: 'index1', isAppStreamConfigured: false, status: 'TERMINATED' }, | ||
{ id: 'env3', indexId: 'index1', isAppStreamConfigured: false, status: 'FAILED' }, | ||
{ id: 'env4', indexId: 'index1', isAppStreamConfigured: false, status: 'UNKNOWN' }, | ||
]; | ||
const indexes = [ | ||
{ id: 'index1', awsAccountId }, | ||
{ id: 'index2', awsAccountId: 'someOtherAccount' }, | ||
]; | ||
environmentScService.list = jest.fn(() => { | ||
return scEnvs; | ||
}); | ||
indexesService.list = jest.fn(() => { | ||
return indexes; | ||
}); | ||
|
||
const expected = []; | ||
|
||
// OPERATE | ||
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }); | ||
|
||
// CHECK | ||
expect(retVal).toEqual(expected); | ||
}); | ||
|
||
it('should return an empty list if active non-AppStream environments exist but for a different account', async () => { | ||
// BUILD | ||
const awsAccountId = 'sampleAwsAccountId'; | ||
settings.getBoolean = jest.fn(() => { | ||
return true; | ||
}); | ||
const scEnvs = [ | ||
{ id: 'env1', indexId: 'index1', isAppStreamConfigured: true, status: 'COMPLETED' }, | ||
{ id: 'env2', indexId: 'index1', isAppStreamConfigured: false, status: 'STOPPED' }, | ||
]; | ||
const indexes = [ | ||
{ id: 'index1', awsAccountId: 'someOtherAccount' }, | ||
{ id: 'index2', awsAccountId }, | ||
]; | ||
environmentScService.list = jest.fn(() => { | ||
return scEnvs; | ||
}); | ||
indexesService.list = jest.fn(() => { | ||
return indexes; | ||
}); | ||
|
||
const expected = []; | ||
|
||
// OPERATE | ||
const retVal = await plugin.getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }); | ||
|
||
// CHECK | ||
expect(retVal).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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
57 changes: 57 additions & 0 deletions
57
...as-appstream/packages/base-raas-appstream-services/lib/plugins/aws-account-mgmt-plugin.js
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,57 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
const _ = require('lodash'); | ||
|
||
const settingKeys = { | ||
isAppStreamEnabled: 'isAppStreamEnabled', | ||
}; | ||
|
||
/** | ||
* Returns a list of active non-AppStream environments linked to a given AWS Account ID | ||
* This check is only performed when the deployment has AppStream enabled, | ||
* and is triggered if the user attempts to update the AWS account using SWB APIs. | ||
* A similar check is performed on the UI components (AccountUtils) as well. | ||
*/ | ||
async function getActiveNonAppStreamEnvs({ awsAccountId }, { requestContext, container }) { | ||
const settings = await container.find('settings'); | ||
const isAppStreamEnabled = settings.getBoolean(settingKeys.isAppStreamEnabled); | ||
if (!isAppStreamEnabled) return []; | ||
|
||
const nonActiveStates = ['FAILED', 'TERMINATED', 'UNKNOWN']; | ||
const environmentScService = await container.find('environmentScService'); | ||
const indexesService = await container.find('indexesService'); | ||
|
||
const indexes = await indexesService.list(requestContext); | ||
const indexesIdsOfInterest = _.map( | ||
_.filter(indexes, index => index.awsAccountId === awsAccountId), | ||
'id', | ||
); | ||
|
||
const scEnvs = await environmentScService.list(requestContext); | ||
const retVal = _.filter( | ||
scEnvs, | ||
scEnv => | ||
_.includes(indexesIdsOfInterest, scEnv.indexId) && | ||
!scEnv.isAppStreamConfigured && | ||
!_.includes(nonActiveStates, scEnv.status), | ||
); | ||
|
||
return retVal; | ||
} | ||
|
||
const plugin = { getActiveNonAppStreamEnvs }; | ||
|
||
module.exports = plugin; |
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
4 changes: 2 additions & 2 deletions
4
addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/accounts/AccountUtils.js
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.