Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #5
0
        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);
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        /// <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);
        }
Beispiel #10
0
        /// <summary>
        /// Gets an armTemplateParameter within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the armTemplateParameter to get.</param>
        /// <returns>The armTemplateParameter object.</returns>
        public async Task <ArmTemplateParameter> GetAsync(string offerName, string name)
        {
            // Check that an armTemplateParameter with the provided name exists within the given offer
            if (!(await ExistsAsync(offerName, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(ArmTemplateParameter).Name,
                                                                                             name, offerName: offerName));
            }

            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Find the armTemplateParameter that matches the name provided
            var armTemplateParameter = await _context.ArmTemplateParameters
                                       .SingleOrDefaultAsync(a => (a.OfferId == offer.Id) && (a.Name == name));

            _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(ArmTemplateParameter).Name,
                                                                          name,
                                                                          JsonSerializer.Serialize(armTemplateParameter),
                                                                          offerName: offerName));

            return(armTemplateParameter);
        }