/// <summary> /// Build the request URI /// </summary> /// <param name="subscriptionId">ISV Azure subscription id</param> /// <param name="resourceGroup">ISV Azure resource group</param> /// <param name="deploymentName"></param> /// <returns></returns> private Uri GetRequestUri( string subscriptionId, string resourceGroup, string deploymentName = default ) { var requestUri = String.IsNullOrEmpty(deploymentName) ? FluentUriBuilder.Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId) .AddPath("resourceGroups") .AddPath(resourceGroup) .AddQuery("api-version", _apiVersion) : FluentUriBuilder.Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId) .AddPath("resourcegroups") .AddPath(resourceGroup) .AddPath("providers/Microsoft.Resources/deployments") .AddPath(deploymentName) .AddQuery("api-version", _apiVersion); return(requestUri.Uri); }
private string BuildLink(List <Tuple <string, string> > queryParams, string controllerName, string controllerAction) { var uriStart = FluentUriBuilder.Start(this.options.BaseUrl).AddPath(controllerName).AddPath(controllerAction); foreach (var(item1, item2) in queryParams) { uriStart.AddQuery(item1, item2); } return(uriStart.Uri.ToString()); }
public async Task <UpdateOrDeleteSubscriptionRequestResult> UpdateSubscriptionAsync( Guid subscriptionId, ActivatedSubscriptionResult update, Guid requestId, Guid correlationId, CancellationToken cancellationToken = default) { try { var requestUrl = FluentUriBuilder .Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId.ToString()) .AddQuery(DefaultApiVersionParameterName, _apiVersion) .Uri; requestId = requestId == default ? Guid.NewGuid() : requestId; correlationId = correlationId == default ? Guid.NewGuid() : correlationId; var updateContent = JsonConvert.SerializeObject(update); if (!string.IsNullOrEmpty(update.PlanId) && !string.IsNullOrEmpty(update.Quantity)) { string fulfillmentRestrictionMessage = "Only a plan or quantity can be patched at one time, not both"; throw new LunaConflictUserException(fulfillmentRestrictionMessage); } var bearerToken = await _keyVaultHelper.GetBearerToken( _options.AzureActiveDirectory, _options.ClientService.AuthenticationResourceId); var response = await SendRequestAndReturnResult( new HttpMethod("PATCH"), requestUrl, requestId, correlationId, bearerToken, null, updateContent, cancellationToken); return(await FulfillmentRequestResult.ParseAsync <UpdateOrDeleteSubscriptionRequestResult>(response)); } catch (LunaServerException e) { throw new LunaFulfillmentException($"Cannot update subscription {subscriptionId}.", e); } }
private string BuildALink( string controllerAction, IEnumerable <Tuple <string, string> > queryParams, string innerText, string controllerName = MailLinkControllerName) { var uriStart = FluentUriBuilder.Start(this.options.BaseUrl).AddPath(controllerName) .AddPath(controllerAction); foreach (var(item1, item2) in queryParams) { uriStart.AddQuery(item1, item2); } var href = uriStart.Uri.ToString(); return($"<a href=\"{href}\">{innerText}</a>"); }
public async Task <CustomMeteringRequestResult> RecordUsageAsync(Guid requestId, Guid correlationId, Usage usage, CancellationToken cancellationToken) { var requestUrl = FluentUriBuilder .Start(_baseUri) .AddPath("usageEvent") .AddQuery(DefaultApiVersionParameterName, _apiVersion) .Uri; requestId = requestId == default ? Guid.NewGuid() : requestId; correlationId = correlationId == default ? Guid.NewGuid() : correlationId; var bearerToken = await _keyVaultHelper.GetBearerToken( _options.AzureActiveDirectory, _options.ClientService.AuthenticationResourceId); var response = await this.SendRequestAndReturnResult( HttpMethod.Post, requestUrl, requestId, correlationId, bearerToken, null, JsonConvert.SerializeObject(usage), cancellationToken); _logger.LogInformation($"RecordUsageAsync response: {response}"); switch (response.StatusCode) { case HttpStatusCode.OK: return(await HttpRequestResult.ParseAsync <CustomMeteringSuccessResult>(response)); case HttpStatusCode.Forbidden: return(await HttpRequestResult.ParseAsync <CustomMeteringForbiddenResult>(response)); case HttpStatusCode.Conflict: return(await HttpRequestResult.ParseAsync <CustomMeteringConflictResult>(response)); case HttpStatusCode.BadRequest: return(await HttpRequestResult.ParseAsync <CustomMeteringBadRequestResult>(response)); default: throw new LunaServerException($"Unknown response from the API {await response.Content.ReadAsStringAsync()}"); } }
public async Task <IEnumerable <SubscriptionOperation> > GetSubscriptionOperationsAsync( Guid subscriptionId, Guid requestId, Guid correlationId, CancellationToken cancellationToken = default) { try { var requestUrl = FluentUriBuilder .Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId.ToString()) .AddPath("operations") .AddQuery(DefaultApiVersionParameterName, _apiVersion) .Uri; requestId = requestId == default ? Guid.NewGuid() : requestId; correlationId = correlationId == default ? Guid.NewGuid() : correlationId; var bearerToken = await _keyVaultHelper.GetBearerToken( _options.AzureActiveDirectory, _options.ClientService.AuthenticationResourceId); var response = await SendRequestAndReturnResult( HttpMethod.Get, requestUrl, requestId, correlationId, bearerToken, null, "", cancellationToken); if (_apiVersion == mockApiVersion) { return(await FulfillmentRequestResult.ParseMultipleAsync <SubscriptionOperation>(response)); } return((await FulfillmentRequestResult.ParseAsync <SubscriptionOperationResult>(response)).Operations); } catch (LunaServerException e) { throw new LunaFulfillmentException($"Cannot get operations for subscription {subscriptionId}.", e); } }
public async Task <FulfillmentRequestResult> UpdateSubscriptionOperationAsync( Guid subscriptionId, Guid operationId, OperationUpdate update, Guid requestId, Guid correlationId, CancellationToken cancellationToken = default) { try { var requestUrl = FluentUriBuilder .Start(_baseUri) .AddPath("subscriptions") .AddPath(subscriptionId.ToString()) .AddPath("operations") .AddPath(operationId.ToString()) .AddQuery(DefaultApiVersionParameterName, _apiVersion) .Uri; requestId = requestId == default ? Guid.NewGuid() : requestId; correlationId = correlationId == default ? Guid.NewGuid() : correlationId; var bearerToken = await _keyVaultHelper.GetBearerToken( _options.AzureActiveDirectory, _options.ClientService.AuthenticationResourceId); var response = await SendRequestAndReturnResult( new HttpMethod("PATCH"), requestUrl, requestId, correlationId, bearerToken, null, JsonConvert.SerializeObject(update), cancellationToken); return(await FulfillmentRequestResult.ParseAsync <ResolvedSubscriptionResult>(response)); } catch (LunaServerException e) { throw new LunaFulfillmentException($"Cannot update operation {operationId} for subscription {subscriptionId}.", e); } }
/// <summary> /// /// </summary> /// <param name="marketplaceToken"> /// Token query parameter in the URL when the user is redirected to the SaaS ISV’s website from Azure. /// Note: The URL decodes the token value from the browser before using it. /// This token is valid only for 1 hour /// </param> /// <param name="requestId"></param> /// <param name="correlationId"></param> /// <param name="bearerToken"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ResolvedSubscriptionResult> ResolveSubscriptionAsync( string marketplaceToken, Guid requestId, Guid correlationId, CancellationToken cancellationToken = default) { try { var requestUrl = FluentUriBuilder .Start(_baseUri) .AddPath("subscriptions") .AddPath("resolve") .AddQuery(DefaultApiVersionParameterName, _apiVersion) .Uri; requestId = requestId == default ? Guid.NewGuid() : requestId; correlationId = correlationId == default ? Guid.NewGuid() : correlationId; var bearerToken = await _keyVaultHelper.GetBearerToken( _options.AzureActiveDirectory, _options.ClientService.AuthenticationResourceId); var response = await SendRequestAndReturnResult( HttpMethod.Post, requestUrl, requestId, correlationId, bearerToken, r => { r.Headers.Add("x-ms-marketplace-token", marketplaceToken); }, "", cancellationToken); return(await FulfillmentRequestResult.ParseAsync <ResolvedSubscriptionResult>(response)); } catch (LunaServerException e) { throw new LunaFulfillmentException("Cannot resolve subscription.", e); } }