Ejemplo n.º 1
0
        //         [InlineData(
        //             @"spec:
        //   template:
        //     spec:
        //       containers:
        //       - - image: 'host:port/owner/name:1234567890abcdef'
        //       - - image: 'host:port/owner/name:1234567890abcdef'",
        //             new string[] { "spec.template.spec.containers[*].[*].image" },
        //             "123abc",
        //             @"spec:
        //   template:
        //     spec:
        //       containers:
        //       - - image: 'host:port/owner/name:123abc'
        //       - - image: 'host:port/owner/name:123abc'
        // ...
        // ")] // Nested array is not supported
        public void UpdateByNestedKeyTest(string yaml, string[] nestedKeys, string newTag, string expected)
        {
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            var sr = new StringReader(yaml);
            var ys = new YamlStream();

            ys.Load(sr);

            foreach (var doc in ys.Documents)
            {
                foreach (var nestedKey in nestedKeys)
                {
                    var oldVal = YamlUtil.UpdateByNestedKey(
                        doc.RootNode,
                        nestedKey.Split("."),
                        oldVal =>
                        TagUpdater.TagReplacer(oldVal, newTag)
                        );
                }
            }
            ys.Save(sw, false);
            Assert.Equal(expected, sw.ToString());
        }
Ejemplo n.º 2
0
        public async Task Test() {
            var n = new YamlUtil().NewFromYaml<RepoVersion>(@"
---
:archive_format: .gz
:format_version: 1
:guid: 08d56888-a75d-4e4c-842f-8db5f9d163f4
:version: 1
:pack_size: 28456
:wd_size: 140157
:pack:
  addons/ace_compat_rhs_afrf3.pbo.gz: f9cfb837b5d64f7fcf364911f83b135a
  addons/ace_compat_rhs_usf3.pbo.gz: 09b04627357283cf3fb39c32be6ebcfb
  addons/userconfig/ace/serverconfig.hpp.gz: 0babb2a8d97247947d57b28f4b6e723e
  addons/ace_compat_rhs_afrf3.pbo.ace_3.8.1.11-e1aa5b42.bisign.gz: 63595430b41898d2d338e4fff11332da
  addons/ace_compat_rhs_afrf3.pbo.six_ace3.bisign.gz: 287a8413dadfd4c2e7dc2bc1a1c07bb4
  addons/ace_compat_rhs_afrf3.pbo.six_ace_optionals.bisign.gz: a2d6ccb71acf718acf8fc8efff1a88fc
  addons/ace_compat_rhs_usf3.pbo.ace_3.8.1.11-e1aa5b42.bisign.gz: 1f36f49ff0d5ee9530837c1b14ed936a
  addons/ace_compat_rhs_usf3.pbo.six_ace3.bisign.gz: 2ac922c177f9496d8d300630f75b8572
  addons/ace_compat_rhs_usf3.pbo.six_ace_optionals.bisign.gz: 05ddf47bf34cafd68d2011f1a360a345
  keys/six_ace_optionals.bikey.gz: 03774883cfb9532af70ec2cd8a70fe70
:wd:
  addons/ace_compat_rhs_usf3.pbo: cb8bc8b508581843dc88412bf545a3ac
  addons/ace_compat_rhs_afrf3.pbo: 972b40ddc0a022235fa64d14dd83a621
  addons/userconfig/ace/serverconfig.hpp: 26b6ecd355676c7413f1fa376a57491e
  keys/six_ace_optionals.bikey: c191ba047f8aa5755c83dfb08d62edd9
  addons/ace_compat_rhs_usf3.pbo.six_ace_optionals.bisign: 17cda3e00aa5f05385850a00bbac8c33
  addons/ace_compat_rhs_usf3.pbo.six_ace3.bisign: bae42633fac2bc1f46549b4e9c55f000
  addons/ace_compat_rhs_usf3.pbo.ace_3.8.1.11-e1aa5b42.bisign: a3d55b42f84e22b749787fb036dbcc3d
  addons/ace_compat_rhs_afrf3.pbo.six_ace_optionals.bisign: cf912f0ab2bc94f6277a98b64f2b72dc
  addons/ace_compat_rhs_afrf3.pbo.six_ace3.bisign: 811bf388a7544124387d063624a7bb88
  addons/ace_compat_rhs_afrf3.pbo.ace_3.8.1.11-e1aa5b42.bisign: 81508e234450dffd3c2c88acfb5e0bd6
");
            Console.WriteLine(n.ToJson());
        }
Ejemplo n.º 3
0
        public void Deserialize_2Resource_1App_Tree()
        {
            var name = "name";

            var yaml = $@"
name: {name}
resources:
    ms-sql-server:        
        type: database
        sub_type: mssqlserver    
        connection_string: localhost:1433
    redis:        
        type: database
        sub_type: redis
        connection_string: localhost:1433
applications:
  ping:
    type_name: Lighthouse.Apps.PingService
    configuration:";

            var config = YamlUtil.ParseYaml <LighthouseRunConfig>(yaml);

            config.Name.Should().Be(name);
            config.Resources.Count.Should().Be(2);
            config.Applications.Count.Should().Be(1);
        }
Ejemplo n.º 4
0
        public YamlConfigurationProvider(IConfiguration configuration)
        {
            var options      = configuration.GetSection(Options.KEY).Get <Options>();
            var deserializer = YamlUtil.BuildDeserializer();

            using var reader = new StreamReader(options.File);
            config           = deserializer.Deserialize <YamlConfig>(reader) ?? new YamlConfig();
        }
Ejemplo n.º 5
0
        public async Task Test2() {
            var n = new YamlUtil().NewFromYaml<RepoConfig>(@"
--- 
:pack_path: C:\temp\testpath
:exclude: []
:include: []
:hosts:
- https://testhost.com
");
            Console.WriteLine(n.ToJson());
        }
Ejemplo n.º 6
0
        public async Task Test2()
        {
            var n = new YamlUtil().NewFromYaml <RepoConfig>(@"
--- 
:pack_path: C:\temp\testpath
:exclude: []
:include: []
:hosts:
- https://testhost.com
");

            Console.WriteLine(n.ToJson());
        }
Ejemplo n.º 7
0
        public void TestYamlFrontMatter()
        {
            TextPosition position;
            var          input  = @"---
name: yes
intvalue: 12351235
floatvalue: 12.3
boooo: 
  - a
  - b
  - c
---
Yo
";
            var          result = YamlUtil.FromYamlFrontMatter(input, out position);

            Assert.AreEqual(new TextPosition(87, 8, 3), position);

            Assert.IsInstanceOf <ScriptObject>(result);
            var scriptObject = (ScriptObject)result;

            Assert.AreEqual(4, scriptObject.Keys.Count);
            var keys = scriptObject.Keys.ToList();

            keys.Sort();
            Assert.AreEqual(new List <string>()
            {
                "boooo",
                "floatvalue",
                "intvalue",
                "name"
            }, keys);

            Assert.AreEqual(true, scriptObject["name"]);
            Assert.AreEqual(12351235, scriptObject["intvalue"]);
            Assert.AreEqual(12.3, scriptObject["floatvalue"]);
            Assert.AreEqual(new ScriptArray()
            {
                "a",
                "b",
                "c"
            }, scriptObject["boooo"]);

            var remaining = input.Substring(position.Offset).Trim();

            Assert.AreEqual("Yo", remaining);
        }
Ejemplo n.º 8
0
        public override ContentResult TryProcessContent(ContentObject page, ContentProcessingStage stage)
        {
            Debug.Assert(stage == ContentProcessingStage.Running);

            _pages.Add(page.Path, page);

            if (page.Path.GetName() != MenuFileName)
            {
                return(ContentResult.Continue);
            }

            // The menu file is not copied to the output!
            page.Discard = true;

            var rawMenu = YamlUtil.FromText(page.SourceFile.ReadAllText(), page.SourceFile.FullName);

            DecodeMenu(rawMenu, page);

            return(ContentResult.Break);
        }
Ejemplo n.º 9
0
        public async Task Test()
        {
            var n = new YamlUtil().NewFromYaml <RepoVersion>(@"
---
:archive_format: .gz
:format_version: 1
:guid: 08d56888-a75d-4e4c-842f-8db5f9d163f4
:version: 1
:pack_size: 28456
:wd_size: 140157
:pack:
  addons/ace_compat_rhs_afrf3.pbo.gz: f9cfb837b5d64f7fcf364911f83b135a
  addons/ace_compat_rhs_usf3.pbo.gz: 09b04627357283cf3fb39c32be6ebcfb
  addons/userconfig/ace/serverconfig.hpp.gz: 0babb2a8d97247947d57b28f4b6e723e
  addons/ace_compat_rhs_afrf3.pbo.ace_3.8.1.11-e1aa5b42.bisign.gz: 63595430b41898d2d338e4fff11332da
  addons/ace_compat_rhs_afrf3.pbo.six_ace3.bisign.gz: 287a8413dadfd4c2e7dc2bc1a1c07bb4
  addons/ace_compat_rhs_afrf3.pbo.six_ace_optionals.bisign.gz: a2d6ccb71acf718acf8fc8efff1a88fc
  addons/ace_compat_rhs_usf3.pbo.ace_3.8.1.11-e1aa5b42.bisign.gz: 1f36f49ff0d5ee9530837c1b14ed936a
  addons/ace_compat_rhs_usf3.pbo.six_ace3.bisign.gz: 2ac922c177f9496d8d300630f75b8572
  addons/ace_compat_rhs_usf3.pbo.six_ace_optionals.bisign.gz: 05ddf47bf34cafd68d2011f1a360a345
  keys/six_ace_optionals.bikey.gz: 03774883cfb9532af70ec2cd8a70fe70
:wd:
  addons/ace_compat_rhs_usf3.pbo: cb8bc8b508581843dc88412bf545a3ac
  addons/ace_compat_rhs_afrf3.pbo: 972b40ddc0a022235fa64d14dd83a621
  addons/userconfig/ace/serverconfig.hpp: 26b6ecd355676c7413f1fa376a57491e
  keys/six_ace_optionals.bikey: c191ba047f8aa5755c83dfb08d62edd9
  addons/ace_compat_rhs_usf3.pbo.six_ace_optionals.bisign: 17cda3e00aa5f05385850a00bbac8c33
  addons/ace_compat_rhs_usf3.pbo.six_ace3.bisign: bae42633fac2bc1f46549b4e9c55f000
  addons/ace_compat_rhs_usf3.pbo.ace_3.8.1.11-e1aa5b42.bisign: a3d55b42f84e22b749787fb036dbcc3d
  addons/ace_compat_rhs_afrf3.pbo.six_ace_optionals.bisign: cf912f0ab2bc94f6277a98b64f2b72dc
  addons/ace_compat_rhs_afrf3.pbo.six_ace3.bisign: 811bf388a7544124387d063624a7bb88
  addons/ace_compat_rhs_afrf3.pbo.ace_3.8.1.11-e1aa5b42.bisign: 81508e234450dffd3c2c88acfb5e0bd6
");

            Console.WriteLine(n.ToJson());
        }
Ejemplo n.º 10
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Starting lighthouse server");

            var server = new LighthouseServer();

            server.AddLogger(Console.WriteLine);

            Parser.Default.ParseArguments <RunOptions, ViewOptions>(args)
            .MapResult(
                (RunOptions runOptions) =>
            {
                if (string.IsNullOrEmpty(runOptions.Application) && string.IsNullOrEmpty(runOptions.File))
                {
                    throw new ApplicationException("Can't find app name");
                }

                if (!runOptions.IsAppMode)
                {
                    var fileContents = File.ReadAllText(runOptions.File);

                    var config = YamlUtil.ParseYaml <LighthouseRunConfig>(fileContents);

                    //(IEnumerable<ResourceProviderConfig> Resources, IEnumerable<Type> Types) = YamlV1Decomposer.Deserialize(fileContents);

                    //var failedResourceCreations = new List<string>();

                    //foreach (var resourceConfig in Resources)
                    //{
                    //    (bool wasSuccessful, string errorReason) = ResourceFactory.TryCreate(resourceConfig, out var resource);

                    //    if (wasSuccessful)
                    //    {
                    //        server.RegisterResourceProvider(resource);
                    //    }
                    //    else
                    //    {
                    //        failedResourceCreations.Add(errorReason);
                    //    }
                    //}

                    // load resources first
                    foreach (var resource in config.Resources)
                    {
                    }

                    // then launch apps
                    foreach (var app in config.Applications)
                    {
                    }
                }
                else
                {
                    Type appType = LighthouseFetcher.Fetch(runOptions.Application);
                    if (appType == null)
                    {
                        throw new ApplicationException("Can't find app name");
                    }

                    server.Launch(appType);
                }

                return(0);
            },
                (ViewOptions viewOptions) =>
            {
                if (Uri.TryCreate(viewOptions.Server, UriKind.Absolute, out var uri))
                {
                    //var connection = server.Connect(uri);

                    // do more things here
                    return(0);
                }
                else
                {
                    throw new ApplicationException($"URI: {viewOptions.Server} could not be converted to a valid URI");
                }
            },
                errs => 1
                );

            _ = Console.ReadLine();
            await server.Stop();
        }
Ejemplo n.º 11
0
        public int Run(IEnumerable <string> args)
        {
            LighthouseClient GetClient(Uri target)
            {
                var networkProvider = TypeFactory.Create <INetworkProvider>();
                var client          = new LighthouseClient(target, networkProvider);

                client.AddLogger(ConsoleWrite);
                return(client);
            }

            var result = Parser.Default.ParseArguments <RunOptions, InspectOptions, StopOptions, StoreOptions, RetrieveOptions, ConfigureOptions>(args)
                         .MapResult(
                (RunOptions run) =>
            {
                if (run.IsFileMode)
                {
                    var fileContents = File.ReadAllText(run.File);

                    var config = YamlUtil.ParseYaml <LighthouseRunConfig>(fileContents);

                    // load resources first
                    foreach (var resource in config.Resources)
                    {
                    }

                    // then launch apps
                    foreach (var app in config.Applications)
                    {
                    }
                }
                else
                {
                    if (run.Where != null)
                    {
                        var client = GetClient(run.Where.ToUri());

                        // make a connection to the other server
                        var response = client.MakeRequest <RemoteAppRunRequest, RemoteAppRunHandle>(new RemoteAppRunRequest(run.What)).GetAwaiter().GetResult();
                        ConsoleWrite($"Request {response?.Status ?? "no response"} (ID: {response?.Id ?? "no ID"})");
                    }
                    else
                    {
                        Type appType = LighthouseFetcher.Fetch(run.What);
                        if (appType == null)
                        {
                            throw new ApplicationException($"Can't find app with name: {run.What}");
                        }

                        // start a lighthouse server locally, and have it run the task
                        var server = new LighthouseServer();
                        server.AddLogger(ConsoleWrite);
                        server.Launch(appType).GetAwaiter().GetResult();
                    }
                }

                return(0);
            },
                (InspectOptions inspect) =>
            {
                var client = GetClient(inspect.Where.ToUri());

                if (inspect.Where == null)
                {
                    throw new Exception("Must include Where to inspect.");
                }

                if (inspect.What == null)
                {
                    var response = client.MakeRequest <StatusRequest, StatusResponse>(new StatusRequest()).GetAwaiter().GetResult();
                    ConsoleWrite(response.ToString());
                }
                else
                {
                    var response = client.MakeRequest <InspectRequest, InspectResponse>(
                        new InspectRequest {
                        What = inspect.What
                    }
                        ).GetAwaiter().GetResult();

                    ConsoleWrite(string.Join(Environment.NewLine, response.RawResponse));
                }

                return(0);
            },
                (StopOptions stop) =>
            {
                if (stop.What == null || stop.Where == null)
                {
                    throw new Exception("Stop what and where?");
                }

                var client = GetClient(stop.Where.ToUri());

                var response = client.MakeRequest <StopRequest, bool>(
                    new StopRequest {
                    What = stop.What
                }
                    ).GetAwaiter().GetResult();

                ConsoleWrite(response ? $"{stop.What} stopped on {stop.Where}" : "failed");

                return(0);
            },
                (StoreOptions store) =>
            {
                if (store.What == null || store.Where == null)
                {
                    throw new Exception("Stop what and where?");
                }

                var client      = GetClient(store.Where.ToUri());
                var deserialize = store.What.DeserializeFromJSON <WarehouseStoreRequest>();

                var response = client.MakeRequest <WarehouseStoreRequest, bool>(
                    new WarehouseStoreRequest {
                    Key = deserialize.Key, Value = deserialize.Value
                }
                    ).GetAwaiter().GetResult();

                ConsoleWrite(response ? "stored" : "failed");

                return(0);
            },
                (RetrieveOptions retrieve) =>
            {
                if (retrieve.What == null || retrieve.Where == null)
                {
                    throw new Exception("Stop what and where?");
                }

                var client      = GetClient(retrieve.Where.ToUri());
                var deserialize = retrieve.What.DeserializeFromJSON <WarehouseRetrieveRequest>();

                var response = client.MakeRequest <WarehouseRetrieveRequest, WarehouseRetrieveResponse>(
                    new WarehouseRetrieveRequest {
                    Key = deserialize.Key
                }
                    ).GetAwaiter().GetResult();

                ConsoleWrite(response.Value ?? string.Empty);

                return(0);
            },
                (ConfigureOptions configure) =>
            {
                if (configure.What == null || configure.Where == null || configure.How == null)
                {
                    throw new Exception("Configure what,where, and how?");
                }

                var client = GetClient(configure.Where.ToUri());

                if (configure.What == "resource")
                {
                    var request = configure.How.DeserializeFromJSON <ResourceRequest>();

                    var response = client.MakeRequest <ResourceRequest, ResourceResponse>(request).GetAwaiter().GetResult();

                    foreach (var val in response.ActionsTaken)
                    {
                        ConsoleWrite(val);
                    }

                    // inspect the event stream for bound events ???
                    return(0);
                }

                ConsoleWrite($"unsupported configure target {configure.What}");
                return(-1);
            },

                errs =>
            {
                foreach (var error in errs)
                {
                    ConsoleWrite(error.ToString());
                }

                throw new Exception(string.Join(",", errs));
            });

            return(0);
        }