Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
177 stars 75 forks source link

support anonymous credentials in rest level client #1447

Open qiaozha opened 2 years ago

qiaozha commented 2 years ago

In confidential ledger and service fabric, we have cases like whether the credentials might be undefined, and we will nees tlsOptions in the options to do the authentication.

export default function ConfidentialLedger(
  ledgerBaseUrl: string,
  ledgerIdentityCertificate: string,
  credentials: TokenCredential,
  options?: ClientOptions
): ConfidentialLedgerClient;
export default function ConfidentialLedger(
  ledgerBaseUrl: string,
  ledgerIdentityCertificate: string,
  credentialsOrOptions?: TokenCredential | ClientOptions,
  opts?: ClientOptions
): ConfidentialLedgerClient {
  let credentials: TokenCredential | undefined;
  let options: ClientOptions;

  if (isTokenCredential(credentialsOrOptions)) {
    credentials = credentialsOrOptions;
    options = opts ?? {};
  } else {
    options = credentialsOrOptions ?? {};
  }

  const tlsOptions = options?.tlsOptions ?? {};
  tlsOptions.ca = ledgerIdentityCertificate;
  const confidentialLedger = GeneratedConfidentialLedger(ledgerBaseUrl, credentials!, {
    ...options,
    tlsOptions,
  });
  return confidentialLedger;
}

we might need to consider to support it in the code gen side

qiaozha commented 1 year ago

update the customization document first and then considering put it in the codegen if there're more cases.