AzureCredentials.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { SelectableValue } from '@grafana/data';
  2. export enum AzureCloud {
  3. Public = 'AzureCloud',
  4. China = 'AzureChinaCloud',
  5. USGovernment = 'AzureUSGovernment',
  6. Germany = 'AzureGermanCloud',
  7. None = '',
  8. }
  9. export const KnownAzureClouds = [
  10. { value: AzureCloud.Public, label: 'Azure' },
  11. { value: AzureCloud.China, label: 'Azure China' },
  12. { value: AzureCloud.USGovernment, label: 'Azure US Government' },
  13. { value: AzureCloud.Germany, label: 'Azure Germany' },
  14. ] as SelectableValue[];
  15. export type AzureAuthType = 'msi' | 'clientsecret';
  16. export type ConcealedSecret = symbol;
  17. interface AzureCredentialsBase {
  18. authType: AzureAuthType;
  19. defaultSubscriptionId?: string;
  20. }
  21. export interface AzureManagedIdentityCredentials extends AzureCredentialsBase {
  22. authType: 'msi';
  23. }
  24. export interface AzureClientSecretCredentials extends AzureCredentialsBase {
  25. authType: 'clientsecret';
  26. azureCloud?: string;
  27. tenantId?: string;
  28. clientId?: string;
  29. clientSecret?: string | ConcealedSecret;
  30. }
  31. export type AzureCredentials = AzureManagedIdentityCredentials | AzureClientSecretCredentials;
  32. export function isCredentialsComplete(credentials: AzureCredentials): boolean {
  33. switch (credentials.authType) {
  34. case 'msi':
  35. return true;
  36. case 'clientsecret':
  37. return !!(credentials.azureCloud && credentials.tenantId && credentials.clientId && credentials.clientSecret);
  38. }
  39. }