Skip to content

Commit

Permalink
refactor(amazon): prepare amazon for library build
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed May 19, 2017
1 parent bd97d09 commit a050ddb
Show file tree
Hide file tree
Showing 28 changed files with 132 additions and 100 deletions.
1 change: 0 additions & 1 deletion app/scripts/modules/amazon/aws.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = angular.module('spinnaker.aws', [
require('./instance/details/instance.details.controller.js'),
require('./securityGroup/details/securityGroupDetail.controller.js'),
require('./securityGroup/configure/CreateSecurityGroupCtrl.js'),
require('./keyPairs/keyPairs.read.service.js'),
require('./securityGroup/configure/EditSecurityGroupCtrl.js'),
require('./securityGroup/securityGroup.transformer.js'),
require('./securityGroup/securityGroup.reader.js'),
Expand Down
8 changes: 5 additions & 3 deletions app/scripts/modules/amazon/cache/cacheConfigurer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
SUBNET_READ_SERVICE
} from '@spinnaker/core';

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular.module('spinnaker.aws.cache.initializer', [
ACCOUNT_SERVICE,
LOAD_BALANCER_READ_SERVICE,
INSTANCE_TYPE_SERVICE,
SUBNET_READ_SERVICE,
require('../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
])
.factory('awsCacheConfigurer', function ($q,
accountService, instanceTypeService,
Expand All @@ -41,8 +43,8 @@ module.exports = angular.module('spinnaker.aws.cache.initializer', [

config.networks = {
version: 2,
initializers: [vpcReader.listVpcs],
onReset: [vpcReader.resetCache],
initializers: [() => vpcReader.listVpcs() ],
onReset: [() => vpcReader.resetCache() ],
};

return config;
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/modules/amazon/domain/IKeyPair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IKeyPair {
account: string;
region: string;
keyName: string;
keyFingerprint: string;
}
1 change: 1 addition & 0 deletions app/scripts/modules/amazon/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './IKeyPair';
5 changes: 5 additions & 0 deletions app/scripts/modules/amazon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './domain';

export * from './keyPairs';

export * from './vpc';
1 change: 1 addition & 0 deletions app/scripts/modules/amazon/keyPairs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './keyPairs.read.service';
22 changes: 0 additions & 22 deletions app/scripts/modules/amazon/keyPairs/keyPairs.read.service.js

This file was deleted.

20 changes: 20 additions & 0 deletions app/scripts/modules/amazon/keyPairs/keyPairs.read.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { module, IPromise } from 'angular';

import { API_SERVICE, Api } from '@spinnaker/core';

import { IKeyPair } from 'amazon/domain';

export class KeyPairsReader {

constructor(private API: Api) {
'ngInject';
}

public listKeyPairs(): IPromise<IKeyPair[]> {
return this.API.all('keyPairs').useCache().getList()
.then((keyPairs: IKeyPair[]) => keyPairs.sort((a, b) => a.keyName.localeCompare(b.keyName)));
}
}

export const KEY_PAIRS_READ_SERVICE = 'spinnaker.amazon.keyPairs.read.service';
module(KEY_PAIRS_READ_SERVICE, [API_SERVICE]).service('keyPairsReader', KeyPairsReader);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const angular = require('angular');
import _ from 'lodash';

import { AWSProviderSettings } from '../aws.settings';
import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular.module('spinnaker.aws.loadBalancer.transformer', [
require('../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
])
.factory('awsLoadBalancerTransformer', function (vpcReader) {

Expand Down
4 changes: 3 additions & 1 deletion app/scripts/modules/amazon/search/searchResultFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

const angular = require('angular');

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular
.module('spinnaker.amazon.search.searchResultFormatter', [
require('../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
])
.factory('awsSearchResultFormatter', function(vpcReader) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import _ from 'lodash';

import { ACCOUNT_SERVICE } from '@spinnaker/core';

import { VPC_READ_SERVICE } from 'amazon/vpc/vpc.read.service';

module.exports = angular
.module('spinnaker.amazon.securityGroup.clone.controller', [
ACCOUNT_SERVICE,
require('../../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
require('../configure/configSecurityGroup.mixin.controller.js')
])
.controller('awsCloneSecurityGroupController', function($scope, $uibModalInstance, $controller, accountService, securityGroup, application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const angular = require('angular');
import _ from 'lodash';
import { Subject } from 'rxjs';

import { AWSProviderSettings } from 'amazon/aws.settings';

import {
ACCOUNT_SERVICE,
SECURITY_GROUP_READER,
Expand All @@ -14,14 +12,17 @@ import {
V2_MODAL_WIZARD_SERVICE
} from '@spinnaker/core';

import { AWSProviderSettings } from 'amazon/aws.settings';
import { VPC_READ_SERVICE } from 'amazon/vpc/vpc.read.service';

module.exports = angular
.module('spinnaker.amazon.securityGroup.baseConfig.controller', [
require('angular-ui-router').default,
TASK_MONITOR_BUILDER,
SECURITY_GROUP_READER,
SECURITY_GROUP_WRITER,
ACCOUNT_SERVICE,
require('../../vpc/vpc.read.service'),
VPC_READ_SERVICE,
V2_MODAL_WIZARD_SERVICE,
require('./ingressRuleGroupSelector.component'),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

const angular = require('angular');

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular.module('spinnaker.aws.securityGroup.transformer', [
require('../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
])
.factory('awsSecurityGroupTransformer', function (vpcReader) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import {
SUBNET_READ_SERVICE
} from '@spinnaker/core';

import { KEY_PAIRS_READ_SERVICE } from 'amazon/keyPairs/keyPairs.read.service';

module.exports = angular.module('spinnaker.aws.serverGroup.configure.service', [
require('../../image/image.reader.js'),
ACCOUNT_SERVICE,
NAMING_SERVICE,
SECURITY_GROUP_READER,
SUBNET_READ_SERVICE,
require('../../instance/awsInstanceType.service.js'),
require('../../keyPairs/keyPairs.read.service.js'),
KEY_PAIRS_READ_SERVICE,
LOAD_BALANCER_READ_SERVICE,
CACHE_INITIALIZER_SERVICE,
SERVER_GROUP_COMMAND_REGISTRY_PROVIDER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const angular = require('angular');
import _ from 'lodash';

const angular = require('angular');
import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular.module('spinnaker.aws.serverGroup.transformer', [
require('../vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
])
.factory('awsServerGroupTransformer', function (vpcReader) {

Expand Down
1 change: 1 addition & 0 deletions app/scripts/modules/amazon/vpc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './vpc.read.service';
2 changes: 1 addition & 1 deletion app/scripts/modules/amazon/vpc/vpc.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const angular = require('angular');

module.exports = angular
.module('spinnaker.vpc', [
require('./vpc.read.service.js')
require('./vpcTag.directive')
]);
52 changes: 0 additions & 52 deletions app/scripts/modules/amazon/vpc/vpc.read.service.js

This file was deleted.

4 changes: 3 additions & 1 deletion app/scripts/modules/amazon/vpc/vpc.read.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import { API_SERVICE } from '@spinnaker/core';

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

describe('vpcReader', function() {

var service, $http, $scope, API;

beforeEach(
window.module(
require('./vpc.read.service.js'),
VPC_READ_SERVICE,
API_SERVICE
)
);
Expand Down
46 changes: 46 additions & 0 deletions app/scripts/modules/amazon/vpc/vpc.read.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { module, IQService, IPromise } from 'angular';

import { IVpc, NETWORK_READ_SERVICE, NetworkReader } from '@spinnaker/core';

export class VpcReader {

private cachedVpcs: IVpc[];

constructor(private $q: IQService, private networkReader: NetworkReader) {
'ngInject';
}

public listVpcs(): IPromise<IVpc[]> {
if (this.cachedVpcs) {
return this.$q.when(this.cachedVpcs);
}
return this.networkReader.listNetworksByProvider('aws').then((vpcs: IVpc[]) => {
const results = vpcs.map(vpc => {
vpc.label = vpc.name;
vpc.deprecated = !!vpc.deprecated;
if (vpc.deprecated) {
vpc.label += ' (deprecated)';
}
return vpc;
});
this.cachedVpcs = results;
return results;
});
}

public resetCache() {
this.cachedVpcs = null;
}

public getVpcName(id: string) {
return this.listVpcs().then(vpcs => {
const match = vpcs.find(test => {
return test.id === id;
});
return match ? match.name : null;
});
}
}

export const VPC_READ_SERVICE = 'spinnaker.amazon.vpc.read.service';
module(VPC_READ_SERVICE, [NETWORK_READ_SERVICE]).service('vpcReader', VpcReader);
4 changes: 3 additions & 1 deletion app/scripts/modules/amazon/vpc/vpcTag.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

const angular = require('angular');

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

module.exports = angular.module('spinnaker.vpc.tag.directive', [
require('./vpc.read.service.js'),
VPC_READ_SERVICE,
])
.directive('vpcTag', function(vpcReader) {
return {
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/modules/amazon/vpc/vpcTag.directive.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

import { VPC_READ_SERVICE } from '../vpc/vpc.read.service';

describe('Directives: vpcTag', function () {

var $q, vpcReader;

beforeEach(
window.module(
require('./vpcTag.directive.js'),
require('./vpc.read.service.js')
VPC_READ_SERVICE
)
);

Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/domain/IVpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export interface IVpc {
name: string;
region: string;
cloudProvider: string;
label?: string;
deprecated?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import {
TASK_READ_SERVICE
} from '@spinnaker/core';

import { KEY_PAIRS_READ_SERVICE, VPC_READ_SERVICE } from '@spinnaker/amazon';

import { NetflixSettings } from 'netflix/netflix.settings';

import '../migrator.less';

module.exports = angular
.module('spinnaker.migrator.pipeline.directive', [
require('angular-ui-bootstrap'),
require('amazon/vpc/vpc.read.service.js'),
VPC_READ_SERVICE,
SUBNET_READ_SERVICE,
require('../migrator.service.js'),
PIPELINE_CONFIG_SERVICE,
SCROLL_TO_SERVICE,
CACHE_INITIALIZER_SERVICE,
TASK_READ_SERVICE,
require('amazon/keyPairs/keyPairs.read.service'),
require('amazon/vpc/vpc.read.service'),
KEY_PAIRS_READ_SERVICE,
require('../migrationWarnings.component'),
require('../migratedSecurityGroups.component'),
require('../migratedLoadBalancers.component'),
Expand Down
Loading

0 comments on commit a050ddb

Please sign in to comment.