/// <summary> /// Gets a customMeterDimension by id. /// </summary> /// <param name="id">The id of the customMeterDimension.</param> /// <returns>The customMeterDimension.</returns> public async Task <CustomMeterDimension> GetAsync(string offerName, string planName, string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeterDimension).Name, meterName, planName, offerName)); var meter = await _customMeterService.GetAsync(offerName, meterName); var plan = await _planService.GetAsync(offerName, planName); // Find the customMeterDimension that matches the id provided var customMeterDimension = await _context.CustomMeterDimensions.SingleOrDefaultAsync(c => c.PlanId == plan.Id && c.MeterId == meter.Id); // Check that an customMeterDimension with the provided id exists if (customMeterDimension is null) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeterDimension).Name, meterName, planName, offerName)); } // Set the customMeterDimension's meterName customMeterDimension.MeterName = meter.MeterName; customMeterDimension.PlanName = plan.PlanName; _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(CustomMeterDimension).Name, meterName, JsonSerializer.Serialize(customMeterDimension), planName, offerName)); return(customMeterDimension); }
/// <summary> /// Gets a restructedUser /// </summary> /// <param name="offerName">The offer name.</param> /// <param name="planName">The plan name.</param> /// <param name="tenantId">The tenant id.</param> /// <returns>The restrictedUser.</returns> public async Task <RestrictedUser> GetAsync(string offerName, string planName, Guid tenantId) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName)); // Check that a restrictedUser with the provided tenantId var plan = await _planService.GetAsync(offerName, planName); // Get all restrictedUsers with a FK to the plan var restrictedUser = await _context.RestrictedUsers.SingleAsync(r => r.PlanId == plan.Id && r.TenantId == tenantId); // Check that an restrictedUser with the provided id exists if (restrictedUser is null) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(RestrictedUser).Name, tenantId.ToString())); } _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(RestrictedUser).Name, tenantId.ToString(), JsonSerializer.Serialize(restrictedUser), offerName: offerName, planName: planName)); return(restrictedUser); }
/// <summary> /// Gets a SubscriptionCustomMeterUsage. /// </summary> /// <param name="subscriptionId">The subscription id.</param> /// <param name="meterName">The name of the SubscriptionCustomMeterUsage.</param> /// <returns>The SubscriptionCustomMeterUsage.</returns> public async Task <SubscriptionCustomMeterUsage> GetAsync(Guid subscriptionId, string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName)); if (!(await ExistsAsync(subscriptionId, meterName))) { throw new LunaNotFoundUserException( LoggingUtils.ComposeNotFoundErrorMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, subscriptionId: subscriptionId)); } var subscription = await _subscriptionService.GetAsync(subscriptionId); // Get the subscriptionCustomMeterUsage that matches the provided subscription id and meterName var customMeter = await _customMeterService.GetAsync(subscription.OfferName, meterName); var subscriptionCustomMeterUsage = await _context.SubscriptionCustomMeterUsages .SingleOrDefaultAsync(c => c.MeterId == customMeter.Id && c.SubscriptionId.Equals(subscriptionId)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage( typeof(SubscriptionCustomMeterUsage).Name, meterName, JsonSerializer.Serialize(subscriptionCustomMeterUsage))); return(subscriptionCustomMeterUsage); }
/// <summary> /// Gets an aadSecretTmp within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="name">The name of the aadSecretTmp to get.</param> /// <returns>An aadSecretTmp object.</returns> public async Task <AadSecretTmp> GetAsync(string offerName, string name) { // Check that an aadSecretTmp with the provided name exists within the given offer if (!(await ExistsAsync(offerName, name))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(AadSecretTmp).Name, name, offerName: offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(AadSecretTmp).Name, name, offerName: offerName)); // Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Find the aadSecretTmp that matches the name provided var aadSecretTmp = await _context.AadSecretTmps .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.Name == name)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(AadSecretTmp).Name, name, JsonSerializer.Serialize(aadSecretTmp), offerName: offerName)); return(aadSecretTmp); }
/// <summary> /// Gets a plan within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="planUniqueName">The name of the plan to get.</param> /// <returns>The plan.</returns> public async Task <Plan> GetAsync(string offerName, string planUniqueName) { // Check that a plan with the provided planUniqueName exists within the given offer if (!(await ExistsAsync(offerName, planUniqueName))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Plan).Name, planUniqueName, offerName: offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Plan).Name, planUniqueName, offerName: offerName)); // Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Find the plan that matches the planUniqueName provided var plan = await _context.Plans .SingleOrDefaultAsync(p => (p.OfferId == offer.Id) && (p.PlanName == planUniqueName)); plan = await SetArmTemplateAndWebhookNames(plan); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Plan).Name, planUniqueName, JsonSerializer.Serialize(plan), offerName: offerName)); return(plan); }
/// <summary> /// Gets a customMeter. /// </summary> /// <param name="offerName">The offer name of the customMeter.</param> /// <param name="meterName">The name of the customMeter.</param> /// <returns>The customMeter.</returns> public async Task <CustomMeter> GetAsync(string offerName, string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeter).Name, meterName, offerName: offerName)); if (!(await ExistsAsync(offerName, meterName))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeter).Name, meterName, offerName: offerName)); } var offer = await _offerService.GetAsync(offerName); // Get the customMeter that matches the provided meterName var customMeter = await _context.CustomMeters.SingleOrDefaultAsync(c => c.OfferId == offer.Id && c.MeterName == meterName); customMeter.OfferName = offerName; var connector = await _context.TelemetryDataConnectors.FindAsync(customMeter.TelemetryDataConnectorId); customMeter.TelemetryDataConnectorName = connector.Name; _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage( typeof(CustomMeter).Name, meterName, JsonSerializer.Serialize(customMeter), offerName: offerName)); return(customMeter); }
/// <summary> /// Gets a webhook within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="webhookName">The name of the webhook to get.</param> /// <returns>The webhook.</returns> public async Task <Webhook> GetAsync(string offerName, string webhookName) { // Check that a webhook with the provided webhook exists within the given offer if (!(await ExistsAsync(offerName, webhookName))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Webhook).Name, webhookName, offerName: offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Webhook).Name, webhookName, offerName: offerName)); // Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Find the webhook that matches the webhookName provided var webhook = await _context.Webhooks .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.WebhookName == webhookName)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Webhook).Name, webhookName, JsonSerializer.Serialize(webhook), offerName: offerName)); return(webhook); }
/// <summary> /// Gets an ipConfig within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="name">The name of the ipConfig to get.</param> /// <returns>The ipConfig.</returns> public async Task <IpConfig> GetAsync(string offerName, string name) { // Check that an ipConfig with the provided name exists within the given offer if (!(await ExistsAsync(offerName, name))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(IpConfig).Name, name, offerName: offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(IpConfig).Name, name, offerName: offerName)); // Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Find the ipConfig that matches the name provided var ipConfig = await _context.IpConfigs .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.Name == name)); // Populate the IpBlocks this IpConfig has ipConfig.IpBlocks = await GetIpBlocks(ipConfig.Id); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(IpConfig).Name, name, JsonSerializer.Serialize(ipConfig), offerName: offerName)); return(ipConfig); }
/// <summary> /// Gets a plan by its id. /// </summary> /// <param name="planId">The plan id</param> /// <returns>The plan.</returns> public async Task <Plan> GetByIdAsync(long planId) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Plan).Name, planId.ToString())); // Find the plan that matches the plan id provided var plan = await _context.Plans .SingleOrDefaultAsync(p => (p.Id == planId)); plan = await SetArmTemplateAndWebhookNames(plan); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Plan).Name, planId.ToString(), JsonSerializer.Serialize(plan))); return(plan); }
/// <summary> /// Gets an offer by name. /// </summary> /// <param name="offerName">The name of the offer to get.</param> /// <returns>The offer.</returns> public async Task <Offer> GetAsync(string offerName) { if (!await ExistsAsync(offerName)) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Offer).Name, offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Offer).Name, offerName)); // Get the offer that matches the provided offerName and that has not been deleted var offer = await _context.Offers.SingleOrDefaultAsync(o => (o.OfferName == offerName) && (o.DeletedTime == null)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Offer).Name, offerName, JsonSerializer.Serialize(offer))); return(offer); }
/// <summary> /// Gets a customMeter. /// </summary> /// <param name="meterName">The name of the customMeter.</param> /// <returns>The customMeter.</returns> public async Task <CustomMeter> GetAsync(string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeter).Name, meterName)); if (!(await ExistsAsync(meterName))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeter).Name, meterName)); } // Get the customMeter that matches the provided meterName var customMeter = await _context.CustomMeters.SingleOrDefaultAsync(c => c.MeterName == meterName); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage( typeof(CustomMeter).Name, meterName, JsonSerializer.Serialize(customMeter))); return(customMeter); }
public async Task <SubscriptionParameter> GetAsync(Guid subscriptionId, string name) { // Check that an armTemplateParameter with the provided name exists within the given offer if (!(await ExistsAsync(subscriptionId, name))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(SubscriptionParameter).Name, name)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(SubscriptionParameter).Name, name)); // Find the armTemplateParameter that matches the name provided var parameter = await _context.SubscriptionParameters .SingleOrDefaultAsync(p => (p.SubscriptionId == subscriptionId) && (p.Name == name)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(SubscriptionParameter).Name, name, JsonSerializer.Serialize(parameter), subscriptionId: subscriptionId)); return(parameter); }
/// <summary> /// Gets a TelemetryDataConnector. /// </summary> /// <param name="name">The name of the TelemetryDataConnector.</param> /// <returns>The TelemetryDataConnector.</returns> public async Task <TelemetryDataConnector> GetAsync(string name) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(TelemetryDataConnector).Name, name)); if (!(await ExistsAsync(name))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name, name)); } // Get the TelemetryDataConnector that matches the provided meterName var connector = await _context.TelemetryDataConnectors.SingleOrDefaultAsync(c => c.Name == name); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage( typeof(TelemetryDataConnector).Name, name, JsonSerializer.Serialize(connector))); return(connector); }
/// <summary> /// Gets a subscription by id. /// </summary> /// <param name="subscriptionId">The id of the subscription.</param> /// <returns>The subscription.</returns> public async Task <Subscription> GetAsync(Guid subscriptionId) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(Subscription).Name, subscriptionId.ToString())); // Find the subscription that matches the subscriptionId provided var subscription = await _context.Subscriptions.FindAsync(subscriptionId); // Check if subscription exists if (subscription is null) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Subscription).Name, subscriptionId.ToString())); } subscription.OfferName = (await _context.Offers.FindAsync(subscription.OfferId)).OfferName; subscription.PlanName = (await _context.Plans.FindAsync(subscription.PlanId)).PlanName; _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(Subscription).Name, subscriptionId.ToString(), JsonSerializer.Serialize(subscription))); return(subscription); //Task.FromResult(subscription); }
/// <summary> /// Gets an armTemplate within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="templateName">The name of the armTemplate to get.</param> /// <param name="useSaSKey">Specify if use SaS key in the uri</param> /// <returns>The armTemplate.</returns> public async Task <ArmTemplate> GetAsync(string offerName, string templateName, bool useSaSKey = true) { if (!await _offerService.ExistsAsync(offerName)) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Offer).Name, offerName)); } // Check that an armTemplate with the provided templateName exists within the given offer if (!(await ExistsAsync(offerName, templateName))) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName)); } _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName)); // Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Find the armTemplate that matches the templateName provided var armTemplate = await _context.ArmTemplates .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.TemplateName == templateName)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(ArmTemplate).Name, templateName, JsonSerializer.Serialize(armTemplate), offerName: offerName)); if (useSaSKey) { // Generate Sas key armTemplate.TemplateFilePath = await _storageUtility.GetFileReferenceWithSasKeyAsync(armTemplate.TemplateFilePath); } _logger.LogInformation("Sas key generated."); return(armTemplate); }
/// <summary> /// Gets a customMeterDimension by id. /// </summary> /// <param name="id">The id of the customMeterDimension.</param> /// <returns>The customMeterDimension.</returns> public async Task <CustomMeterDimension> GetAsync(long id) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeterDimension).Name, id.ToString())); // Find the customMeterDimension that matches the id provided var customMeterDimension = await _context.CustomMeterDimensions.FindAsync(id); // Check that an customMeterDimension with the provided id exists if (customMeterDimension is null) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeterDimension).Name, id.ToString())); } // Set the customMeterDimension's meterName customMeterDimension.MeterName = (await _context.CustomMeters.FindAsync(customMeterDimension.MeterId)).MeterName; _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(CustomMeterDimension).Name, id.ToString(), JsonSerializer.Serialize(customMeterDimension))); return(customMeterDimension); }
public async Task <ActionResult> GetAsync(string offerName, string templateName) { AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, true); _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName)); return(Ok(await _armTemplateService.GetAsync(offerName, templateName))); }