コード例 #1
0
        private static async Task <IImmutableDictionary <string, string> > GetFunctionEnvironmentVariables(
            TemplateData template,
            TemplateData.ResourceData functionNode,
            Components.Components.ComponentTree components)
        {
            if (!functionNode.Properties.ContainsKey("Environment") ||
                !((IDictionary <object, object>)functionNode.Properties["Environment"]).ContainsKey("Variables"))
            {
                return(new Dictionary <string, string>().ToImmutableDictionary());
            }

            var parsers = components
                          .FindAll <IParseCloudformationValues>(Components.Components.Direction.Out)
                          .Select(x => x.component)
                          .ToImmutableList();

            var variables =
                (IDictionary <object, object>)((IDictionary <object, object>)functionNode.Properties["Environment"])[
                    "Variables"];

            var resultVariables = new Dictionary <string, string>();

            foreach (var variable in variables)
            {
                var variableName = variable.Key.ToString() ?? "";

                var parsedValue = await parsers.Parse(variable.Value, template);

                resultVariables[variableName] = (parsedValue ?? "").ToString();
            }

            return(resultVariables.ToImmutableDictionary());
        }
コード例 #2
0
        public static TemplateData Merge(
            this IEnumerable <TemplateData> templates)
        {
            var newTemplate = new TemplateData();

            foreach (var template in templates)
            {
                newTemplate.Merge(template);
            }

            return(newTemplate);
        }
コード例 #3
0
        public static async Task <IImmutableDictionary <string, IImmutableDictionary <string, string> > > FindEnvironmentVariables(
            this TemplateData template,
            Components.Components.ComponentTree components)
        {
            var result = new Dictionary <string, IImmutableDictionary <string, string> >();

            foreach (var resource in template.Resources)
            {
                if (resource.Value.Type == "AWS::Serverless::Function")
                {
                    result[resource.Key] = await GetFunctionEnvironmentVariables(
                        template,
                        resource.Value,
                        components);
                }
            }

            return(result.ToImmutableDictionary());
        }
コード例 #4
0
        public void Merge(TemplateData other)
        {
            foreach (var global in other.Globals)
            {
                if (!Globals.ContainsKey(global.Key))
                {
                    Globals[global.Key] = global.Value;
                }
            }

            foreach (var output in other.Outputs)
            {
                if (!Outputs.ContainsKey(output.Key))
                {
                    Outputs[output.Key] = output.Value;
                }
            }

            foreach (var parameter in other.Parameters)
            {
                if (!Parameters.ContainsKey(parameter.Key))
                {
                    Parameters[parameter.Key] = parameter.Value;
                }
            }

            foreach (var resource in other.Resources)
            {
                if (Resources.ContainsKey(resource.Key))
                {
                    Resources[resource.Key] = Resources[resource.Key].Merge(resource.Value);
                }
                else
                {
                    Resources[resource.Key] = resource.Value;
                }
            }
        }
コード例 #5
0
        public static TemplateData SetContentUris(this TemplateData template, string contentUri)
        {
            if (template.Resources == null)
            {
                return(template);
            }

            foreach (var resource in template.Resources.Where(x => x.Value?.Type == "AWS::Serverless::LayerVersion"))
            {
                if (resource.Value.Properties == null)
                {
                    continue;
                }

                if (!resource.Value.Properties.ContainsKey("ContentUri") ||
                    resource.Value.Properties["ContentUri"] == null)
                {
                    resource.Value.Properties["ContentUri"] = contentUri;
                }
            }

            return(template);
        }
コード例 #6
0
 GetRequiredConfigurations(this TemplateData templateData)
 {
     return(Task.FromResult(templateData.Parameters.Select(parameter => ($"{SettingNamespaces.CloudformationParameters}{parameter.Key}",
                                                                         $"Please enter local value for cloudformation parameter: \"{parameter.Key}\"",
                                                                         INeedConfiguration.ConfigurationType.Project))));
 }