예제 #1
0
        private static async Task UpdateFrontDoorAsync(bool isHealthy, ILogger log)
        {
            log.LogInformation("UpdateFrontDoorAsync method has been triggered...");

            // Get a token to access the Azure Resource Health API using the managed identity
            var tokenProvider = new AzureServiceTokenProvider(IDENTITY_CONN_STR);
            var token         = await tokenProvider.GetAccessTokenAsync("https://management.azure.com/");

            var credentials = new TokenCredentials(token);

            var mgmtClient = new FrontDoorManagementClient(credentials)
            {
                SubscriptionId = SUBSCRIPTION_ID
            };

            // Use the Azure Management SDK to get the Front Door
            var frontDoor = await mgmtClient.FrontDoors.GetAsync(RESOURCE_GROUP_NAME, FRONT_DOOR_NAME);

            // Find the associated Backend
            var backend = frontDoor.BackendPools
                          .Single(p => p.Name == BACKEND_POOL_NAME)
                          .Backends.Single(s => s.Address == BACKEND_ADDRESS);

            // Set the status of the front door backend
            var newStatus = isHealthy ? "Enabled" : "Disabled";

            // If the status has changed, then update the status
            if (backend.EnabledState != newStatus)
            {
                backend.EnabledState = newStatus;
                var result = await mgmtClient.FrontDoors.CreateOrUpdateAsync(RESOURCE_GROUP_NAME, FRONT_DOOR_NAME, frontDoor);
            }
        }
        public async Task <IEnumerable <FrontendEndpoint> > GetFrontEnds(String resourceGroup, String frontDoor)
        {
            FrontDoorManagementClient Interface = await GetClientInstance();

            IEnumerable <FrontendEndpoint> Output = await Interface.FrontendEndpoints.ListByFrontDoorAsync(resourceGroup, frontDoor);

            return(Output?.ToList());
        }
        public async Task <IEnumerable <FrontDoorModel> > GetFrontDoors()
        {
            FrontDoorManagementClient Interface = await GetClientInstance();

            IEnumerable <FrontDoorModel> Output = await Interface.FrontDoors.ListAsync();

            return(Output?.ToList());
        }
예제 #4
0
        protected void SetupManagementClients(MockContext context)
        {
            ResourceManagementClient  = GetResourceManagementClient(context);
            FrontDoorManagementClient = GetFrontDoorManagementClient(context);

            _helper.SetupManagementClients(
                ResourceManagementClient,
                FrontDoorManagementClient);
        }
        public async Task <FrontDoorManagementClient> GetClientInstance()
        {
            String BearerToken = await this._authenticationHandler.GetBearerToken();

            ServiceClientCredentials  Creds  = new TokenCredentials(BearerToken);
            FrontDoorManagementClient Client = new FrontDoorManagementClient(Creds)
            {
                SubscriptionId = _subscriptionId
            };

            return(Client);
        }
예제 #6
0
 public SharedFunctions(IHttpClientFactory httpClientFactory, LookupClient lookupClient,
                        IAcmeProtocolClientFactory acmeProtocolClientFactory, IOptions <LetsEncryptOptions> options,
                        KeyVaultClient keyVaultClient, DnsManagementClient dnsManagementClient
                        , FrontDoorManagementClient frontDoorManagementClient
                        , ResourceManagementClient resourceManagementClient)
 {
     _httpClientFactory         = httpClientFactory;
     _lookupClient              = lookupClient;
     _acmeProtocolClientFactory = acmeProtocolClientFactory;
     _options                   = options.Value;
     _keyVaultClient            = keyVaultClient;
     _dnsManagementClient       = dnsManagementClient;
     _frontDoorManagementClient = frontDoorManagementClient;
     _resourceManagementClient  = resourceManagementClient;
 }
예제 #7
0
        public static FrontDoorManagementClient GetFrontDoorManagementClient(MockContext context, RecordedDelegatingHandler handler)
        {
            FrontDoorManagementClient frontDoorClient;

            if (IsTestTenant)
            {
                frontDoorClient = new FrontDoorManagementClient(new TokenCredentials("xyz"), GetHandler());
                frontDoorClient.SubscriptionId = testSubscription;
                frontDoorClient.BaseUri        = testUri;
            }
            else
            {
                handler.IsPassThrough = true;
                frontDoorClient       = context.GetServiceClient <FrontDoorManagementClient>(handlers: handler);
            }
            return(frontDoorClient);
        }
        public async Task <Boolean> EnableCustomHttps(String resourceGroup, String frontDoor, String endpointName, String vaultId, String secretName, String secretVersion)
        {
            CustomHttpsConfiguration EndpointHttpsConfiguration = new CustomHttpsConfiguration();

            EndpointHttpsConfiguration.CertificateSource = "AzureKeyVault";
            EndpointHttpsConfiguration.Vault             = new KeyVaultCertificateSourceParametersVault(vaultId);
            EndpointHttpsConfiguration.SecretName        = secretName;
            EndpointHttpsConfiguration.SecretVersion     = secretVersion;
            EndpointHttpsConfiguration.ProtocolType      = "ServerNameIndication";

            AzureOperationResponse Response = null;

            using (FrontDoorManagementClient Interface = await GetClientInstance())
            {
                Response = await Interface.FrontendEndpoints.EnableHttpsWithHttpMessagesAsync(resourceGroup, frontDoor, endpointName, EndpointHttpsConfiguration);
            }

            return(Response.Response.IsSuccessStatusCode);
        }
        public async Task <Boolean> CreateFrontEnd(String resourceGroup, String frontDoor, String endpointName, String hostName)
        {
            FrontDoorManagementClient Interface = await GetClientInstance();

            FrontendEndpoint Parameters = new FrontendEndpoint()
            {
                HostName = hostName,
                Name     = endpointName,
                SessionAffinityEnabledState      = "Enabled",
                WebApplicationFirewallPolicyLink = null,
            };

            AzureOperationResponse <FrontDoorModel> Response;

            try
            {
                //Add the frontend by pulling down and reuploading the full config for the frontdoor
                FrontDoorModel TargetFrontDoor = Interface.FrontDoors.Get(resourceGroup, frontDoor);

                TargetFrontDoor.FrontendEndpoints.Add(Parameters);

                Response = await Interface.FrontDoors.CreateOrUpdateWithHttpMessagesAsync(resourceGroup, frontDoor, TargetFrontDoor);
            }
            catch (ErrorResponseException exc)
            {
                this.LastError = exc.Response?.Content;

                if (String.IsNullOrWhiteSpace(this.LastError))
                {
                    this.LastError = exc.ToString();
                }

                return(false);
            }

            return(Response.Response.IsSuccessStatusCode);
        }
예제 #10
0
 public FrontDoorRotationFunction(CertificateClientFactory certificateClientFactory, FrontDoorManagementClient frontDoorManagementClient)
 {
     _certificateClientFactory  = certificateClientFactory;
     _frontDoorManagementClient = frontDoorManagementClient;
 }