public ResourceTemplate CreateAPISchema(JObject restObject) { if (restObject == null) { return(null); } string name = restObject.Value <string>("name"); string type = restObject.Value <string>("type"); AzureResourceId apiid = new AzureResourceId(restObject.Value <string>("id")); string servicename = apiid.ValueAfter("service"); string apiname = apiid.ValueAfter("apis"); var obj = new ResourceTemplate(); obj.AddName($"parameters('{AddParameter($"service_{servicename}_name", "string", servicename)}')"); obj.AddName($"parameters('{AddParameter($"api_{apiname}_name", "string", apiname)}')"); obj.AddName($"'{name}'"); obj.comments = "Generated for resource " + restObject.Value <string>("id"); obj.name = $"[concat(parameters('{AddParameter($"service_{servicename}_name", "string", servicename)}'),'/',parameters('{AddParameter($"api_{apiname}_name", "string", apiname)}'), '/{name}')]"; obj.type = type; obj.properties = restObject.Value <JObject>("properties"); if (APIMInstanceAdded) { obj.dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service', parameters('service_{servicename}_name'))]"); //resource["dependsOn"] = new JArray(new string[] { $"[resourceId('Microsoft.ApiManagement/service', parameters('service_{servicename}_name'))]" }); } obj.dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service/apis', parameters('service_{servicename}_name'),parameters('{AddParameter($"api_{apiname}_name", "string", apiname)}'))]"); return(obj); }
public ResourceTemplate AddLogger(string servicename, string loggerNameParam) { string serviceNameParam = WrapParameterNameWithoutBrackets(GetServiceName(servicename)); string appInsightsRgNameParam = WrapParameterNameWithoutBrackets(AddParameter("app-insights-resourceGroup", "string", "")); string appInsightsNameParam = WrapParameterNameWithoutBrackets(AddParameter("app-insights-name", "string", "")); var loggerTemplate = new ResourceTemplate { type = "Microsoft.ApiManagement/service/loggers", properties = JObject.FromObject(new { loggerType = "applicationInsights", credentials = new { instrumentationKey = $"[reference(resourceId({appInsightsRgNameParam}, 'Microsoft.Insights/components', {appInsightsNameParam}), '2014-04-01').InstrumentationKey]" }, isBuffered = true }) }; loggerTemplate.AddName(serviceNameParam); loggerTemplate.AddName(loggerNameParam); if (resources.Any(r => r.Value <string>("name") == loggerTemplate.name)) { return(null); } resources.Add(JObject.FromObject(loggerTemplate)); return(loggerTemplate); }
public ResourceTemplate AddVersionSet(JObject restObject) { if (restObject == null) { return(null); } string name = restObject.Value <string>("name"); string type = restObject.Value <string>("type"); Func <JObject, bool> findVersionSet = vs => vs.Value <string>("type") == "Microsoft.ApiManagement/service/api-version-sets" && vs.Value <string>("name").Contains(name); bool versionSetExists = this.resources.Any(findVersionSet); if (versionSetExists) { return(null); } AzureResourceId apiid = new AzureResourceId(restObject.Value <string>("id")); string servicename = apiid.ValueAfter("service"); var obj = new ResourceTemplate(); obj.comments = "Generated for resource " + restObject.Value <string>("id"); obj.AddName($"parameters('{AddParameter($"{GetServiceName(servicename)}", "string", servicename)}')"); obj.AddName($"'{name}'"); obj.type = type; obj.properties = restObject.Value <JObject>("properties"); var resource = JObject.FromObject(obj); resource["properties"] = restObject["properties"]; var dependsOn = new JArray(); if (APIMInstanceAdded) { dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service', parameters('{GetServiceName(servicename)}'))]"); } resource["dependsOn"] = dependsOn; this.resources.Add(resource); return(obj); }
public ResourceTemplate AddProperty(JObject restObject) { if (restObject == null) { return(null); } string name = restObject.Value <string>("name"); string type = restObject.Value <string>("type"); bool secret = restObject["properties"].Value <bool>("secret"); AzureResourceId apiid = new AzureResourceId(restObject.Value <string>("id")); string servicename = apiid.ValueAfter("service"); var obj = new ResourceTemplate(); obj.comments = "Generated for resource " + restObject.Value <string>("id"); obj.AddName($"parameters('{AddParameter($"service_{servicename}_name", "string", servicename)}')"); obj.AddName($"'{name}'"); obj.type = type; obj.properties = restObject.Value <JObject>("properties"); var resource = JObject.FromObject(obj); var propValue = resource["properties"].Value <string>("value"); if (!(propValue == null || (propValue.StartsWith("[") && propValue.EndsWith("]")))) { resource["properties"]["value"] = WrapParameterName(this.AddParameter(restObject["properties"].Value <string>("displayName") + "_" + "value", secret ? "securestring" : "string", secret ? "secretvalue" : resource["properties"]["value"])); } //AddParameterFromObject((JObject)resource["properties"], "value", secret ? "securestring" : "string", restObject["properties"].Value<string>("displayName")); var dependsOn = new JArray(); if (APIMInstanceAdded) { dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service', parameters('service_{servicename}_name'))]"); } resource["dependsOn"] = dependsOn; this.resources.Add(resource); return(obj); }
public JObject CreateServiceResource(JObject restObject, string resourceType, bool addResource) { var obj = new ResourceTemplate { comments = "Generated for resource " + restObject.Value <string>("id"), type = resourceType }; var rid = new AzureResourceId(restObject.Value <string>("id")); var servicename = rid.ValueAfter("service"); obj.AddName($"parameters('{AddParameter($"{GetServiceName(servicename)}", "string", servicename)}')"); var name = restObject.Value <string>("name"); var resourceTypeShort = GetResourceTypeShort(resourceType); bool applicationInsightsLogger = IsApplicationInsightsLogger(restObject); if (applicationInsightsLogger && referenceApplicationInsightsInstrumentationKey) { name = $"parameters('{AddParameter($"{GetServiceName(servicename, false)}_applicationInsights", "string", name)}')"; } else { name = parametrizePropertiesOnly ? $"'{name}'" : $"parameters('{AddParameter($"{resourceTypeShort}_{name}_name", "string", name)}')"; } obj.AddName(name); var resource = JObject.FromObject(obj); resource["properties"] = restObject["properties"]; var dependsOn = new JArray(); if (APIMInstanceAdded) { dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service', parameters('{GetServiceName(servicename)}'))]"); } resource["dependsOn"] = dependsOn; if (addResource) { if (resources.All(x => x.Value <string>("name") != resource.Value <string>("name"))) { resources.Add(resource); } } return(resource); }
public ResourceTemplate AddVersionSet(JObject restObject) { if (restObject == null) { return(null); } string name = restObject.Value <string>("name"); string type = restObject.Value <string>("type"); AzureResourceId apiid = new AzureResourceId(restObject.Value <string>("id")); string servicename = apiid.ValueAfter("service"); var obj = new ResourceTemplate(); obj.comments = "Generated for resource " + restObject.Value <string>("id"); obj.AddName($"parameters('{AddParameter($"service_{servicename}_name", "string", servicename)}')"); obj.AddName($"'{name}'"); obj.type = type; obj.properties = restObject.Value <JObject>("properties"); var resource = JObject.FromObject(obj); resource["properties"] = restObject["properties"]; var dependsOn = new JArray(); if (APIMInstanceAdded) { dependsOn.Add($"[resourceId('Microsoft.ApiManagement/service', parameters('service_{servicename}_name'))]"); } resource["dependsOn"] = dependsOn; this.resources.Add(resource); return(obj); }