Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: get appstream setting optional bool (#633)
Browse files Browse the repository at this point in the history
* fix: get appstream setting optional bool

* fix: changing optionalBoolean to getBoolean

* fix: unit tests for getBoolean

* undo potential merge conflict
  • Loading branch information
SanketD92 authored Aug 5, 2021
1 parent 41527a2 commit 74c206a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ describe('accountService', () => {
delete inputMissingAppStreamData.appStreamImageName;
delete inputMissingAppStreamData.appStreamInstanceType;

settingsService.get = jest.fn(key => {
settingsService.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return 'true';
return true;
}
return undefined;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AccountService extends Service {
await validationService.ensureValid(rawData, createSchema);

let appStreamConfig = {};
if (this.settings.get(settingKeys.isAppStreamEnabled) === 'true') {
if (this.settings.getBoolean(settingKeys.isAppStreamEnabled)) {
const {
appStreamFleetDesiredInstances,
appStreamDisconnectTimeoutSeconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class AwsAccountsService extends Service {
});

// Only try to shareAppStreamImage with member account if AppStream is enabled and appStreamImageName is provided
if (this.settings.get(settingKeys.isAppStreamEnabled) === 'true' && rawData.appStreamImageName !== undefined) {
if (this.settings.getBoolean(settingKeys.isAppStreamEnabled) && rawData.appStreamImageName !== undefined) {
const appStreamImageName = rawData.appStreamImageName;
const accountId = rawData.accountId;
await this.shareAppStreamImageWithMemberAccount(requestContext, accountId, appStreamImageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class AwsCfnService extends Service {
fieldsToUpdate.id = accountEntity.id;
fieldsToUpdate.rev = accountEntity.rev;

if (this.settings.get(settingKeys.isAppStreamEnabled) === 'true') {
if (this.settings.getBoolean(settingKeys.isAppStreamEnabled)) {
fieldsToUpdate.subnetId = findOutputValue('PrivateWorkspaceSubnet');
fieldsToUpdate.appStreamStackName = findOutputValue('AppStreamStackName');
fieldsToUpdate.appStreamFleetName = findOutputValue('AppStreamFleet');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ProjectService extends Service {
const [dbService] = await this.service(['dbService']);
const table = this.settings.get(settingKeys.tableName);
this.userService = await this.service('userService');
this.isAppStreamEnabled = this.settings.get(settingKeys.isAppStreamEnabled) === 'true';
this.isAppStreamEnabled = this.settings.getBoolean(settingKeys.isAppStreamEnabled);

this._getter = () => dbService.helper.getter().table(table);
this._updater = () => dbService.helper.updater().table(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ describe('ProvisionAccount', () => {
it('AppStream: false', async () => {
// BUILD
step.settings = {
get: key => {
getBoolean: key => {
if (key === 'isAppStreamEnabled') {
return 'false';
return false;
}
throw new Error('Unexpected key');
},
Expand All @@ -116,9 +116,9 @@ describe('ProvisionAccount', () => {
it('AppStream: true', async () => {
// BUILD
step.settings = {
get: key => {
getBoolean: key => {
if (key === 'isAppStreamEnabled') {
return 'true';
return true;
}
throw new Error('Unexpected key');
},
Expand Down Expand Up @@ -273,9 +273,9 @@ describe('ProvisionAccount', () => {
it('AppStream: false', async () => {
// BUILD
step.settings = {
get: key => {
getBoolean: key => {
if (key === 'isAppStreamEnabled') {
return 'false';
return false;
}
throw new Error('Unexpected key');
},
Expand Down Expand Up @@ -351,9 +351,9 @@ describe('ProvisionAccount', () => {
it('AppStream: true', async () => {
// BUILD
step.settings = {
get: key => {
getBoolean: key => {
if (key === 'isAppStreamEnabled') {
return 'true';
return true;
}
throw new Error('Unexpected key');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ProvisionAccount extends StepBase {
// THIS IS NEEDED, we should wait AWS to setup the account, even if we can fetch the account ID
this.print('start to wait for 5 minutes for AWS getting the account ready.');

if (this.settings.get(settingKeys.isAppStreamEnabled) === 'true') {
if (this.settings.getBoolean(settingKeys.isAppStreamEnabled)) {
return this.wait(60 * 5).thenCall('shareImageWithMemberAccount');
}
return this.wait(60 * 5).thenCall('deployStack');
Expand Down Expand Up @@ -292,7 +292,7 @@ class ProvisionAccount extends StepBase {
permissionStatus: 'CURRENT',
};
let additionalAccountData = {};
if (this.settings.get(settingKeys.isAppStreamEnabled) === 'true') {
if (this.settings.getBoolean(settingKeys.isAppStreamEnabled)) {
// Start AppStream Fleet and wait for AppStream fleet to transition to RUNNING state
await this.startAppStreamFleet(cfnOutputs.AppStreamFleet);
const isAppStreamFleetRunning = await this.checkAppStreamFleetIsRunning(cfnOutputs.AppStreamFleet);
Expand Down Expand Up @@ -321,10 +321,9 @@ class ProvisionAccount extends StepBase {
cfnInfo: {
stackId,
vpcId: cfnOutputs.VPC,
subnetId:
this.settings.get(settingKeys.isAppStreamEnabled) === 'true'
? cfnOutputs.PrivateWorkspaceSubnet
: cfnOutputs.VpcPublicSubnet1,
subnetId: this.settings.getBoolean(settingKeys.isAppStreamEnabled)
? cfnOutputs.PrivateWorkspaceSubnet
: cfnOutputs.VpcPublicSubnet1,
crossAccountExecutionRoleArn: cfnOutputs.CrossAccountExecutionRoleArn,
crossAccountEnvMgmtRoleArn: cfnOutputs.CrossAccountEnvMgmtRoleArn,
encryptionKeyArn: cfnOutputs.EncryptionKeyArn,
Expand Down
2 changes: 1 addition & 1 deletion addons/addon-base/packages/services/lib/s3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class S3Service extends Service {
await s3Client.putObject(params).promise();
} catch (error) {
throw this.boom.badRequest(
`S3Service error with putting object to bukcet: ${params.Bucket} with key: ${params.Key}`,
`S3Service error with putting object to bucket: ${params.Bucket} with key: ${params.Key}`,
true,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ describe('UpdateCfnStackPolicy', () => {
service = await container.find('UpdateCfnStackPolicy');
settings = await container.find('settings');
settings.get = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return true;
}
if (key === 'enableEgressStore') {
return 'true';
}
Expand All @@ -60,6 +57,12 @@ describe('UpdateCfnStackPolicy', () => {
}
return undefined;
});
settings.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return true;
}
return undefined;
});
});

describe('Run post deployment step', () => {
Expand Down Expand Up @@ -366,9 +369,6 @@ describe('UpdateCfnStackPolicy', () => {
],
};
settings.get = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
if (key === 'enableEgressStore') {
return 'true';
}
Expand All @@ -377,6 +377,12 @@ describe('UpdateCfnStackPolicy', () => {
}
return undefined;
});
settings.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
return undefined;
});
service.cfn.getStackPolicy = jest.fn(() => ({
promise: () =>
Promise.resolve({
Expand Down Expand Up @@ -416,9 +422,6 @@ describe('UpdateCfnStackPolicy', () => {
],
};
settings.get = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return true;
}
if (key === 'enableEgressStore') {
return 'false';
}
Expand All @@ -427,6 +430,12 @@ describe('UpdateCfnStackPolicy', () => {
}
return undefined;
});
settings.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return true;
}
return undefined;
});
service.cfn.getStackPolicy = jest.fn(() => ({
promise: () =>
Promise.resolve({
Expand All @@ -444,9 +453,6 @@ describe('UpdateCfnStackPolicy', () => {

it('should not update policy when Egress was disabled, but it was previously enabled', async () => {
settings.get = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
if (key === 'enableEgressStore') {
return 'false';
}
Expand All @@ -455,6 +461,12 @@ describe('UpdateCfnStackPolicy', () => {
}
return undefined;
});
settings.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
return undefined;
});
service.cfn.getStackPolicy = jest.fn();
service.cfn.setStackPolicy = jest.fn();

Expand All @@ -465,9 +477,6 @@ describe('UpdateCfnStackPolicy', () => {

it('should not update policy when AppStream was disabled, but it was previously enabled', async () => {
settings.get = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
if (key === 'enableEgressStore') {
return 'false';
}
Expand All @@ -476,6 +485,12 @@ describe('UpdateCfnStackPolicy', () => {
}
return undefined;
});
settings.getBoolean = jest.fn(key => {
if (key === 'isAppStreamEnabled') {
return false;
}
return undefined;
});
service.cfn.getStackPolicy = jest.fn();
service.cfn.setStackPolicy = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class UpdateCfnStackPolicy extends Service {
async execute() {
const enableEgressStore = this.settings.get(settingKeys.enableEgressStore);
const isEgressStoreEnabled = enableEgressStore ? enableEgressStore.toUpperCase() === 'TRUE' : false;
const isAppStreamEnabled = this.settings.get(settingKeys.isAppStreamEnabled);
const isAppStreamEnabled = this.settings.getBoolean(settingKeys.isAppStreamEnabled);

if (!isEgressStoreEnabled && !isAppStreamEnabled) {
this.log.info('AppStream and EgressStore disabled. CFN stack policy does not need updates');
Expand Down

0 comments on commit 74c206a

Please sign in to comment.