Beispiel #1
0
        private static void HandleServiceBindingNameMapping(YamlMappingNode yamlMappingNode, ConfigServiceBinding binding)
        {
            foreach (var child in yamlMappingNode.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    binding.Name = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "connectionString":
                    binding.ConnectionString = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "port":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var port))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    binding.Port = port;
                    break;

                case "containerPort":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var containerPort))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    binding.ContainerPort = containerPort;
                    break;

                case "host":
                    binding.Host = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "protocol":
                    binding.Protocol = YamlParser.GetScalarValue(key, child.Value);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #2
0
        private static void HandleIngressMapping(YamlMappingNode yamlMappingNode, ConfigIngress configIngress)
        {
            foreach (var child in yamlMappingNode !.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    configIngress.Name = YamlParser.GetScalarValue(key, child.Value).ToLowerInvariant();
                    break;

                case "replicas":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var replicas))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (replicas < 0)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBePositive(key));
                    }

                    configIngress.Replicas = replicas;
                    break;

                case "rules":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }
                    HandleIngressRules((child.Value as YamlSequenceNode) !, configIngress.Rules);
                    break;

                case "bindings":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }
                    HandleIngressBindings((child.Value as YamlSequenceNode) !, configIngress.Bindings);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #3
0
        public static void HandleExtensionsMapping(YamlSequenceNode yamlSequenceNode, List <Dictionary <string, object> > extensions)
        {
            foreach (var child in yamlSequenceNode.Children)
            {
                switch (child.NodeType)
                {
                case YamlNodeType.Mapping:
                    var extensionDictionary = YamlParser.GetDictionary(child);
                    extensions.Add(extensionDictionary);
                    break;

                default:
                    throw new TyeYamlException(child.Start,
                                               CoreStrings.FormatUnexpectedType(YamlNodeType.Mapping.ToString(), child.NodeType.ToString()));
                }
            }
        }
Beispiel #4
0
        private static void HandleServiceHttpProber(YamlMappingNode yamlMappingNode, ConfigHttpProber prober)
        {
            foreach (var child in yamlMappingNode.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "path":
                    prober.Path = YamlParser.GetScalarValue("path", child.Value);
                    break;

                case "port":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var port))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    prober.Port = port;
                    break;

                case "protocol":
                    prober.Path = YamlParser.GetScalarValue("protocol", child.Value);
                    break;

                case "headers":
                    prober.Headers = new List <KeyValuePair <string, object> >();
                    var headersNode = child.Value as YamlSequenceNode;
                    if (headersNode is null)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence("headers"));
                    }

                    foreach (var header in headersNode.Children)
                    {
                        HandleServiceProbeHttpHeader((YamlMappingNode)header, prober.Headers);
                    }

                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #5
