示例#1
0
        public async Task <JObject> generateDefinition(JObject resource)
        {
            ARMTemplateClass template = new ARMTemplateClass();



            return(JObject.FromObject(template));
        }
        public async Task <JObject> generateDefinition(JObject resource)
        {
            ARMTemplateClass template = new ARMTemplateClass();
            var paramiaName           = template.AddParameter("IntegrationAccountName", "string", integrationAccount);
            var uri         = resource["properties"]["contentLink"].Value <string>("uri").Split('?');
            var rawresource = await resourceCollector.GetRawResource(uri[0], uri[1].Replace("api-version=", ""));

            var paramResourceName = template.AddParameter("name", "string", resource.Value <string>("name"));

            //create the resource and add to the template
            var obj = new IntegationAccountResource();

            obj.name = $"[concat(parameters('{paramiaName}'), '/' ,parameters('{paramResourceName}'))]";
            obj.type = resource.Value <string>("type");
            //add the current Integration Account parameter name
            var location = template.AddParameter("integrationAccountLocation", "string", "[resourceGroup().location]");

            obj.location = "[parameters('integrationAccountLocation')]";

            if (type == ARtifactType.Maps)
            {
                obj.properties["mapType"]          = resource["properties"]["mapType"];
                obj.properties["parametersSchema"] = resource["properties"]["parametersSchema"];
                obj.properties["contentType"]      = obj.properties.Value <string>("mapType") == "Liquid" ? "text/plain" : "application/xml";
            }
            else if (type == ARtifactType.Schemas)
            {
                obj.properties["schemaType"]  = resource["properties"]["schemaType"];
                obj.properties["contentType"] = "application/xml";
            }

            obj.properties["content"] = rawresource;

            template.resources.Add(JObject.FromObject(obj));

            return(JObject.FromObject(template));
        }
        /// <summary>
        /// Generate Definition for Schemas
        /// </summary>
        /// <param name="resource">resource definition from Azure</param>
        /// <param name="content">schema content, leave in here for depedency injection for testing</param>
        /// <returns></returns>
        public async Task <JObject> GenerateSchemaDefinition(JObject resource, string content = null)
        {
            ARMTemplateClass template  = new ARMTemplateClass();
            var integrationAccountName = template.AddParameter("IntegrationAccountName", "string", integrationAccount);
            var uri         = resource["properties"]["contentLink"].Value <string>("uri").Split('?');
            var rawresource = content;

            if (content == null)
            {
                rawresource = await resourceCollector.GetRawResource(uri[0], uri[1].Replace("api-version=", ""));
            }

            var paramResourceName = template.AddParameter("name", "string", resource.Value <string>("name"));

            //create the resource and add to the template
            var obj = new IntegationAccountResource();

            obj.name = $"[concat(parameters('{integrationAccountName}'), '/' ,parameters('{paramResourceName}'))]";
            obj.type = resource.Value <string>("type");
            //add the current Integration Account parameter name
            var location = template.AddParameter("integrationAccountLocation", "string", "[resourceGroup().location]");

            obj.location = "[parameters('integrationAccountLocation')]";



            obj.properties["schemaType"]   = resource["properties"]["schemaType"];
            obj.properties["documentName"] = resource["properties"]["documentName"];

            obj.properties["content"]     = rawresource;
            obj.properties["contentType"] = "application/xml";


            template.resources.Add(JObject.FromObject(obj));

            return(JObject.FromObject(template));
        }
