예제 #1
0
        private async Task <DnsNameAvailabilityResult> CheckDnsNameAvailability(string subscriptionId, string location, string dnsPrefix)
        {
            try
            {
                var endpointUrl   = string.Format(UriConstants.CheckDnsNameAvailabilityUri, subscriptionId, location, dnsPrefix);
                var restApiClient = new RestApiClient();
                var result        = await restApiClient.CallGetAsync <DnsNameAvailabilityResult>(endpointUrl, await ServicePrincipal.GetAccessToken());

                Log.Info(TemplateHelper.ToJson(result));

                if (result.Success)
                {
                    return(result.Result);
                }

                Log.Error(result.Message);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(new DnsNameAvailabilityResult()
            {
                Available = false
            });
        }
        public async Task <JsonResult> GetAzureAsyncOperationStatus([FromUri] string url)
        {
            Log.Info($"Requesting status for Azure async operation: {url}");
            IRestApiClient restApiClient = new RestApiClient();
            var            response      = await restApiClient.CallGetAsync <AzureAsyncOperationStatusResponse>(
                url,
                await ServicePrincipal.GetAccessToken());

            Log.Info($"Async operation status response: {TemplateHelper.ToJson(response)}");

            if (!response.Success)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(response.Message, JsonRequestBehavior.AllowGet));
            }

            return(Json(response.Result, JsonRequestBehavior.AllowGet));
        }
        public async Task <JsonResult> GetDeployOutputParameters([FromUri] string url)
        {
            Log.Info($"Receiving output parameters from deployment: {url}");

            IRestApiClient restApiClient = new RestApiClient();
            var            response      = await restApiClient.CallGetAsync <DeploymentExtended>(
                url,
                await ServicePrincipal.GetAccessToken());

            Log.Info($"Output parameters response: {TemplateHelper.ToJson(response)}");

            if (!response.Success)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(response.Message, JsonRequestBehavior.AllowGet));
            }

            return(Json(TemplateHelper.ToJson(response.Result?.Properties?.Outputs), JsonRequestBehavior.AllowGet));
        }
        public async Task <ResourceGroup> GetResourceGroupByName(
            string subscriptionId,
            string resourceGroupName
            )
        {
            Log.Info($"Getting resource group by name. Subscription ID: {subscriptionId}, Name: {resourceGroupName}");
            var endpointUri = string.Format(UriConstants.GetResourceGroupUri, subscriptionId, resourceGroupName);
            var client      = new RestApiClient();
            var result      = await client.CallGetAsync <ResourceGroup>(endpointUri, await ServicePrincipal.GetAccessToken());

            Log.Info($"Resouce group result: {TemplateHelper.ToJson(result)}");

            if (!result.Success)
            {
                throw new ServiceCatalogException(result.Message);
            }

            return(result.Result);
        }