Skip to content

Commit

Permalink
feat(core): Version account lookup (#4212)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Oct 3, 2017
1 parent 19c5c7e commit 25b98bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions app/scripts/modules/core/src/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IAccount {
name: string;
requiredGroupMembership: string[];
type: string;
providerVersion?: string;
}

export interface IAccountDetails extends IAccount {
Expand All @@ -34,7 +35,6 @@ export interface IAccountDetails extends IAccount {
primaryAccount: boolean;
regions: IRegion[];
namespaces?: string[];
providerVersion?: string;
}

export interface IAggregatedAccounts {
Expand Down Expand Up @@ -83,8 +83,8 @@ export class AccountService {
.get();
}

public getAllAccountDetailsForProvider(provider: string): ng.IPromise<IAccountDetails[]> {
return this.listAccounts(provider)
public getAllAccountDetailsForProvider(provider: string, providerVersion: string = null): ng.IPromise<IAccountDetails[]> {
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);
Expand Down Expand Up @@ -166,11 +166,14 @@ export class AccountService {
});
}

public listAccounts(provider: string = null): ng.IPromise<IAccount[]> {

public listAccounts(provider: string = null, providerVersion: string = null): ng.IPromise<IAccount[]> {
let result: ng.IPromise<IAccount[]> = this.API.one('credentials').useCache().get();
if (provider) {
result = result.then((accounts: IAccount[]) => accounts.filter((account: IAccount) => account.type === provider));
result = result.then((accounts) => accounts.filter((account) => account.type === provider));
}

if (providerVersion) {
result = result.then((accounts) => accounts.filter((account) => account.providerVersion === providerVersion));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 25b98bf

Please sign in to comment.