示例#4
0
        // the apiDefinition parameter allows dependency injection for unit testing
        public async Task <JObject> generateDefinition(JObject resource, string apiDefinition = null)
        {
            ARMTemplateClass template = new ARMTemplateClass();

            template.AddParameter("customConnectorApiVersion", "string", "1.0.0.0");
            var name     = template.AddParameter("customConnectorName", "string", resource.Value <string>("name"));
            var location = template.AddParameter("customConnectorLocation", "string", "[resourceGroup().location]");

            var uri = resource["properties"]["apiDefinitions"].Value <string>("modifiedSwaggerUrl");

            string swaggerRawDefinition = apiDefinition ?? GetCustomConnectorSwagger(uri);

            JObject preParsedswaggerDefinition = JObject.Parse(swaggerRawDefinition);
            var     host = preParsedswaggerDefinition.Value <string>("host");

            //replace the host with a parameter to allow the scenarios where the host could be different between environments
            var serviceHost = template.AddParameter("serviceHost", "string", host);
            var scheme      = "http";

            if (preParsedswaggerDefinition.ContainsKey("schemes"))
            {
                scheme = preParsedswaggerDefinition["schemes"].Children().First().Value <string>();
            }
            var backendService = template.AddParameter("backendService", "string", scheme + "://" + host + preParsedswaggerDefinition.Value <string>("basePath"));

            swaggerRawDefinition = swaggerRawDefinition.Replace(host, template.WrapParameterName(serviceHost));

            // handle connectionID
            swaggerRawDefinition = swaggerRawDefinition.Replace(@"/{connectionId}", string.Empty);
            JObject swaggerDefinition = JObject.Parse(swaggerRawDefinition);

            // remove all connectionID parameters
            if (swaggerDefinition.ToString().Contains("connectionId"))
            {
                // note: only Json.Net 12.0.1 supports XPath like below, hence guarding with a try/catch just in case of older version of the libray
                try
                {
                    foreach (var token in swaggerDefinition["paths"].SelectTokens(@"$..[?(@.name === 'connectionId')]").ToList())
                    {
                        token.Remove();
                    }
                }
                catch (JsonException) { }
            }


            JObject resourceObject   = new JObject();
            JObject propertiesObject = new JObject();


            // handle ISE

            JToken origIseToken = resource["properties"].SelectToken("integrationServiceEnvironment");

            if (origIseToken != null)
            {
                var iseEnvName = template.AddParameter("ISEEnvironmentName", "string", origIseToken.Value <string>("name"));


                JObject         iseObject = new JObject();
                AzureResourceId iseId     = new AzureResourceId(origIseToken.Value <string>("id"));
                //iseObject.Add("id", origIseToken.Value<string>("id"));
                var iseEnvResouceGroup = template.AddParameter("ISEEnvironmentResourceGroup", "string", iseId.ResourceGroupName);
                iseId.SubscriptionId    = "subscription().subscriptionId";
                iseId.ResourceGroupName = template.WrapParameterName(iseEnvResouceGroup);
                iseId.ResourceName      = template.WrapParameterName(iseEnvName);

                iseObject.Add("id", $"[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/',parameters('{iseEnvResouceGroup}'), '/providers/Microsoft.Logic/integrationServiceEnvironments/', parameters('{iseEnvName}'))]");

                iseObject.Add("name", template.WrapParameterName(iseEnvName));
                iseObject.Add("type", origIseToken.Value <string>("type"));

                propertiesObject.Add("integrationServiceEnvironment", iseObject);
            }

            if (resource["properties"].SelectToken("connectionParameters") != null)
            {
                propertiesObject.Add("connectionParameters", resource["properties"]["connectionParameters"]);
            }

            JObject backendObject = new JObject();

            backendObject.Add("serviceUrl", template.WrapParameterName(backendService));   // $"[parameters('{serviceHost}')]");
            propertiesObject.Add("backendService", backendObject);

            propertiesObject.Add("swagger", swaggerDefinition);
            propertiesObject.Add("description", resource["properties"].Value <string>("description"));
            propertiesObject.Add("displayname", template.WrapParameterName(name));
            propertiesObject.Add("iconUri", resource["properties"].Value <string>("iconUri"));

            resourceObject.Add("apiVersion", "2019-05-01");
            resourceObject.Add("location", template.WrapParameterName(location));
            resourceObject.Add("name", template.WrapParameterName(name));
            resourceObject.Add("type", resource.Value <string>("type"));
            resourceObject.Add("properties", propertiesObject);

            template.resources.Add(resourceObject);

            return(JObject.FromObject(template));
        }