コード例 #1
0
        private string LoadPassword()
        {
            try
            {
                string dir  = Directory.GetParent(this.path).FullName;
                string file = $"{dir}/WaykDen.key";
                if (!File.Exists(file))
                {
                    string pswd = DenServiceUtils.GenerateRandom(20);
                    File.WriteAllText(file, pswd.Replace("-", string.Empty));
                    return(pswd);
                }

                return(File.ReadAllText(file));
            }
            catch (Exception e)
            {
                e.ToString();
                return(string.Empty);
            }
        }
コード例 #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();
        }
コード例 #3
0
        public async Task <bool> StartWaykDen(int instanceCount = 1)
        {
            try
            {
                Task t = this.RemoveWaykDenContainers();
                t.Wait();

                List <string> networks = await this.GetDenNetwork();

                if (networks.Count == 0)
                {
                    await this.DenNetwork.CreateNetwork();
                }
                else
                {
                    this.DenNetwork.SetNetworkId(networks[0]);
                }

                if (string.IsNullOrEmpty(this.DenConfig.DenLucidConfigObject.ApiKey))
                {
                    this.DenConfig.DenLucidConfigObject.ApiKey = DenServiceUtils.GenerateRandom(32);
                }

                if (string.IsNullOrEmpty(this.DenConfig.DenLucidConfigObject.AdminSecret))
                {
                    this.DenConfig.DenLucidConfigObject.AdminSecret = DenServiceUtils.GenerateRandom(10);
                }

                if (string.IsNullOrEmpty(this.DenConfig.DenLucidConfigObject.AdminUsername))
                {
                    this.DenConfig.DenLucidConfigObject.AdminUsername = DenServiceUtils.GenerateRandom(16);
                }

                if (string.IsNullOrEmpty(this.DenConfig.DenServerConfigObject.ApiKey))
                {
                    this.DenConfig.DenServerConfigObject.ApiKey = DenServiceUtils.GenerateRandom(32);
                }

                if (string.IsNullOrEmpty(this.DenConfig.DenPickyConfigObject.ApiKey))
                {
                    this.DenConfig.DenPickyConfigObject.ApiKey = DenServiceUtils.GenerateRandom(32);
                }

                if (!string.IsNullOrEmpty(this.DenConfig.DenTraefikConfigObject.Certificate) && (string.IsNullOrEmpty(this.DenConfig.DenTraefikConfigObject.PrivateKey)))
                {
                    this.WriteError(new Exception("No private key found for certificate. Add private key or remove certificate"));
                    return(false);
                }

                bool started = await this.StartDenMongo();

                started = started ? await this.StartDenPicky(): false;

                started = started ? await this.StartDenLucid() : false;

                int count = 1;
                while (count != instanceCount + 1)
                {
                    started = started ? await this.StartDenServer(instanceCount > 1, count) : false;

                    count++;
                }

                if (started)
                {
                    Task <bool> traefikStarted = this.StartTraefikService(instanceCount);
                    traefikStarted.Wait();
                    started = await traefikStarted;
                    if (!started)
                    {
                        this.WriteError(new Exception("Error starting Traefik service. Make sure External URL is well configured."));
                    }
                }

                return(started);
            }
            catch (Exception e)
            {
                this.WriteError(e);
                return(false);
            }
        }