protected void InitializeResourceManagementClients()
        {
            var azureCredentials = _authenticationManager
                                   .GetDelegatingAzureCredentials();

            // Create generic RestClient for services
            _restClient = RestClient
                          .Configure()
                          .WithEnvironment(_authConf.AzureEnvironment)
                          .WithCredentials(azureCredentials)
                          //.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                          .Build();

            var subscriptionId = _subscription.SubscriptionId;

            _keyVaultManagementClient            = new KeyVaultMgmtClient(subscriptionId, _restClient);
            _storageManagementClient             = new StorageMgmtClient(subscriptionId, _restClient);
            _iotHubManagementClient              = new IotHubMgmtClient(subscriptionId, _restClient);
            _cosmosDBManagementClient            = new CosmosDBMgmtClient(subscriptionId, _restClient);
            _serviceBusManagementClient          = new ServiceBusMgmtClient(subscriptionId, _restClient);
            _eventHubManagementClient            = new EventHubMgmtClient(subscriptionId, _restClient);
            _operationalInsightsManagementClient = new OperationalInsightsMgmtClient(subscriptionId, _restClient);
            _applicationInsightsManagementClient = new ApplicationInsightsMgmtClient(subscriptionId, _restClient);
            _webSiteManagementClient             = new WebSiteMgmtClient(subscriptionId, _restClient);
            _networkManagementClient             = new NetworkMgmtClient(subscriptionId, _restClient);
            _authorizationManagementClient       = new AuthorizationMgmtClient(subscriptionId, _restClient);
            _aksManagementClient     = new AksMgmtClient(subscriptionId, _restClient);
            _signalRManagementClient = new SignalRMgmtClient(subscriptionId, _restClient);
        }
Beispiel #2
0
        public void InitializeResourceManagementClients(
            CancellationToken cancellationToken = default
            )
        {
            // Microsoft Graph
            var microsoftGraphTokenProvider = _authenticationManager
                                              .GenerateDelegatingTokenProvider(
                _authenticationManager.AcquireMicrosoftGraphTokenAsync
                );

            _msGraphServiceClient = new MicrosoftGraphServiceClient(
                _tenantId,
                microsoftGraphTokenProvider,
                cancellationToken
                );

            // Create generic RestClient for services
            _restClient = RestClient
                          .Configure()
                          .WithEnvironment(_azureEnvironment)
                          .WithCredentials(_azureCredentials)
                          //.WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                          .Build();

            var subscriptionId = _subscription.SubscriptionId;

            _resourceMgmtClient                  = new ResourceMgmtClient(subscriptionId, _restClient);
            _keyVaultManagementClient            = new KeyVaultMgmtClient(subscriptionId, _restClient);
            _storageManagementClient             = new StorageMgmtClient(subscriptionId, _restClient);
            _iotHubManagementClient              = new IotHubMgmtClient(subscriptionId, _restClient);
            _cosmosDBManagementClient            = new CosmosDBMgmtClient(subscriptionId, _restClient);
            _serviceBusManagementClient          = new ServiceBusMgmtClient(subscriptionId, _restClient);
            _eventHubManagementClient            = new EventHubMgmtClient(subscriptionId, _restClient);
            _operationalInsightsManagementClient = new OperationalInsightsMgmtClient(subscriptionId, _restClient);
            _applicationInsightsManagementClient = new ApplicationInsightsMgmtClient(subscriptionId, _restClient);
            _webSiteManagementClient             = new WebSiteMgmtClient(subscriptionId, _restClient);
            _networkManagementClient             = new NetworkMgmtClient(subscriptionId, _restClient);
            _authorizationManagementClient       = new AuthorizationMgmtClient(subscriptionId, _restClient);
            _aksManagementClient                 = new AksMgmtClient(subscriptionId, _restClient);
            _signalRManagementClient             = new SignalRMgmtClient(subscriptionId, _restClient);
        }
        protected async Task GenerateAzureResourceNamesAsync(
            CancellationToken cancellationToken = default
            )
        {
            // It might happen that there is no registered resource provider
            // found for specified location and/or api version to perform name
            // availability check. In these cases, we will silently ignore
            // errors and just use generated random names.
            const string notAvailableApiFormat = "Name availability APIs are not available for '{0}'";

            // KeyVault names
            try {
                _keyVaultName = await _keyVaultManagementClient
                                .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "KeyVault");
                _keyVaultName = KeyVaultMgmtClient.GenerateName();
            }

            // Storage Account names
            try {
                _storageAccountName = await _storageManagementClient
                                      .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "Storage Account");
                _storageAccountName = StorageMgmtClient.GenerateStorageAccountName();
            }

            // IoT hub names
            try {
                _iotHubName = await _iotHubManagementClient
                              .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "IoT Hub");
                _iotHubName = IotHubMgmtClient.GenerateIotHubName();
            }

            // CosmosDB names
            try {
                _cosmosDBAccountName = await _cosmosDBManagementClient
                                       .GenerateAvailableNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "CosmosDB Account");
                _cosmosDBAccountName = CosmosDBMgmtClient.GenerateCosmosDBAccountName();
            }

            // Service Bus Namespace names
            try {
                _serviceBusNamespaceName = await _serviceBusManagementClient
                                           .GenerateAvailableNamespaceNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "ServiceBus Namespace");
                _serviceBusNamespaceName = ServiceBusMgmtClient.GenerateNamespaceName();
            }

            // Event Hub Namespace names
            try {
                _eventHubNamespaceName = await _eventHubManagementClient
                                         .GenerateAvailableNamespaceNameAsync(cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "EventHub Namespace");
                _eventHubNamespaceName = EventHubMgmtClient.GenerateEventHubNamespaceName();
            }

            _eventHubName = EventHubMgmtClient.GenerateEventHubName();

            // Operational Insights workspace name.
            _operationalInsightsWorkspaceName = OperationalInsightsMgmtClient.GenerateWorkspaceName();

            // Application Insights name.
            _applicationInsightsName = ApplicationInsightsMgmtClient.GenerateName();

            // AppService Plan name
            _appServicePlanName = WebSiteMgmtClient.GenerateAppServicePlanName(_applicationName);
            _azureWebsiteName   = _applicationName;

            // Networking names
            _networkSecurityGroupName = NetworkMgmtClient.GenerateNetworkSecurityGroupName();
            //_routTableName = NetworkMgmtClient.GenerateRoutTableName();
            _virtualNetworkName = NetworkMgmtClient.GenerateVirtualNetworkName();
            //_networkInterfaceName = NetworkMgmtClient.GenerateNetworkInterfaceName();
            //_publicIPAddressName = NetworkMgmtClient.GeneratePublicIPAddressName();
            //_domainNameLabel = SdkContext.RandomResourceName(_applicationName + "-", 5);

            // AKS cluster name
            _aksClusterName = AksMgmtClient.GenerateName();

            // SignalR name
            try {
                _signalRName = await _signalRManagementClient
                               .GenerateAvailableNameAsync(_resourceGroup, cancellationToken);
            }
            catch (Microsoft.Rest.Azure.CloudException) {
                Log.Warning(notAvailableApiFormat, "SignalR");
                _signalRName = SignalRMgmtClient.GenerateName();
            }
        }