Esempio n. 1
0
        public static (ArmClientOptions, TokenCredentialOptions) GetArmClientOptions(this ServicePrincipalAccount servicePrincipalAccount)
        {
            var azureKnownEnvironment = new AzureKnownEnvironment(servicePrincipalAccount.AzureEnvironment);

            // Configure a specific transport that will pick up the proxy settings set by Calamari
            var httpClientTransport = new HttpClientTransport(new HttpClientHandler {
                Proxy = WebRequest.DefaultWebProxy
            });

            // Specifically tell the new Azure SDK which authentication endpoint to use
            var authorityHost          = azureKnownEnvironment.GetAzureAuthorityHost();
            var tokenCredentialOptions = new TokenCredentialOptions
            {
                Transport     = httpClientTransport,
                AuthorityHost = authorityHost
            };

            // The new Azure SDK uses a different representation of Environments
            var armEnvironment   = azureKnownEnvironment.AsAzureArmEnvironment();
            var armClientOptions = new ArmClientOptions()
            {
                Transport   = httpClientTransport,
                Environment = armEnvironment
            };

            return(armClientOptions, tokenCredentialOptions);
        }
Esempio n. 2
0
        public static IAzure CreateAzureClient(this ServicePrincipalAccount servicePrincipal)
        {
            var environment = new AzureKnownEnvironment(servicePrincipal.AzureEnvironment).AsAzureSDKEnvironment();
            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(servicePrincipal.ClientId,
                                                                                      servicePrincipal.Password, servicePrincipal.TenantId, environment
                                                                                      );

            // Note: This is a tactical fix to ensure this Sashimi uses the appropriate web proxy
            #pragma warning disable
            var client = new HttpClient(new HttpClientHandler {
                Proxy = WebRequest.DefaultWebProxy
            });

            return(Microsoft.Azure.Management.Fluent.Azure.Configure()
                   .WithHttpClient(client)
                   .Authenticate(credentials)
                   .WithSubscription(servicePrincipal.SubscriptionNumber));
        }