Exemple #1
0
 public IActionResult Hello()
 {
     // Required response format.
     return(ContosoController.CreateResponse(
                statusCode: HttpStatusCode.OK,
                value: "hELLO"));
 }
Exemple #2
0
        /// <summary>
        /// Validates if resource can be created.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="resourceGroup">The resource group.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="tenantId">The tenant Id.</param>
        private async Task <IActionResult> ValidateResourceCreation(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string tenantId)
        {
            var errorResponse = this.ValidateAndGetErrorResponse(
                subscriptionId: subscriptionId,
                resourceGroup: resourceGroup,
                providerNamespace: providerNamespace,
                resourceType: resourceType,
                responseMessage: "SampleErrorMessage - Please don't create this resource. This is dangerous.");

            if (errorResponse == null)
            {
                return(await this
                       .ValidateMaximumResourceCounts(
                           subscriptionId : subscriptionId,
                           resourceGroup : resourceGroup,
                           providerNamespace : providerNamespace,
                           resourceType : resourceType,
                           tenantId : tenantId)
                       .ConfigureAwait(continueOnCapturedContext: false));
            }

            // Required response format in case of validation failure.
            return(ContosoController.CreateResponse(
                       statusCode: HttpStatusCode.OK,
                       value: errorResponse));
        }
Exemple #3
0
        public IActionResult OnResourceCreationBegin(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string resourceName)
        {
            /*** Implement this method if you want to opt for "ResourceCreationBegin" extension for your resource type. ***/
            Logger.LogMessage("OnResourceCreationBegin called");

            // Required response format.
            return(ContosoController.CreateResponse(
                       statusCode: HttpStatusCode.OK,
                       value: this.AppendResourceWithInternalMetadata()));
        }
Exemple #4
0
        /// <summary>
        /// Validates if resource can be deleted.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="resourceGroup">The resource group.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        private IActionResult ValidateResourceDeletion(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType)
        {
            var errorResponse = this.ValidateAndGetErrorResponse(
                subscriptionId: subscriptionId,
                resourceGroup: resourceGroup,
                providerNamespace: providerNamespace,
                resourceType: resourceType,
                responseMessage: "SampleErrorMessage - Please don't delete this resource. This is important.");

            // Required response format in case of validation failure.
            return(ContosoController.CreateResponse(
                       statusCode: HttpStatusCode.OK,
                       value: errorResponse));
        }
Exemple #5
0
        /// <summary>
        /// Validates if the number of resources in the resource group is under the limit.
        /// </summary>
        /// <param name="subscriptionId">The subscription Id.</param>
        /// <param name="resourceGroup">The resource group.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="tenantId">The tenant Id.</param>
        private async Task <IActionResult> ValidateMaximumResourceCounts(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string tenantId)
        {
            ErrorResponse errorRespone = null;

            // Call into ARM to get all resources of this resource type within the resource group.
            var resourceCollectionUri = UriEngine.GetResourceGroupResourceRequestUri(
                endpoint: this.ArmEndpoint,
                subscriptionId: subscriptionId,
                resourceGroupName: resourceGroup,
                resourceProviderNamespace: providerNamespace,
                resourceType: resourceType,
                resourceName: null,
                apiVersion: this.ApiVersion);

            var responseFromARM = await this.CallRPSaaSForMetadata(resourceCollectionUri, tenantId, HttpMethod.Get).ConfigureAwait(false);

            Logger.LogMessage($"Response status from ARM: '{responseFromARM.StatusCode}'");

            if (responseFromARM.StatusCode == HttpStatusCode.OK)
            {
                var reader              = new StreamReader(await responseFromARM.Content.ReadAsStreamAsync().ConfigureAwait(false));
                var responseContent     = reader.ReadToEnd();
                var resourcesCollection = JsonConvert.DeserializeObject <ResponseWithContinuation <Resource[]> >(responseContent);

                if (resourcesCollection.Value != null)
                {
                    // Return error if we have more than max count resources of this type in the resource group.
                    if (resourcesCollection.Value.Count() >= this.MaxCount)
                    {
                        errorRespone = new ErrorResponse
                        {
                            Error = new Error
                            {
                                Code    = "SampleValidationErrorCode",
                                Message = "SampleValidationErrorMessage - Maximum number of resources per resource group count hit.",
                            },
                            Status = "Failed",
                        };
                    }
                }
            }

            // Required response format in case of validation failure.
            return(ContosoController.CreateResponse(
                       statusCode: HttpStatusCode.OK,
                       value: errorRespone));
        }
Exemple #6
0
        public async Task <IActionResult> OnResourceCreationCompleted(string subscriptionId, string resourceGroup, string providerNamespace, string resourceType, string resourceName)
        {
            /*** Implement this method if you want to opt for "OnResourceCreationCompleted" extension for your resource type. ***/
            Logger.LogMessage("OnResourceCreationCompleted called");

            // Do post creation processing here ex: start billing
            await this
            .CompleteResourceCreation(
                subscriptionId : subscriptionId,
                resourceGroup : resourceGroup,
                providerNamespace : providerNamespace,
                resourceType : resourceType,
                resourceName : resourceName,
                tenantId : this.Request.Headers["x-ms-client-tenant-id"]).ConfigureAwait(false);

            // Required response format with empty body.
            return(ContosoController.CreateResponse(statusCode: HttpStatusCode.OK));
        }
Exemple #7
0
        public async Task <IActionResult> OnSubscriptionLifeCycleNotification(string subscriptionId, string providerNamespace, string resourceType)
        {
            /*** Implement this method if you want to opt for "SubscriptionLifeCycleNotification" extension for your resource type. ***/
            Logger.LogMessage("OnSubscriptionLifeCycleNotification called");

            // Do subscription state change validation here
            // This is a sample implementation
            // We also use OData $filter in this sample.
            await this
            .ValidateSubscriptionLifeCycleNotification(
                subscriptionId : subscriptionId,
                providerNamespace : providerNamespace,
                resourceType : resourceType,
                tenantId : this.Request.Headers["x-ms-client-tenant-id"])
            .ConfigureAwait(false);

            // Required response format with empty body.
            return(ContosoController.CreateResponse(statusCode: HttpStatusCode.OK));
        }