export function serviceAccountFromShorthand()

in src/common/encoding.ts [53:72]


export function serviceAccountFromShorthand(
  serviceAccount: string
): string | null {
  if (serviceAccount === 'default') {
    return null;
  } else if (serviceAccount.endsWith('@')) {
    if (!process.env.GCLOUD_PROJECT) {
      throw new Error(
        `Unable to determine email for service account '${serviceAccount}' because process.env.GCLOUD_PROJECT is not set.`
      );
    }
    return `${serviceAccount}${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`;
  } else if (serviceAccount.includes('@')) {
    return serviceAccount;
  } else {
    throw new Error(
      `Invalid option for serviceAccount: '${serviceAccount}'. Valid options are 'default', a service account email, or '{serviceAccountName}@'`
    );
  }
}