コード例 #1
0
        private static IAzure GetAzureContext()
        {
            IAzure azure = Azure.Authenticate("my.azureauth").WithDefaultSubscription();
            var    currentSubscription = azure.GetCurrentSubscription();

            return(azure);
        }
コード例 #2
0
        private IAzure GetAzureContext(string authFilePath)
        {
            IAzure        azure;
            ISubscription sub;

            azure = Azure.Authenticate(authFilePath).WithDefaultSubscription();
            sub   = azure.GetCurrentSubscription();

            return(azure);
        }
コード例 #3
0
ファイル: Azure_instance.cs プロジェクト: yeahsicy/AzureRM
        public Azure_instance(string subscriptionId, string clientId, string clientSecret, string tenantId, AzureEnvironment environment)
        {
            var c = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, environment);

            azure = Azure.Authenticate(c).WithSubscription(subscriptionId);

            try
            {
                azure.GetCurrentSubscription();
            }
            catch
            {
                throw;
            }
        }
コード例 #4
0
        public AzureReader(
            string clientId,
            string clientSecret,
            string tenantId,
            string subscriptionId,
            ILogger logger = null)
        {
            _logger = logger ?? new ConsoleLogger();

            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(
                clientId,
                clientSecret,
                tenantId,
                AzureEnvironment.AzureGlobalCloud);

            _azure = Microsoft.Azure.Management.Fluent.Azure
                     .Configure()
                     .Authenticate(credentials)
                     .WithSubscription(subscriptionId);

            SubscriptionName = _azure.GetCurrentSubscription().DisplayName;
        }
コード例 #5
0
ファイル: AzureAccountManager.cs プロジェクト: JonJam/kubemob
        public async Task <(bool isValid, string message)> TrySaveCredentials(
            CloudEnvironment cloudEnvironment,
            string tenantId,
            string clientId,
            string clientSecret,
            bool isEditing)
        {
            IEnumerable <AzureAccount> accounts = await this.appSettings
                                                  .GetCloudAccounts <AzureAccount>(CloudAccountType.Azure);

            if (!isEditing &&
                accounts.Any(a => a.TenantId == tenantId))
            {
                // Ensuring not adding duplicate accounts, based upon TenantId.
                return(false, AppResources.AzureAccountManager_TryAddCredentials_DuplicateTenantId);
            }

            try
            {
                IAzure azure = AzureAccountManager.CreateAuthenticatedClient(cloudEnvironment.Id, tenantId, clientId, clientSecret);

                string subscriptionName = azure.GetCurrentSubscription().DisplayName;

                await this.appSettings.AddOrUpdateCloudAccount(new AzureAccount(
                                                                   subscriptionName,
                                                                   cloudEnvironment.Id,
                                                                   tenantId,
                                                                   clientId,
                                                                   clientSecret));
            }
            catch (AdalServiceException e) when(e.ServiceErrorCodes != null &&
                                                e.ServiceErrorCodes.Contains(AzureAccountManager.AdalInvalidClientIdServiceErrorCode))
            {
                // AADSTS70001 - Invalid client ID.
                return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidClientId);
            }
            catch (AdalServiceException e) when(e.ServiceErrorCodes != null &&
                                                e.ServiceErrorCodes.Contains(AzureAccountManager.AdalInvalidClientSecretServiceErrorCode))
            {
                // AADSTS70002 - Invalid client secret.
                return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidClientSecret);
            }
            catch (AdalServiceException e) when(e.ServiceErrorCodes != null &&
                                                e.ServiceErrorCodes.Contains(AzureAccountManager.AdalTenantDoesntExistServiceErrorCode))
            {
                // AADSTS90002 - Tenant doesn't exist.
                return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidTenantId);
            }
            catch (AdalServiceException e) when(e.StatusCode == AzureAccountManager.AdalRequestTimeoutStatusCode)
            {
                // No internet
                return(false, AppResources.AzureAccountManager_TryAddCredentials_NoInternet);
            }
            catch (HttpRequestException e) when(e.InnerException is WebException web &&
                                                web.Status == WebExceptionStatus.NameResolutionFailure)
            {
                // No internet
                return(false, AppResources.AzureAccountManager_TryAddCredentials_NoInternet);
            }

            return(true, string.Empty);
        }
コード例 #6
0
ファイル: AzureService.cs プロジェクト: lulzzz/sepes
 public string getSubscription()
 {
     return(_azure.GetCurrentSubscription().DisplayName);
 }