constructor()

in packages/components/environments/src/environment-component.ts [25:85]


  constructor(blueprint: Blueprint, environment_: EnvironmentDefinition<any>) {
    super(blueprint);
    const environment = environment_ || {};
    this.name = environment?.name || 'default-env-name';
    this.definition = environment;
    this.accountKeys = [];

    const writtenEnvironment = {
      name: this.name,
      description: environment.description || environment.name,
      environmentType: environment.environmentType || 'PRODUCTION',
    };

    const connectedAccounts: {
      environmentName: string;
      name: string;
    }[] = [];

    /**
     * keys of the environment definition that dont represent an account connection
     */
    const nonAccountKeys = new Set(Object.keys(writtenEnvironment));

    // find all the account connections on the environment
    Object.keys(environment)
      .filter(key => !nonAccountKeys.has(key))
      .forEach(accountkey => {
        this.accountKeys.push(accountkey);
        const account: AccountConnection<any> = environment[accountkey];
        if (account.name && environment.name) {
          connectedAccounts.push({
            environmentName: environment.name,
            name: account.name,
          });
        }
      });

    // create the environment file
    new YamlFile(
      blueprint,
      `environments/${stripSpaces(writtenEnvironment.name || 'env')}-${getHashedEntropy(5, JSON.stringify(writtenEnvironment))}.yaml`,
      {
        readonly: false,
        marker: false,
        obj: writtenEnvironment,
      },
    );

    // create all the linked accounts from the environment
    connectedAccounts.forEach(account => {
      new YamlFile(
        blueprint,
        `aws-account-to-environment/${stripSpaces(account.name || 'account')}-${getHashedEntropy(5, JSON.stringify(account))}.yaml`,
        {
          readonly: false,
          marker: false,
          obj: account,
        },
      );
    });
  }