Example #1
0
  public selectProvider(application: Application, feature: string): IPromise<string> {
    return this.accountService.listProviders(application).then((providers) => {
      let provider;
      let reducedProviders: string[] = [];
      if (feature) {
        reducedProviders = providers.filter((p) => this.cloudProviderRegistry.hasValue(p, feature));
      }

      // reduce the providers to the smallest, unique collection taking into consideration the useProvider values
      reducedProviders = uniq(reducedProviders.map((providerName) => {
        const providerFeature = this.cloudProviderRegistry.getProvider(providerName)[feature] || {};
        return providerFeature.useProvider || providerName;
      }));

      if (reducedProviders.length > 1) {
        provider = this.$uibModal.open({
          templateUrl: require('./providerSelection.html'),
          controller: 'ProviderSelectCtrl as ctrl',
          resolve: {
            providerOptions: () =>  reducedProviders
          }
        }).result;
      } else if (reducedProviders.length === 1) {
        provider = this.$q.when(reducedProviders[0]);
      } else {
        provider = this.$q.when(SETTINGS.defaultProvider || 'aws');
      }
      return provider;
    });
  }
  public buildNewServerGroupCommand(app: Application,
                                    selectedProvider = 'appengine',
                                    mode = 'create'): IPromise<IAppengineServerGroupCommand> {
    let dataToFetch = {
      accounts: this.accountService.getAllAccountDetailsForProvider('appengine'),
    };

    let viewState: IViewState = {
      mode: mode,
      submitButtonLabel: this.getSubmitButtonLabel(mode),
      disableStrategySelection: mode === 'create' ? true : false,
    };

    return this.$q.all(dataToFetch)
      .then((backingData: any) => {
        let credentials: string = this.getCredentials(backingData.accounts, app);
        let region: string = this.getRegion(backingData.accounts, credentials);

        return {
          application: app.name,
          backingData,
          viewState,
          credentials,
          region,
          selectedProvider,
          interestingHealthProviderNames: [],
        } as IAppengineServerGroupCommand;
      });
  }
Example #3
0
    it('should filter out providers not registered', () => {

      registeredProviders.pop();
      const test: any = (result: string[]) => expect(result).toEqual(['aws', 'gce']);
      accountService.listProviders().then(test);
      $http.flush();
    });
Example #4
0
 public getRegions(provider: string): ng.IPromise<string[]> {
   if (has(this.settings, `providers.${provider}.bakeryRegions`)) {
     return this.$q.when(get(this.settings, `providers.${provider}.bakeryRegions`));
   }
   return this.accountService.getUniqueAttributeForAllAccounts(provider, 'regions')
     .then((regions: string[]) => regions.sort());
 }
Example #5
0
    it('should return an empty array if none of the app providers are available from the server', () => {

      const application: any = {attributes: {cloudProviders: ['lamp', 'ceiling', 'fan']}};
      const test: any = (result: string[]) => expect(result).toEqual([]);
      settings.defaultProviders = 'aws';
      accountService.listProviders(application).then(test);
      $http.flush();
    });
Example #6
0
    it('should fall back to all registered available providers if no defaults configured and none configured on app', () => {

      const application: any = {attributes: { cloudProviders: [] }};
      const test: any = (result: string[]) => expect(result).toEqual(['aws', 'cf', 'gce']);
      delete settings.defaultProviders;
      accountService.listProviders(application).then(test);
      $http.flush();
    });
Example #7
0
    it('should return the intersection of those configured for the application and those available from the server', () => {

      const application: any = {attributes: {cloudProviders: ['gce', 'cf', 'unicron']}};
      const test: any = (result: string[]) => expect(result).toEqual(['cf', 'gce']);
      settings.defaultProviders = ['aws'];
      accountService.listProviders(application).then(test);
      $http.flush();
    });
Example #8
0
    it('should fall back to the defaultProviders if none configured for the application', () => {

      const application: any = {attributes: { cloudProviders: [] }};
      const test: any = (result: string[]) => expect(result).toEqual(['cf', 'gce']);
      settings.defaultProviders = ['gce', 'cf'];
      accountService.listProviders(application).then(test);
      $http.flush();
    });
Example #9
0
 public setStageRegion(): void {
   let selected = this.$scope.accounts.find((account) => account.name === this.$scope.stage.credentials);
   if (selected && selected.name) {
     this.accountService.getAccountDetails(selected.name)
       .then((accountDetails: IAppengineAccount) => {
         this.$scope.stage.region = accountDetails.region;
       });
   }
 }
Example #10
0
    it('should fall back to an empty array if an exception occurs when listing accounts', () => {
      $http.expectGET(`${API.baseUrl}/credentials`).respond(429, null);

      let details: any[] = null;
      accountService.getAllAccountDetailsForProvider('aws').then((results: any[]) => {
        details = results;
      });

      $http.flush();
      expect(details).toEqual([]);
    });