azureCliCredentials.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { WebResource } from "@azure/ms-rest-js";
  2. import { TokenClientCredentials, TokenResponse } from "./tokenClientCredentials";
  3. import { LinkedSubscription } from "../subscriptionManagement/subscriptionUtils";
  4. /**
  5. * Describes the access token retrieved from Azure CLI.
  6. */
  7. export interface CliAccessToken {
  8. /**
  9. * The access token for the resource
  10. */
  11. accessToken: string;
  12. /**
  13. * Time when the access token expires.
  14. */
  15. expiresOn: Date;
  16. /**
  17. * SubscriptionId associated with the token.
  18. */
  19. subscription: string;
  20. /**
  21. * tenantId associated with the token.
  22. */
  23. tenant: string;
  24. /**
  25. * The token type. example: "Bearer".
  26. */
  27. tokenType: string;
  28. }
  29. /**
  30. * Describes the options that can be provided while listing all the subscriptions/accounts via
  31. * Azure CLI.
  32. */
  33. export interface ListAllSubscriptionOptions {
  34. /**
  35. * List all subscriptions, rather just 'Enabled' ones.
  36. */
  37. all?: boolean;
  38. /**
  39. * Retrieve up-to-date subscriptions from server.
  40. */
  41. refresh?: boolean;
  42. }
  43. export interface AccessTokenOptions {
  44. /**
  45. * The subscription id or name for which the access token is required.
  46. */
  47. subscriptionIdOrName?: string;
  48. /**
  49. * Azure resource endpoints.
  50. * - Defaults to Azure Resource Manager from environment: AzureCloud. "https://management.azure.com"
  51. * - For Azure KeyVault: "https://vault.azure.net"
  52. * - For Azure Batch: "https://batch.core.windows.net"
  53. * - For Azure Active Directory Graph: "https://graph.windows.net"
  54. *
  55. * To get the resource for other clouds:
  56. * - `az cloud list`
  57. */
  58. resource?: string;
  59. }
  60. /**
  61. * Describes the credentials by retrieving token via Azure CLI.
  62. */
  63. export declare class AzureCliCredentials implements TokenClientCredentials {
  64. /**
  65. * Provides information about the default/current subscription for Azure CLI.
  66. */
  67. subscriptionInfo: LinkedSubscription;
  68. /**
  69. * Provides information about the access token for the corresponding subscription for Azure CLI.
  70. */
  71. tokenInfo: CliAccessToken;
  72. /**
  73. * Azure resource endpoints.
  74. * - Defaults to Azure Resource Manager from environment: AzureCloud. "https://management.azure.com"
  75. * - For Azure KeyVault: "https://vault.azure.net"
  76. * - For Azure Batch: "https://batch.core.windows.net"
  77. * - For Azure Active Directory Graph: "https://graph.windows.net"
  78. *
  79. * To get the resource for other clouds:
  80. * - `az cloud list`
  81. */
  82. resource: string;
  83. /**
  84. * The number of seconds within which it is good to renew the token.
  85. * A constant set to 270 seconds (4.5 minutes).
  86. */
  87. private readonly _tokenRenewalMarginInSeconds;
  88. constructor(subscriptionInfo: LinkedSubscription, tokenInfo: CliAccessToken, resource?: string);
  89. /**
  90. * Tries to get the new token from Azure CLI, if the token has expired or the subscription has
  91. * changed else uses the cached accessToken.
  92. * @return The tokenResponse (tokenType and accessToken are the two important properties).
  93. */
  94. getToken(): Promise<TokenResponse>;
  95. /**
  96. * Signs a request with the Authentication header.
  97. * @param The request to be signed.
  98. */
  99. signRequest(webResource: WebResource): Promise<WebResource>;
  100. private _hasTokenExpired;
  101. private _hasSubscriptionChanged;
  102. private _parseToken;
  103. private _isAzureResourceManagerEndpoint;
  104. private _hasResourceChanged;
  105. /**
  106. * Gets the access token for the default or specified subscription.
  107. * @param options Optional parameters that can be provided to get the access token.
  108. */
  109. static getAccessToken(options?: AccessTokenOptions): Promise<CliAccessToken>;
  110. /**
  111. * Gets the subscription from Azure CLI.
  112. * @param subscriptionIdOrName - The name or id of the subscription for which the information is
  113. * required.
  114. */
  115. static getSubscription(subscriptionIdOrName?: string): Promise<LinkedSubscription>;
  116. /**
  117. * Sets the specified subscription as the default subscription for Azure CLI.
  118. * @param subscriptionIdOrName The name or id of the subsciption that needs to be set as the
  119. * default subscription.
  120. */
  121. static setDefaultSubscription(subscriptionIdOrName: string): Promise<void>;
  122. /**
  123. * Returns a list of all the subscriptions from Azure CLI.
  124. * @param options Optional parameters that can be provided while listing all the subcriptions.
  125. */
  126. static listAllSubscriptions(options?: ListAllSubscriptionOptions): Promise<LinkedSubscription[]>;
  127. /**
  128. * Provides credentials that can be used by the JS SDK to interact with Azure via azure cli.
  129. * **Pre-requisite**
  130. * - **install azure-cli** . For more information see
  131. * {@link https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest Install Azure CLI}
  132. * - **login via `az login`**
  133. * @param options - Optional parameters that can be provided while creating AzureCliCredentials.
  134. */
  135. static create(options?: AccessTokenOptions): Promise<AzureCliCredentials>;
  136. }
  137. //# sourceMappingURL=azureCliCredentials.d.ts.map