Пример #1
0
        internal Option <string> ParseURI(string uri, IEnvironmentWrapper env)
        {
            Option <string> parsedURI = Option.None <string>();

            Match matchHost = ImageUpstreamRegex.Match(uri);

            if (matchHost.Success &&
                (matchHost.Groups["post"]?.Length > 0))
            {
                string hostAddress = env.GetVariable(Core.Constants.GatewayHostnameVariableName).
                                     Expect(() => new InvalidOperationException($"Could not find environment variable: {Core.Constants.GatewayHostnameVariableName}"));

                parsedURI = Option.Some(matchHost.Groups["pre"].Value + hostAddress + matchHost.Groups["post"].Value);
            }

            return(parsedURI);
        }
Пример #2
0
        internal static string ValidateAndGetImage(string image, IEnvironmentWrapper env)
        {
            image = Preconditions.CheckNonWhiteSpace(image, nameof(image)).Trim();

            if (image[0] == '$')
            {
                Match matchHost = ImageUpstreamRegex.Match(image);
                if (matchHost.Success &&
                    (matchHost.Groups["path"]?.Length > 0))
                {
                    string hostAddress = env.GetVariable(Core.Constants.GatewayHostnameVariableName).
                                         Expect(() => new InvalidOperationException($"Could not find environment variable: {Core.Constants.GatewayHostnameVariableName}"));

                    image = hostAddress + matchHost.Groups["path"].Value;
                }
                else
                {
                    throw new ArgumentException($"Image {image} is not in the right format.If your intention is to use an environment variable, check the port is specified.");
                }
            }

            Match match = ImageRegex.Match(image);

            if (match.Success)
            {
                if (match.Groups["tag"]?.Length > 0)
                {
                    return(image);
                }
                else
                {
                    return(Invariant($"{image}:{Constants.DefaultTag}"));
                }
            }
            else
            {
                throw new ArgumentException($"Image {image} is not in the right format");
            }
        }