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);
            }
        }
Esempio n. 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();
        }
Esempio n. 3
0
        private void ImportKey()
        {
            this.DenServicesController.Path = this.DenServicesController.Path.TrimEnd(System.IO.Path.DirectorySeparatorChar);
            string path = $"{this.DenServicesController.Path}{System.IO.Path.DirectorySeparatorChar}den-server";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            File.WriteAllText($"{path}{System.IO.Path.DirectorySeparatorChar}den-server.key", KeyCertUtils.DerToPem(this.DenConfig.DenServerConfigObject.PrivateKey));
            File.WriteAllText($"{path}{System.IO.Path.DirectorySeparatorChar}den-router.key", KeyCertUtils.DerToPem(this.DenConfig.DenServerConfigObject.PublicKey));
            string mountPoint = this.DenConfig.DenDockerConfigObject.Platform == Platforms.Linux.ToString() ? DEN_SERVER_LINUX_PATH : DEN_SERVER_WINDOWS_PATH;

            this.Volumes.Add($"den-server:{mountPoint}:ro");
            this.Env.Add($"{DEN_PRIVATE_KEY_FILE_ENV}={mountPoint}/den-server.key");
            this.Env.Add($"{DEN_PUBLIC_KEY_FILE_ENV}={mountPoint}/den-router.key");
        }