public AzureSessionFactory(IAzureSessionOptions azureSessionOptions)
        {
            this.azureSessionOptions = azureSessionOptions ?? throw new ArgumentNullException(nameof(azureSessionOptions));

            session = new Lazy <AZFluent.Azure.IAuthenticated>(() =>
            {
                var credentials = new RMFluent.Authentication.AzureCredentialsFactory()
                                  .FromServicePrincipal(azureSessionOptions.ClientId, azureSessionOptions.ClientSecret, azureSessionOptions.TenantId, RMFluent.AzureEnvironment.AzureGlobalCloud);

                return(AZFluent.Azure
                       .Configure()
                       .Authenticate(credentials));
            });
        }
Example #2
0
        private static IAzure Authenticate()
        {
            var credentials =
                new Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentialsFactory()
                .FromServicePrincipal(
                    GetSetting("RAFT_SERVICE_PRINCIPAL_CLIENT_ID"),
                    GetSetting("RAFT_SERVICE_PRINCIPAL_CLIENT_SECRET"),
                    GetSetting("RAFT_SERVICE_PRINCIPAL_TENANT_ID"), AzureEnvironment.AzureGlobalCloud);

            var azure = Microsoft.Azure.Management.Fluent.Azure
                        .Configure()
                        .Authenticate(credentials)
                        .WithSubscription(GetSetting("RAFT_SERVICE_PRINCIPAL_SUBSCRIPTION_ID"));

            return(azure);
        }
Example #3
0
        private static IAzure Authenticate()
        {
            int    maxAttempts = 10;
            IAzure azure       = null;

            for (int i = 0; i < maxAttempts; i++)
            {
                try
                {
                    var credentials =
                        new Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentialsFactory()
                        .FromServicePrincipal(
                            GetSetting("RAFT_SERVICE_PRINCIPAL_CLIENT_ID"),
                            GetSetting("RAFT_SERVICE_PRINCIPAL_CLIENT_SECRET"),
                            GetSetting("RAFT_SERVICE_PRINCIPAL_TENANT_ID"), AzureEnvironment.AzureGlobalCloud);

                    azure = Microsoft.Azure.Management.Fluent.Azure
                            .Configure()
                            .Authenticate(credentials)
                            .WithSubscription(GetSetting("RAFT_SERVICE_PRINCIPAL_SUBSCRIPTION_ID"));
                }
                catch (Exception)
                {
                    if (i == maxAttempts - 1)
                    {
                        throw;
                    }
                    else
                    {
                        System.Console.Out.WriteLine("Got exception when authenticating, trying again...");
                        System.Threading.Thread.Sleep(3000);
                    }
                }
            }
            return(azure);
        }