0
        private static void HandleServiceConfigurationCompact(YamlScalarNode yamlScalarNode, ConfigConfigurationSource config)
        {
            var nodeValue         = YamlParser.GetScalarValue(yamlScalarNode);
            var keyValueSeparator = nodeValue.IndexOf('=');

            if (keyValueSeparator != -1)
            {
                var key   = nodeValue.Substring(0, keyValueSeparator).Trim();
                var value = nodeValue.Substring(keyValueSeparator + 1)?.Trim();

                config.Name  = key;
                config.Value = value?.Trim(new[] { ' ', '"' }) ?? string.Empty;
            }
            else
            {
                config.Name = nodeValue.Trim();
            }
        }
        public static void HandleConfigApplication(YamlMappingNode yamlMappingNode, ConfigApplication app)
        {
            foreach (var child in yamlMappingNode.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    app.Name = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "namespace":
                    app.Namespace = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "network":
                    app.Network = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "registry":
                    app.Registry = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "ingress":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigIngressParser.HandleIngress((child.Value as YamlSequenceNode) !, app.Ingress);
                    break;

                case "services":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigServiceParser.HandleServiceMapping((child.Value as YamlSequenceNode) !, app.Services, app);
                    break;

                case "extensions":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigExtensionsParser.HandleExtensionsMapping((child.Value as YamlSequenceNode) !, app.Extensions);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #7
0
        private static void HandleServiceBuildPropertyNameMapping(YamlMappingNode yamlMappingNode, BuildProperty buildProperty)
        {
            foreach (var child in yamlMappingNode !.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    buildProperty.Name = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "value":
                    buildProperty.Value = YamlParser.GetScalarValue(key, child.Value);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
        public static void HandleExtensionsMapping(YamlSequenceNode yamlSequenceNode, List <Dictionary <string, object> > extensions)
        {
            foreach (var child in yamlSequenceNode.Children)
            {
                switch (child.NodeType)
                {
                case YamlNodeType.Mapping:
                    var extensionDictionary = new Dictionary <string, object>();
                    foreach (var mapping in (YamlMappingNode)child)
                    {
                        var key = YamlParser.GetScalarValue(mapping.Key);
                        extensionDictionary[key] = YamlParser.GetScalarValue(key, mapping.Value) !;
                    }

                    extensions.Add(extensionDictionary);
                    break;

                default:
                    throw new TyeYamlException(child.Start,
                                               CoreStrings.FormatUnexpectedType(YamlNodeType.Mapping.ToString(), child.NodeType.ToString()));
                }
            }
        }
Beispiel #9
0
        private static void HandleServiceNameMapping(YamlMappingNode yamlMappingNode, ConfigService service)
        {
            foreach (var child in yamlMappingNode !.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    service.Name = YamlParser.GetScalarValue(key, child.Value).ToLowerInvariant();
                    break;

                case "external":
                    if (!bool.TryParse(YamlParser.GetScalarValue(key, child.Value), out var external))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeABoolean(key));
                    }

                    service.External = external;
                    break;

                case "image":
                    service.Image = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "dockerFile":
                    service.DockerFile = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "dockerFileContext":
                    service.DockerFileContext = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "project":
                    service.Project = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "buildProperties":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }

                    HandleBuildProperties((child.Value as YamlSequenceNode) !, service.BuildProperties);
                    break;

                case "include":
                    service.Include = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "repository":
                    service.Repository = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "build":
                    if (!bool.TryParse(YamlParser.GetScalarValue(key, child.Value), out var build))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeABoolean(key));
                    }

                    service.Build = build;
                    break;

                case "executable":
                    service.Executable = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "workingDirectory":
                    service.WorkingDirectory = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "args":
                    service.Args = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "replicas":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var replicas))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (replicas < 0)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBePositive(key));
                    }

                    service.Replicas = replicas;
                    break;

                case "bindings":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }

                    HandleServiceBindings((child.Value as YamlSequenceNode) !, service.Bindings);
                    break;

                case "volumes":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }

                    HandleServiceVolumes((child.Value as YamlSequenceNode) !, service.Volumes);
                    break;

                case "env":
                case "configuration":
                    if (child.Value.NodeType != YamlNodeType.Sequence)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatExpectedYamlSequence(key));
                    }

                    HandleServiceConfiguration((child.Value as YamlSequenceNode) !, service.Configuration);
                    break;

                case "liveness":
                    service.Liveness = new ConfigProbe();
                    HandleServiceProbe((YamlMappingNode)child.Value, service.Liveness !);
                    break;

                case "readiness":
                    service.Readiness = new ConfigProbe();
                    HandleServiceProbe((YamlMappingNode)child.Value, service.Readiness !);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #10
