From 17d1d15f5eaa977ece1419109aa3a94b65b9fb78 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Tue, 3 Oct 2017 13:59:02 -0400 Subject: [PATCH] feat(core): Version account lookup --- .../modules/core/src/account/account.service.ts | 13 ++++++++----- .../src/cloudProvider/cloudProvider.registry.ts | 2 +- .../kubernetes/cluster/configure/CommandBuilder.js | 2 +- .../serverGroup/configure/configuration.service.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/scripts/modules/core/src/account/account.service.ts b/app/scripts/modules/core/src/account/account.service.ts index 75cf9fd90d3..bde63e38634 100644 --- a/app/scripts/modules/core/src/account/account.service.ts +++ b/app/scripts/modules/core/src/account/account.service.ts @@ -21,6 +21,7 @@ export interface IAccount { name: string; requiredGroupMembership: string[]; type: string; + providerVersion?: string; } export interface IAccountDetails extends IAccount { @@ -34,7 +35,6 @@ export interface IAccountDetails extends IAccount { primaryAccount: boolean; regions: IRegion[]; namespaces?: string[]; - providerVersion?: string; } export interface IAggregatedAccounts { @@ -83,8 +83,8 @@ export class AccountService { .get(); } - public getAllAccountDetailsForProvider(provider: string): ng.IPromise { - return this.listAccounts(provider) + public getAllAccountDetailsForProvider(provider: string, providerVersion: string = null): ng.IPromise { + return this.listAccounts(provider, providerVersion) .then((accounts: IAccount[]) => this.$q.all(accounts.map((account: IAccount) => this.getAccountDetails(account.name)))) .catch((error: any) => { this.$log.warn(`Failed to load accounts for provider "${provider}"; exception:`, error); @@ -166,13 +166,16 @@ export class AccountService { }); } - public listAccounts(provider: string = null): ng.IPromise { - + public listAccounts(provider: string = null, providerVersion: string = null): ng.IPromise { let result: ng.IPromise = this.API.one('credentials').useCache().get(); if (provider) { result = result.then((accounts: IAccount[]) => accounts.filter((account: IAccount) => account.type === provider)); } + if (providerVersion) { + result = result.then((accounts: IAccount[]) => accounts.filter((account: IAccount) => account.providerVersion === providerVersion )); + } + return result; } diff --git a/app/scripts/modules/core/src/cloudProvider/cloudProvider.registry.ts b/app/scripts/modules/core/src/cloudProvider/cloudProvider.registry.ts index d9522f82cd0..8f0e8a55957 100644 --- a/app/scripts/modules/core/src/cloudProvider/cloudProvider.registry.ts +++ b/app/scripts/modules/core/src/cloudProvider/cloudProvider.registry.ts @@ -1,6 +1,6 @@ /* tslint:disable: no-console */ import { module } from 'angular'; -import { cloneDeep, uniq, without } from 'lodash'; +import { cloneDeep, isNil, uniq, without } from 'lodash'; import { SETTINGS } from 'core/config/settings'; diff --git a/app/scripts/modules/kubernetes/cluster/configure/CommandBuilder.js b/app/scripts/modules/kubernetes/cluster/configure/CommandBuilder.js index 9bfed7aea96..2d8137473a7 100644 --- a/app/scripts/modules/kubernetes/cluster/configure/CommandBuilder.js +++ b/app/scripts/modules/kubernetes/cluster/configure/CommandBuilder.js @@ -12,7 +12,7 @@ module.exports = angular.module('spinnaker.kubernetes.clusterCommandBuilder.serv ]) .factory('kubernetesClusterCommandBuilder', function (accountService) { function attemptToSetValidAccount(application, defaultAccount, command) { - return accountService.listAccounts('kubernetes').then(function(kubernetesAccounts) { + return accountService.listAccounts('kubernetes', 'v1').then(function(kubernetesAccounts) { var kubernetesAccountNames = _.map(kubernetesAccounts, 'name'); var firstKubernetesAccount = null; diff --git a/app/scripts/modules/kubernetes/serverGroup/configure/configuration.service.js b/app/scripts/modules/kubernetes/serverGroup/configure/configuration.service.js index 81d9365af74..2f7e0b32dd4 100644 --- a/app/scripts/modules/kubernetes/serverGroup/configure/configuration.service.js +++ b/app/scripts/modules/kubernetes/serverGroup/configure/configuration.service.js @@ -43,7 +43,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.kubernetes.conf } return $q.all({ - accounts: accountService.listAccounts('kubernetes'), + accounts: accountService.listAccounts('kubernetes', 'v1'), loadBalancers: loadBalancerReader.listLoadBalancers('kubernetes'), allImages: imagesPromise }).then(function(backingData) {