Ejemplo n.º 1
0
 private static void UpdateTemplateMetadata(JObject properties, IArmPropertyValueResolver armPropertyValueResolver)
 {
     RemoveTemplateId(properties);
     properties.ReplacePropertyValueWith(ArmTemplateDynamicProperty.DashboardName, armPropertyValueResolver);
     AddArmApiVersion(properties);
     properties.GetObject("tags").ReplacePropertyValueWith(ArmTemplateDynamicProperty.DashboardDisplayName, armPropertyValueResolver);
 }
Ejemplo n.º 2
0
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            JObject variables = CreateVariablesObject(armTemplate);

            armTemplate.Json.AddFirst(new JProperty(ArmTemplatePropertyNameConstants.Variables, variables));

            return(armTemplate);
        }
Ejemplo n.º 3
0
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            armTemplate.Json.AddFirst(new JProperty(ArmTemplatePropertyNameConstants.Variables, new JObject()));
            armTemplate.Json.AddFirst(BuildTemplateParameters(armTemplate));
            armTemplate.Json.AddFirst(new JProperty(ArmTemplatePropertyNameConstants.ContentVersion, ArmPropertyValueConstants.ContentVersion));
            armTemplate.Json.AddFirst(new JProperty("$schema", ArmPropertyValueConstants.TemplateSchema));

            return(armTemplate);
        }
Ejemplo n.º 4
0
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            var properties = armTemplate.Json.SelectToken("properties");
            var parts      = properties.SelectToken("lenses.0.parts");

            UpdateParts(parts, armPropertyValueResolver);
            UpdateTemplateMetadata(armTemplate.Json, armPropertyValueResolver);

            return(armTemplate);
        }
Ejemplo n.º 5
0
        private static void UpdateComponentIds(IJEnumerable <JToken> inputs, IArmPropertyValueResolver armPropertyValueResolver)
        {
            var componentIdInput = inputs.GetObjectByName("ComponentId")?.GetObject("value");

            if (componentIdInput != null)
            {
                componentIdInput.ReplacePropertyValueWith(ArmTemplateDynamicProperty.SubscriptionId, armPropertyValueResolver);
                componentIdInput.ReplacePropertyValueWith(ArmTemplateDynamicProperty.ResourceGroupName, armPropertyValueResolver);
                componentIdInput.ReplacePropertyValueWith(ArmTemplateDynamicProperty.AppInsightsName, armPropertyValueResolver);
            }
        }
            public ResourceId(string resourceIdString, IArmPropertyValueResolver armPropertyValueResolver)
            {
                this.armPropertyValueResolver = armPropertyValueResolver;
                Match match = ResourceIdPattern.Match(resourceIdString);

                this.ResourceIdString = resourceIdString;
                this.SubscriptionId   = match.Groups["subscription"].Value;
                this.ResourceGroup    = match.Groups["resourceGroup"].Value;
                this.Provider         = match.Groups["provider"].Value;
                this.ProviderType     = match.Groups["providerType"].Value;
                this.ResourceName     = match.Groups["resourceName"].Value;
            }
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            var dependencies = new JArray();

            dependencies.Add(WrapVariableSelector(armPropertyValueResolver.GetValue(ArmTemplateDynamicProperty.AppInsightsName)));
            foreach (var additionalResource in armTemplate.AdditionalResourceNames)
            {
                dependencies.Add(WrapVariableSelector(armPropertyValueResolver.GetValue(additionalResource)));
            }

            armTemplate.Json.Add(new JProperty("dependsOn", dependencies));
            return(armTemplate);
        }
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            var resourceIdProperties    = armTemplate.Json.GetAllChildProperties("resourceId");
            var additionalResourceNames = new HashSet <string>();

            foreach (var resourceIdProperty in resourceIdProperties)
            {
                var resourceId = new ResourceId(resourceIdProperty.Value.Value <string>(), armPropertyValueResolver);
                resourceIdProperty.Value = resourceId.ToParameterisedString();
                additionalResourceNames.Add(resourceId.ResourceParameterName);
            }
            armTemplate.AdditionalResourceNames.AddRange(additionalResourceNames);
            return(armTemplate);
        }
        protected override ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
        {
            var resources       = new JArray();
            var properties      = armTemplate.Json.Properties();
            var resourcesObject = new JObject();

            foreach (var property in properties)
            {
                resourcesObject.Add(property);
            }

            resources.Add(resourcesObject);
            armTemplate.ReplaceJson(new JObject(new JProperty("resources", resources)));
            return(armTemplate);
        }
Ejemplo n.º 10
0
        internal static ArmTemplate TransformTemplate(InputDashboardArmTemplate inputTemplate, TransformationDetails transformationDetails)
        {
            try
            {
                var inputJson   = JObject.Parse(inputTemplate.TemplateJson);
                var armTemplate = new ArmTemplate(inputJson);
                ArmTemplateTransformer    rootTransformer          = CreateTransformer(transformationDetails);
                IArmPropertyValueResolver armPropertyValueResolver = CreatePropertyValueResolver(transformationDetails);
                rootTransformer.Transform(armTemplate, armPropertyValueResolver);

                return(armTemplate);
            }
            catch (Exception e)
            {
                throw new InvalidInputTemplateException(e);
            }
        }
Ejemplo n.º 11
0
        private static void UpdateParts(JToken parts, IArmPropertyValueResolver armPropertyValueResolver)
        {
            int partNumber = 0;

            while (true)
            {
                var part = parts.SelectToken(partNumber.ToString());
                if (part != null)
                {
                    var inputs = part.SelectToken("metadata.inputs").AsJEnumerable();

                    UpdateComponentIds(inputs, armPropertyValueResolver);
                    UpdatePartSubTitle(inputs, armPropertyValueResolver);
                    RemoveDashboardId(inputs);
                }
                else
                {
                    return;
                }

                partNumber++;
            }
        }
Ejemplo n.º 12
0
 private static void UpdatePartSubTitle(IJEnumerable <JToken> inputs, IArmPropertyValueResolver armPropertyValueResolver)
 {
     inputs.GetObjectByName("PartSubTitle")?.ReplacePropertyValueWith("value", ArmTemplateDynamicProperty.AppInsightsName, armPropertyValueResolver);
 }
 public static void ReplacePropertyValueWith(this JObject jObject, string propertyName, ArmTemplateDynamicProperty armPropertyParameter, IArmPropertyValueResolver armPropertyValueResolver)
 {
     jObject.UpdatePropertyValue(propertyName, $"[{armPropertyValueResolver.GetValue(armPropertyParameter)}]");
 }
 public static void ReplacePropertyValueWith(this JObject jObject, ArmTemplateDynamicProperty armPropertyParameter, IArmPropertyValueResolver armPropertyValueResolver)
 {
     jObject.ReplacePropertyValueWith(armPropertyParameter.ArmTemplatePropertyName, armPropertyParameter, armPropertyValueResolver);
 }
 protected abstract ArmTemplate TransformInner(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver);
 public ArmTemplate Transform(ArmTemplate armTemplate, IArmPropertyValueResolver armPropertyValueResolver)
 {
     armTemplate = this.TransformInner(armTemplate, armPropertyValueResolver);
     return(this.nextTransformer != null?this.nextTransformer.Transform(armTemplate, armPropertyValueResolver) : armTemplate);
 }