0
        private static void HandleServiceProbe(YamlMappingNode yamlMappingNode, ConfigProbe probe)
        {
            foreach (var child in yamlMappingNode.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "http":
                    probe.Http = new ConfigHttpProber();
                    HandleServiceHttpProber((YamlMappingNode)child.Value, probe.Http !);
                    break;

                case "initialDelay":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var initialDelay))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (initialDelay < 0)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBePositive(key));
                    }

                    probe.InitialDelay = initialDelay;
                    break;

                case "period":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var period))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (period < 1)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeGreaterThanZero(key));
                    }

                    probe.Period = period;
                    break;

                case "timeout":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var timeout))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (timeout < 1)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeGreaterThanZero(key));
                    }

                    probe.Timeout = timeout;
                    break;

                case "successThreshold":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var successThreshold))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (successThreshold < 1)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeGreaterThanZero(key));
                    }

                    probe.SuccessThreshold = successThreshold;
                    break;

                case "failureThreshold":
                    if (!int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var failureThreshold))
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }

                    if (failureThreshold < 1)
                    {
                        throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeGreaterThanZero(key));
                    }

                    probe.FailureThreshold = failureThreshold;
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }
Beispiel #11
0
        private static void HandleServiceEnvFiles(YamlSequenceNode yamlSequenceNode, List <ConfigConfigurationSource> configuration, ConfigApplication application)
        {
            foreach (var child in yamlSequenceNode.Children)
            {
                switch (child)
                {
                case YamlScalarNode childScalarNode:
                    var envFile = new FileInfo(Path.Combine(application.Source?.DirectoryName ?? Directory.GetCurrentDirectory(), YamlParser.GetScalarValue(childScalarNode)));
                    if (!envFile.Exists)
                    {
                        throw new TyeYamlException(child.Start, CoreStrings.FormatPathNotFound(envFile.FullName));
                    }
                    HandleServiceEnvFile(childScalarNode, File.ReadAllLines(envFile.FullName), configuration);
                    break;

                default:
                    throw new TyeYamlException(child.Start, CoreStrings.FormatUnexpectedType(YamlNodeType.Scalar.ToString(), child.NodeType.ToString()));
                }
            }
        }
Beispiel #12
0
        public static void HandleConfigApplication(YamlMappingNode yamlMappingNode, ConfigApplication app)
        {
            foreach (var child in yamlMappingNode.Children)
            {
                var key = YamlParser.GetScalarValue(child.Key);

                switch (key)
                {
                case "name":
                    app.Name = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "solution":
                    app.BuildSolution = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "namespace":
                    app.Namespace = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "network":
                    app.Network = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "registry":
                    app.Registry = YamlParser.GetScalarValue(key, child.Value);
                    break;

                case "containerEngine":
                    string engine = YamlParser.GetScalarValue(key, child.Value);
                    if (engine.Equals("docker", StringComparison.InvariantCultureIgnoreCase))
                    {
                        app.ContainerEngineType = ContainerEngineType.Docker;
                    }
                    else if (engine.Equals("podman", StringComparison.InvariantCultureIgnoreCase))
                    {
                        app.ContainerEngineType = ContainerEngineType.Podman;
                    }
                    else
                    {
                        throw new TyeYamlException($"Unknown container engine: \"{engine}\"");
                    }
                    break;

                case "dashboardPort":
                    if (int.TryParse(YamlParser.GetScalarValue(key, child.Value), out var dashboardPort))
                    {
                        app.DashboardPort = dashboardPort;
                    }
                    else
                    {
                        throw new TyeYamlException(child.Key.Start, CoreStrings.FormatMustBeAnInteger(key));
                    }
                    break;

                case "ingress":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigIngressParser.HandleIngress((child.Value as YamlSequenceNode) !, app.Ingress);
                    break;

                case "services":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigServiceParser.HandleServiceMapping((child.Value as YamlSequenceNode) !, app.Services, app);
                    break;

                case "extensions":
                    YamlParser.ThrowIfNotYamlSequence(key, child.Value);
                    ConfigExtensionsParser.HandleExtensionsMapping((child.Value as YamlSequenceNode) !, app.Extensions);
                    break;

                default:
                    throw new TyeYamlException(child.Key.Start, CoreStrings.FormatUnrecognizedKey(key));
                }
            }
        }