Skip to content

Commit

Permalink
chore: addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kakha urigashvili committed May 6, 2020
1 parent f4d12f8 commit 08508b7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const CONSTANTS = require('@src/utils/constants');
const stringUtils = require('@src/utils/string-utils');


module.exports = class AbstractClient {
module.exports = class AbstractAwsClient {
constructor(configuration) {
const { awsProfile, awsRegion } = configuration;
if (!stringUtils.isNonBlankString(awsProfile) || !stringUtils.isNonBlankString(awsRegion)) {
Expand All @@ -16,6 +16,7 @@ module.exports = class AbstractClient {
});
}
this.awsRegion = awsRegion;
this.awsProfile = awsProfile;
aws.config.region = this.awsRegion;
}
};
4 changes: 2 additions & 2 deletions lib/clients/aws-client/cloudformation-client.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const aws = require('aws-sdk');
const R = require('ramda');
const stringUtils = require('@src/utils/string-utils');
const AbstractClient = require('./abstract-client');
const AbstractAwsClient = require('./abstract-aws-client');

/**
* Class for AWS Cloudformation Client
*/
module.exports = class CloudformationClient extends AbstractClient {
module.exports = class CloudformationClient extends AbstractAwsClient {
constructor(configuration) {
super(configuration);
this.client = new aws.CloudFormation();
Expand Down
4 changes: 2 additions & 2 deletions lib/clients/aws-client/iam-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const aws = require('aws-sdk');


const CONSTANTS = require('@src/utils/constants');
const AbstractClient = require('./abstract-client');
const AbstractAwsClient = require('./abstract-aws-client');

/**
* Class for AWS IAM Client
*/
module.exports = class IAMClient extends AbstractClient {
module.exports = class IAMClient extends AbstractAwsClient {
constructor(configuration) {
super(configuration);
this.client = new aws.IAM();
Expand Down
4 changes: 2 additions & 2 deletions lib/clients/aws-client/lambda-client.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const aws = require('aws-sdk');

const stringUtils = require('@src/utils/string-utils');
const AbstractClient = require('./abstract-client');
const AbstractAwsClient = require('./abstract-aws-client');

/**
* Class for Lambda Client
*/
module.exports = class LambdaClient extends AbstractClient {
module.exports = class LambdaClient extends AbstractAwsClient {
constructor(configuration) {
super(configuration);
this.client = new aws.Lambda();
Expand Down
4 changes: 2 additions & 2 deletions lib/clients/aws-client/s3-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const aws = require('aws-sdk');
const SpinnerView = require('@src/view/spinner-view');
const { ParallelStream } = require('@src/utils/stream-utility');
const CONSTANTS = require('@src/utils/constants');
const AbstractClient = require('./abstract-client');
const AbstractAwsClient = require('./abstract-aws-client');


/**
* Class for S3 client
*/
module.exports = class S3Client extends AbstractClient {
module.exports = class S3Client extends AbstractAwsClient {
constructor(configuration) {
super(configuration);

Expand Down
3 changes: 2 additions & 1 deletion lib/commands/abstract-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ const {
} = require('@src/commands/option-validator');
const AppConfig = require('@src/model/app-config');
const CONSTANTS = require('@src/utils/constants');
const metricClient = require('@src/utils/metrics');
const Messenger = require('@src/view/messenger');
const metricClient = require('@src/utils/metrics');
const profileHelper = require('@src/utils/profile-helper');


const packageJson = require('@root/package.json');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const aws = require('aws-sdk');
const CONSTANTS = require('@src/utils/constants');

const AbstractClient = require('@src/clients/aws-client/abstract-client');
const AbstractAwsClient = require('@src/clients/aws-client/abstract-aws-client');

describe('Clients test - abstract client test', () => {
const TEST_AWS_PROFILE = 'TEST_AWS_PROFILE';
Expand All @@ -18,30 +18,32 @@ describe('Clients test - abstract client test', () => {

describe('# constructor tests', () => {
it('| should set region and credentials profile', () => {
const client = new AbstractClient(configuration);
expect(client).to.be.instanceof(AbstractClient);
const client = new AbstractAwsClient(configuration);
expect(client).to.be.instanceof(AbstractAwsClient);
expect(client.awsRegion).eql(TEST_AWS_REGION);
expect(client.awsProfile).eql(TEST_AWS_PROFILE);
expect(aws.config.region).eql(TEST_AWS_REGION);
expect(aws.config.credentials.profile).eql(TEST_AWS_PROFILE);
});

it('| should not set credentials profile since using env variables', () => {
configuration.awsProfile = CONSTANTS.PLACEHOLDER.ENVIRONMENT_VAR.AWS_CREDENTIALS;
const client = new AbstractClient(configuration);
expect(client).to.be.instanceof(AbstractClient);
const client = new AbstractAwsClient(configuration);
expect(client).to.be.instanceof(AbstractAwsClient);
expect(client.awsRegion).eql(TEST_AWS_REGION);
expect(client.awsProfile).eql(CONSTANTS.PLACEHOLDER.ENVIRONMENT_VAR.AWS_CREDENTIALS);
expect(aws.config.region).eql(TEST_AWS_REGION);
expect(aws.config.credentials.profile).eql(null);
});

it('| should throw error when aws profile is not specified ', () => {
configuration.awsProfile = null;
expect(() => new AbstractClient(configuration)).to.throw('Invalid awsProfile or Invalid awsRegion');
expect(() => new AbstractAwsClient(configuration)).to.throw('Invalid awsProfile or Invalid awsRegion');
});

it('| should throw error when aws region is not specified ', () => {
configuration.awsRegion = null;
expect(() => new AbstractClient(configuration)).to.throw('Invalid awsProfile or Invalid awsRegion');
expect(() => new AbstractAwsClient(configuration)).to.throw('Invalid awsProfile or Invalid awsRegion');
});
});
});
2 changes: 1 addition & 1 deletion test/unit/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require('module-alias/register');
'@test/unit/clients/smapi-client-test',
'@test/unit/clients/git-client-test',
'@test/unit/clients/lwa-auth-code-client-test',
'@test/unit/clients/aws-client/abstract-client-test',
'@test/unit/clients/aws-client/abstract-aws-client-test',
'@test/unit/clients/aws-client/s3-client-test',
'@test/unit/clients/aws-client/cloudformation-client-test',
'@test/unit/clients/aws-client/aws-util-test',
Expand Down

0 comments on commit 08508b7

Please sign in to comment.