protected override void ProcessRecord()
        {
            try
            {
                DenConfigController denConfigController = new DenConfigController(this.Path, this.Key);
                DenConfig           config = denConfigController.GetConfig();

                if (this.ParameterSetName == PKCS12)
                {
                    CertificateObject cert = KeyCertUtils.GetPkcs12CertificateInfo(CertificatePath, this.KeyPassword);
                    config.DenTraefikConfigObject.Certificate = cert.Certificate;
                    config.DenTraefikConfigObject.PrivateKey  = cert.Privatekey;
                }
                else
                {
                    config.DenTraefikConfigObject.Certificate = File.ReadAllText(CertificatePath);
                    config.DenTraefikConfigObject.PrivateKey  = File.ReadAllText(PrivateKeyPath);
                }

                if (string.IsNullOrEmpty(config.DenTraefikConfigObject.Certificate))
                {
                    this.OnError(new Exception("No certificate found"));
                }

                if (string.IsNullOrEmpty(config.DenTraefikConfigObject.PrivateKey))
                {
                    this.OnError(new Exception("No private key found"));
                }

                denConfigController.StoreConfig(config);
            }
            catch (Exception e)
            {
                this.OnError(e);
            }
        }
示例#2
0
        protected override void ProcessRecord()
        {
            try
            {
                DenConfigController denConfigController = new DenConfigController(this.Path, this.Key);

                if (denConfigController.DbExists)
                {
                    this.DenConfig = denConfigController.GetConfig();
                    this.UpdateConfig();
                }
                else
                {
                    if (string.IsNullOrEmpty(this.Platform))
                    {
                        this.Platform = "Linux";
                    }

                    Platforms       platform        = this.Platform.Equals("Linux") ? Platforms.Linux : Platforms.Windows;
                    RsaKeyGenerator rsaKeyGenerator = new RsaKeyGenerator();
                    this.DenConfig = new DenConfig()
                    {
                        DenDockerConfigObject = new DenDockerConfigObject
                        {
                            DockerClientUri = string.IsNullOrEmpty(this.DockerClientUri) ? this.DockerDefaultEndpoint : this.DockerClientUri,
                            Platform        = platform.ToString(),
                            SyslogServer    = this.SyslogServer
                        },

                        DenMongoConfigObject = new DenMongoConfigObject
                        {
                            Url = !string.IsNullOrEmpty(this.MongoUrl) ? this.MongoUrl : DEFAULT_MONGO_URL
                        },

                        DenPickyConfigObject = new DenPickyConfigObject
                        {
                            ApiKey  = DenServiceUtils.GenerateRandom(32),
                            Backend = "mongodb",
                            Realm   = this.Realm
                        },

                        DenLucidConfigObject = new DenLucidConfigObject
                        {
                            AdminSecret   = DenServiceUtils.GenerateRandom(10),
                            AdminUsername = DenServiceUtils.GenerateRandom(16),
                            ApiKey        = DenServiceUtils.GenerateRandom(32)
                        },

                        DenServerConfigObject = new DenServerConfigObject
                        {
                            ApiKey         = DenServiceUtils.GenerateRandom(32),
                            AuditTrails    = "true",
                            ExternalUrl    = this.ExternalUrl,
                            LDAPPassword   = this.LDAPPassword != null ? this.LDAPPassword : string.Empty,
                            LDAPServerUrl  = this.LDAPServerUrl != null ? this.LDAPServerUrl : string.Empty,
                            LDAPUserGroup  = this.LDAPUserGroup != null ? this.LDAPUserGroup : string.Empty,
                            LDAPUsername   = this.LDAPUsername != null ? this.LDAPUsername : string.Empty,
                            LDAPServerType = this.LDAPServerType != null ? this.LDAPServerType : string.Empty,
                            LDAPBaseDN     = this.LDAPBaseDN != null ? this.LDAPBaseDN : string.Empty,
                            PrivateKey     = KeyCertUtils.PemToDer(rsaKeyGenerator.PrivateKey),
                            JetServerUrl   = this.JetServerUrl != null ? this.JetServerUrl : string.Empty,
                            JetRelayUrl    = this.JetRelayUrl != null ? this.JetRelayUrl : string.Empty,
                            LoginRequired  = this.LoginRequired ? "True": "False",
                            PublicKey      = KeyCertUtils.PemToDer(rsaKeyGenerator.PublicKey),
                            NatsUsername   = this.NatsUsername,
                            NatsPassword   = this.NatsPassword,
                            RedisPassword  = this.RedisPassword
                        },

                        DenTraefikConfigObject = new DenTraefikConfigObject
                        {
                            WaykDenPort = this.WaykDenPort != null ? this.WaykDenPort : "4000",
                            Certificate = this.CertificatePath != null ? this.CertificatePath : string.Empty,
                            PrivateKey  = this.PrivateKeyPath != null ? this.PrivateKeyPath : string.Empty
                        },

                        DenImageConfigObject = new DenImageConfigObject(platform)
                    };
                }

                denConfigController.StoreConfig(this.DenConfig);
                Environment.SetEnvironmentVariable(WAYK_DEN_HOME, this.Path);
            }
            catch (Exception e)
            {
                this.OnError(e);
            }

            base.ProcessRecord();
        }