public async generateProfile()

in Composer/packages/server/src/externalContentProvider/azureBotServiceProvider.ts [41:85]


  public async generateProfile(): Promise<PublishTarget> {
    const appId = this.metadata.appId;
    // parse subscriptionId ... from this.metadata
    const temp = { ...this.metadata };
    const subs = this.metadata.resourceId.match(/subscriptions\/([\w-]*)\//);
    const groups = this.metadata.resourceId.match(/resourceGroups\/([^/]*)/);
    const names = this.metadata.resourceId.match(/botServices\/([^/]*)/);
    temp.subscriptionId = (subs && subs.length > 0 && subs[1]) || '';
    temp.resourceGroup = (groups && groups.length > 0 && groups[1]) || '';
    temp.botName = (names && names.length > 0 && names[1]) || '';
    delete temp.appId;

    // transform key vault token hint to microsoft app password
    const hint = this.metadata.appPasswordHint || '';
    delete temp.appPasswordHint;
    const vaultNames = hint.match(/vaults\/([^/]*)/);
    const secretNames = hint.match(/secrets\/([^/]*)/);
    const resourceGroupNames = hint.match(/resourceGroups\/([^/]*)/);
    const vaultName = (vaultNames && vaultNames.length > 0 && vaultNames[1]) || '';
    const secretName = (secretNames && secretNames.length > 0 && secretNames[1]) || '';
    const resourceGroupName = (resourceGroupNames && resourceGroupNames.length > 0 && resourceGroupNames[1]) || '';
    const tenantId = this.metadata.tenantId;

    // get token
    const armToken = await this.getArmAccessToken(tenantId);
    const vaultToken = await this.getVaultAccessToken();
    const decoded = jwtDecode<{ oid: string }>(armToken);

    // set key vault policy
    await this.keyVaultUpdatePolicy(armToken, temp.subscriptionId, resourceGroupName, vaultName, tenantId, decoded.oid);
    const appPwd = await this.keyVaultGetSecretValue(vaultToken, vaultName, secretName);
    return {
      name: `abs-${this.metadata.botName}`,
      type: 'azurePublish',
      configuration: JSON.stringify({
        hostname: '',
        runtimeIdentifier: 'win-x64',
        settings: {
          MicrosoftAppId: appId,
          MicrosoftAppPassword: appPwd,
        },
        ...temp,
      }),
    };
  }