Exemplo n.º 1
0
        public static async Task <IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
                                                          [ResourceDeployment("CLIENT_ID", "CLIENT_PASS", "TENANT_ID")] IAsyncCollector <ResourceDeploymentContext> collector,
                                                          TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // If you want to manually deploy or control resource, use this.
            //  var azure = ((ResourceDeploymentCollector)collector).GetClient();

            var parameter  = JsonConvert.SerializeObject(new TemplateParameter("resourceBindingSample5"));
            var deployment = new ResourceDeploymentContext("testResource5", "https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-function-app-create-dynamic/azuredeploy.json", parameter, "testResource5", "westus");

            await collector.AddAsync(deployment); // This execute deployment

            return((ActionResult) new OkObjectResult($"I've done the provioning."));
        }
Exemplo n.º 2
0
        public static async Task <IActionResult> CreateFunctionApp(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "functionapp")] HttpRequest req,
            [CosmosDB(
                 databaseName: "FunctionAppDB",
                 collectionName: "FunctionApp",
                 CreateIfNotExists = true,
                 ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector <FunctionApp> functionApp,
            [ResourceDeployment("CLIENT_ID", "CLIENT_PASS", "TENANT_ID")] IAsyncCollector <ResourceDeploymentContext> deployment,
            ILogger log)
        {
            try
            {
                string      requestBody = new StreamReader(req.Body).ReadToEnd();
                FunctionApp input       = JsonConvert.DeserializeObject <FunctionApp>(requestBody);
                if (input.Id == null)
                {
                    input.Id = Guid.NewGuid().ToString();
                }

                if (input.TemplateURL == null)
                {
                    input.TemplateURL = "https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-function-app-create-dynamic/azuredeploy.json";
                }

                input.CreatedDate = DateTimeOffset.Now;

                var parameter         = JsonConvert.SerializeObject(new TemplateParameter(input.Name));
                var deploymentContext = new ResourceDeploymentContext("functionAppDeploy", input.TemplateURL, parameter, input.ResourceGroup, input.Location);

                await deployment.AddAsync(deploymentContext); // This execute deployment

                log.LogInformation($"FunctionApp {input.Name} has been created.");

                // If success you write cosmos db record for managing functions apps.

                await functionApp.AddAsync(input);

                return((ActionResult) new OkObjectResult(JsonConvert.SerializeObject(input)));
            } catch (Exception e)
            {
                log.LogInformation($"CreateFunctionApp: Error: {e.Message} : {e.StackTrace}");
                return((ActionResult) new System.Web.Http.ExceptionResult(e, true));
            }
        }