Exemplo n.º 1
0
        public DscPullClient(DscPullConfig config, Func <HttpClientHandler, HttpClient> clientFactory = null)
        {
            Configuration = config;
            if (clientFactory != null)
            {
                _clientFactory = clientFactory;
            }

            LOG.LogInformation("Initializing DSC Pull Client -- validating state");

            AssertState(Configuration != null,
                        /*SR*/ "missing configuration");
            AssertState(Configuration.AgentInformation != null,
                        /*SR*/ "missing configuration agent information");
            AssertState(Configuration.ConfigurationNames?.Count() > 0,
                        /*SR*/ "at least one configuration name must be configured");
            AssertState(Configuration.ConfigurationRepositoryServer != null ||
                        Configuration.ResourceRepositoryServer != null ||
                        Configuration.ReportServer != null,
                        /*SR*/ "at least one target server configuration must be specified");

            // Create JSON ser settings to be used in JSON to/from serializations
            _jsonSerSettings = new JsonSerializerSettings();
            // This enables converting Enums to/from their string names instead
            // of their numerical value, based on:
            //    * https://www.exceptionnotfound.net/serializing-enumerations-in-asp-net-web-api/
            //    * https://siderite.blogspot.com/2016/10/controlling-json-serialization-in-net.html
            _jsonSerSettings.Converters.Add(new StringEnumConverter());

            IsInitialized = true;

            LOG.LogInformation("Initialized DSC Pull Client");
        }
Exemplo n.º 2
0
        protected static DscPullConfig BuildConfig(bool newAgentId = false)
        {
            var config = new DscPullConfig();

            config.AgentId = newAgentId
                    ? Guid.NewGuid()
                    : Guid.Parse(DEFAULT_AGENT_ID);

            config.AgentInformation   = TugDSC.Client.CLIApp.Program.ComputeAgentInformation();
            config.ConfigurationNames = new[] { "StaticTestConfig" };

            // This is required for RegKey Authz
            config.CertificateInformation = new Model.CertificateInformation
            {
                FriendlyName = "Tug.Client-Test",
                Issuer       = "Tug.Client.Test",
                NotAfter     = DateTime.Now.AddYears(1).ToString("O"),
                NotBefore    = DateTime.Now.AddMinutes(-10).ToString("O"),
                Subject      = "Tug.Client-TestNode",
                PublicKey    = "U3lzdGVtLlNlY3VyaXR5LkNyeXB0b2dyYXBoeS5YNTA5Q2VydGlmaWNhdGVzLlB1YmxpY0tleQ==",
                Thumbprint   = "8351F16C2B06634279F2C0287B5430452DA1CD94",
                Version      = 3,
            };

            config.ConfigurationRepositoryServer = new DscPullConfig.ServerConfig
            {
                ServerUrl       = new Uri(DEFAULT_SERVER_URL),
                RegistrationKey = DEFAULT_REG_KEY,
            };

            // Resource Server Endpoint URL is same as Config Server Endpoint URL
            config.ResourceRepositoryServer = config.ConfigurationRepositoryServer;

            return(config);
        }
Exemplo n.º 3
0
 protected static DscPullClient BuildClient(DscPullConfig config = null)
 {
     if (config == null)
     {
         config = _defaultConfig;
     }
     return(new DscPullClient(config, x => _tugServer.CreateClient()));
 }
Exemplo n.º 4
0
        public static void Init(TestContext ctx)
        {
            var myPath = typeof(ServerProtocolTests).GetTypeInfo().Assembly.Location;
            var myDir  = Path.GetDirectoryName(myPath);

            Directory.SetCurrentDirectory(myDir);

            var hostBuilder = new WebHostBuilder()
                              .UseLoggerFactory(AppLog.Factory)
                              .UseStartup <Startup>();

            _tugServer = new TestServer(hostBuilder);

            _defaultConfig = BuildConfig();
            _defaultClient = BuildClient();
        }
