autorest.typescript icon indicating copy to clipboard operation
autorest.typescript copied to clipboard

support anonymous credentials in rest level client

Open qiaozha opened this issue 3 years ago • 0 comments

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 avatar Jul 19 '22 02:07 qiaozha