Exemple #1
0
        /// <summary>
        /// Resolve given input parameters into JSON parameter object for put
        /// </summary>
        /// <param name="policyParameter"></param>
        /// <param name="policyParameterObject"></param>
        /// <returns></returns>
        protected JObject GetParameters(string policyParameter, Hashtable policyParameterObject)
        {
            // Load parameters from local file or literal
            if (policyParameter != null)
            {
                string policyParameterFilePath = this.TryResolvePath(policyParameter);
                return(FileUtilities.DataStore.FileExists(policyParameterFilePath)
                    ? JObject.Parse(FileUtilities.DataStore.ReadFileAsText(policyParameterFilePath))
                    : JObject.Parse(policyParameter));
            }

            // Load from PS object
            if (policyParameterObject != null)
            {
                return(policyParameterObject.ToJObjectWithValue());
            }

            // Load dynamic parameters
            var parameters = PowerShellUtilities.GetUsedDynamicParameters(AsJobDynamicParameters, MyInvocation);

            if (parameters.Count() > 0)
            {
                return(MyInvocation.BoundParameters.ToJObjectWithValue(parameters.Select(p => p.Name)));
            }

            return(null);
        }
        protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
        {
            // NOTE(jogao): create a new Hashtable so that user can re-use the templateParameterObject.
            var prameterObject = new Hashtable();

            if (templateParameterObject != null)
            {
                foreach (var parameterKey in templateParameterObject.Keys)
                {
                    // Let default behavior of a value parameter if not a KeyVault reference Hashtable
                    var hashtableParameter = templateParameterObject[parameterKey] as Hashtable;
                    if (hashtableParameter != null && hashtableParameter.ContainsKey("reference"))
                    {
                        prameterObject[parameterKey] = templateParameterObject[parameterKey];
                    }
                    else
                    {
                        prameterObject[parameterKey] = new Hashtable {
                            { "value", templateParameterObject[parameterKey] }
                        };
                    }
                }
            }

            // Load parameters from the file
            string templateParameterFilePath = this.ResolvePath(TemplateParameterFile);

            if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
            {
                var parametersFromFile = TemplateUtility.ParseTemplateParameterFileContents(templateParameterFilePath);
                parametersFromFile.ForEach(dp =>
                {
                    var parameter = new Hashtable();
                    if (dp.Value.Value != null)
                    {
                        parameter.Add("value", dp.Value.Value);
                    }
                    if (dp.Value.Reference != null)
                    {
                        parameter.Add("reference", dp.Value.Reference);
                    }

                    prameterObject[dp.Key] = parameter;
                });
            }

            // Load dynamic parameters
            IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(this.AsJobDynamicParameters, MyInvocation);

            if (parameters.Any())
            {
                parameters.ForEach(dp => prameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = new Hashtable {
                    { "value", dp.Value }
                });
            }

            return(prameterObject);
        }
        protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
        {
            // NOTE(jogao): create a new Hashtable so that user can re-use the templateParameterObject.
            var prameterObject = new Hashtable();

            if (templateParameterObject != null)
            {
                foreach (var parameterKey in templateParameterObject.Keys)
                {
                    prameterObject[parameterKey] = new Hashtable {
                        { "value", templateParameterObject[parameterKey] }
                    };
                }
            }

            // Load parameters from the file
            string templateParameterFilePath = this.TryResolvePath(TemplateParameterFile);

            if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
            {
                var parametersFromFile = GalleryTemplatesClient.ParseTemplateParameterFileContents(templateParameterFilePath);
                parametersFromFile.ForEach(dp => prameterObject[dp.Key] = new Hashtable {
                    { "value", dp.Value.Value }, { "reference", dp.Value.Reference }
                });
            }

            // Load dynamic parameters
            IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(dynamicParameters, MyInvocation);

            if (parameters.Any())
            {
                parameters.ForEach(dp => prameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = new Hashtable {
                    { "value", dp.Value }
                });
            }

            return(prameterObject);
        }
Exemple #4
0
        protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
        {
            templateParameterObject = templateParameterObject ?? new Hashtable();

            // Load parameters from the file
            string templateParameterFilePath = this.TryResolvePath(TemplateParameterFile);

            if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
            {
                var parametersFromFile = GalleryTemplatesClient.ParseTemplateParameterFileContents(templateParameterFilePath);
                parametersFromFile.ForEach(dp => templateParameterObject[dp.Key] = dp.Value.Value);
            }

            // Load dynamic parameters
            IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(dynamicParameters, MyInvocation);

            if (parameters.Any())
            {
                parameters.ForEach(dp => templateParameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = dp.Value);
            }

            return(templateParameterObject);
        }
        protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
        {
            templateParameterObject = templateParameterObject ?? new Hashtable();

            // Load parameters from the file
            string templateParameterFilePath = this.TryResolvePath(TemplateParameterFile);

            if (templateParameterFilePath != null && File.Exists(templateParameterFilePath))
            {
                var parametersFromFile = JsonConvert.DeserializeObject <Dictionary <string, TemplateFileParameter> >(File.ReadAllText(templateParameterFilePath));
                parametersFromFile.ForEach(dp => templateParameterObject[dp.Key] = dp.Value.Value);
            }

            // Load dynamic parameters
            IEnumerable <RuntimeDefinedParameter> parameters = PowerShellUtilities.GetUsedDynamicParameters(dynamicParameters, MyInvocation);

            if (parameters.Any())
            {
                parameters.ForEach(dp => templateParameterObject[((ParameterAttribute)dp.Attributes[0]).HelpMessage] = dp.Value);
            }

            return(templateParameterObject);
        }