Exemplo n.º 5
0
        public void Execute(string[] args)
        {
            var run = new List <Action>();

            _commandLine = new CommandLine();
            _commandLine.OnRegisterAgent             = () => run.Add(DoRegisterAgent);
            _commandLine.OnGetAction                 = () => run.Add(DoGetAction);
            _commandLine.OnGetConfiguration          = () => run.Add(DoGetConfiguration);
            _commandLine.OnGetActionAndConfiguration = () => run.Add(DoGetActionAndConfiguration);
            _commandLine.OnGetModule                 = () => run.Add(DoGetModule);

            _commandLine.Init().Execute(args);

            _config = ResolveClientConfiguration();

            try
            {
                using (_client = new DscPullClient(_config))
                {
                    foreach (var r in run)
                    {
                        r();
                    }
                }
            }
            catch (AggregateException ex)
            {
                Console.Error.WriteLine("UNCAUGHT EXCEPTION:");
                Console.Error.WriteLine(ex.InnerException);
                Console.Error.WriteLine("INNER EXCEPTIONS ====================>");
                foreach (var iex in ex.InnerExceptions)
                {
                    Console.Error.WriteLine(iex);
                }
            }
        }
        protected static DscPullConfig BuildConfig(bool newAgentId = false)
        {
            var config = new DscPullConfig();

            config.AgentId = newAgentId
                    ? Guid.NewGuid()
                    : Guid.Parse(_testConfig.agent_id);

            config.AgentInformation   = Program.ComputeAgentInformation();
            config.ConfigurationNames = new[] { "TestConfig1" };

            // This is required for RegKey Authz
            config.CertificateInformation = new Model.CertificateInformation
            {
                FriendlyName = "Tug.Client-Test",
                Issuer       = "Tug.Client.Test",
                NotAfter     = DateTime.Now.AddYears(1).ToString("O"),
                NotBefore    = DateTime.Now.AddMinutes(-10).ToString("O"),
                Subject      = "Tug.Client-TestNode",
                PublicKey    = "U3lzdGVtLlNlY3VyaXR5LkNyeXB0b2dyYXBoeS5YNTA5Q2VydGlmaWNhdGVzLlB1YmxpY0tleQ==",
                Thumbprint   = "8351F16C2B06634279F2C0287B5430452DA1CD94",
                Version      = 3,
            };

            config.ConfigurationRepositoryServer = new DscPullConfig.ServerConfig
            {
                ServerUrl       = new Uri(_testConfig.server_url),
                RegistrationKey = _testConfig.reg_key,
            };

            // Only for debugging/testing in DEV (i.e. with Fiddler)
            if (!string.IsNullOrEmpty(_testConfig.proxy_url))
            {
                config.ConfigurationRepositoryServer.Proxy =
                    new Util.BasicWebProxy(_testConfig.proxy_url);
            }

            // Resource & Reporting Server endpoint URLs same as Config Server endpoint URL
            config.ResourceRepositoryServer = config.ConfigurationRepositoryServer;
            config.ReportServer             = config.ConfigurationRepositoryServer;

            config.SendReport = new DscPullConfig.SendReportConfig
            {
                CommonDefaults = new Model.SendReportBody
                {
                    OperationType       = "Consistency",
                    ReportFormatVersion = "2.0",
                    StartTime           = "%NOW%",
                    AdditionalData      = new[]
                    {
                        new Model.SendReportBody.AdditionalDataItem
                        {
                            Key   = "OSVersion",
                            Value = "{\"VersionString\":\"Microsoft Windows NT 10.0.14393.0\",\"ServicePack\":\"\",\"Platform\":\"Win32NT\"}"
                        },
                        new Model.SendReportBody.AdditionalDataItem
                        {
                            Key   = "PSVersion",
                            Value = "{\"CLRVersion\":\"4.0.30319.42000\",\"PSVersion\":\"5.1.14393.576\",\"BuildVersion\":\"10.0.14393.576\"}"
                        },
                    }
                },
                Profiles = new Dictionary <string, Model.SendReportBody>
                {
                    ["SimpleInventoryDefaults"] = new Model.SendReportBody
                    {
                        NodeName   = "HOST_NAME",
                        IpAddress  = "127.0.0.1;::1",
                        LCMVersion = "2.0",
                    },
                    ["DetailedStatusDefaults"] = new Model.SendReportBody
                    {
                        RefreshMode          = Model.DscRefreshMode.Pull,
                        Status               = "Success",
                        EndTime              = "%NOW%",
                        ConfigurationVersion = "2.0",
                        RebootRequested      = Model.DscTrueFalse.False,
                    },
                    ["ErrorDefaults"] = new Model.SendReportBody
                    {
                    },
                },
            };

            return(config);
        }