Beispiel #1
0
        public IEnumerable <IUpdatableResource> UpdatableResources()
        {
            var resources = this.Root["Resources"];

            if (resources == null)
            {
                throw new LambdaToolsException("CloudFormation template does not define any AWS resources", LambdaToolsException.LambdaErrorCode.ServerlessTemplateMissingResourceSection);
            }

            foreach (var field in resources.PropertyNames)
            {
                var resource = resources[field];
                if (resource == null)
                {
                    continue;
                }

                var properties = resource["Properties"];
                if (properties == null)
                {
                    continue;
                }

                var type = resource["Type"]?.ToString();
                UpdatableResourceDefinition updatableResourceDefinition;
                if (!UpdatableResourceDefinition.ValidUpdatableResourceDefinitions.TryGetValue(type,
                                                                                               out updatableResourceDefinition))
                {
                    continue;
                }

                var updatableResource = new UpdatableResource(field, updatableResourceDefinition, new JsonUpdatableResourceDataSource(this.Root, properties));
                yield return(updatableResource);
            }
        }
        public IEnumerable <IUpdatableResource> UpdatableResources()
        {
            var root = (YamlMappingNode)this.Yaml.Documents[0].RootNode;

            if (root == null)
            {
                throw new LambdaToolsException("CloudFormation template does not define any AWS resources", LambdaToolsException.LambdaErrorCode.ServerlessTemplateMissingResourceSection);
            }

            var resourcesKey = new YamlScalarNode("Resources");

            if (!root.Children.ContainsKey(resourcesKey))
            {
                throw new LambdaToolsException("CloudFormation template does not define any AWS resources", LambdaToolsException.LambdaErrorCode.ServerlessTemplateMissingResourceSection);
            }

            var resources = (YamlMappingNode)root.Children[resourcesKey];

            foreach (var resource in resources.Children)
            {
                var resourceBody = (YamlMappingNode)resource.Value;
                var type         = (YamlScalarNode)resourceBody.Children[new YamlScalarNode("Type")];


                if (!resourceBody.Children.ContainsKey("Properties"))
                {
                    continue;
                }

                var properties = (YamlMappingNode)resourceBody.Children[new YamlScalarNode("Properties")];

                if (properties == null)
                {
                    continue;
                }
                if (type == null)
                {
                    continue;
                }


                UpdatableResourceDefinition updatableResourceDefinition;
                if (!UpdatableResourceDefinition.ValidUpdatableResourceDefinitions.TryGetValue(type.Value,
                                                                                               out updatableResourceDefinition))
                {
                    continue;
                }

                var updatableResource = new UpdatableResource(resource.Key.ToString(), updatableResourceDefinition, new YamlUpdatableResourceDataSource(root, properties));

                yield return(updatableResource);
            }
        }
Beispiel #3
0
 public UpdatableResourceField(UpdatableResource resource, UpdatableResourceDefinition.FieldDefinition field)
 {
     this._resource = resource;
     this.Field     = field;
 }
Beispiel #4
0
 public UpdatableResourceField(UpdatableResource resource, UpdatableResourceDefinition.FieldDefinition field, IUpdatableResourceDataSource dataSource)
 {
     this._resource  = resource;
     this.Field      = field;
     this.DataSource = dataSource;
 }