Beispiel #1
0
        public bool CreateTenant(string tenantName, TenantSettings tenantSettings)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant != null)
            {
                return(false);
            }

            var tenantConfiguration = new TenantConfiguration()
            {
                Name = tenantName, Settings = tenantSettings
            };

            tenants.Add(tenantConfiguration);
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                _tenantRepository.AddTenantFromApi(tenantConfiguration);
                _storageHubService.CreateTenantAsync(_tenantFactory
                                                     .CreateTenant(tenantConfiguration.Name,
                                                                   tenantConfiguration.Settings.DigitalSignature,
                                                                   tenantConfiguration.Settings.EnableEncryption,
                                                                   tenantConfiguration.Settings.AllowProductCreation,
                                                                   tenantConfiguration.Settings.EnableAuthorization,
                                                                   tenantConfiguration.Settings.Tokens,
                                                                   tenantConfiguration.Settings.Logging,
                                                                   tenantConfiguration.Settings.EnableGeoReplication,
                                                                   tenantConfiguration.Settings.CertificatePath));
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public bool RevokeComponentToken(string tenantName, string productName, string componentName, string token)
        {
            // Remove from the memory
            _tenantRepository.RemoveComponentToken(tenantName, productName, componentName, token);
            // remove from config file

            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(false);
            }

            var product = tenant.Products.Find(x => x.Name == productName);

            if (product == null)
            {
                return(false);
            }

            var component = product.Components.Find(x => x.Name == componentName);

            if (component == null)
            {
                return(false);
            }


            var componentToken = component.Settings.Tokens.Find(x => x.Token == token);

            if (componentToken == null)
            {
                return(true);
            }

            component.Settings.Tokens.Remove(componentToken);

            // write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                // Send to the Cluster
                _storageHubService.SendRevokeComponentTokenStorage(new Model.Storages.Requests.Components.RevokeComponentTokenDetails()
                {
                    Tenant    = tenantName,
                    Product   = productName,
                    Component = componentName,
                    Token     = token,

                    StoragesAlreadySent = new List <string>()
                });

                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public string AddComponentToken(string tenantName, string productName, string componentName, ComponentToken componentToken, bool shoudGenerateToken = true)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            var product = tenant.Products.Find(x => x.Name == productName);

            if (product == null)
            {
                return(null);
            }

            var component = product.Components.Find(x => x.Name == componentName);

            if (component == null)
            {
                return(null);
            }

            if (shoudGenerateToken == true)
            {
                string apiKey = KeyGenerators.GenerateApiKey();
                componentToken.Token = apiKey;
            }

            component.Settings.Tokens.Add(componentToken);

            // store token in memory!
            _tenantRepository.AddComponentToken(tenantName, productName, componentName, componentToken);

            // Write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                if (shoudGenerateToken == true)
                {
                    // Send to the Cluster
                    _storageHubService.SendCreateComponentTokenStorage(new Model.Storages.Requests.Components.CreateComponentTokenDetails()
                    {
                        Tenant    = tenantName,
                        Product   = productName,
                        Component = componentName,
                        Token     = componentToken,

                        StoragesAlreadySent = new List <string>()
                    });
                }
                return(componentToken.Token);
            }

            return(null);
        }
Beispiel #4
0
        public TenantConfiguration GetTenant(string tenantName)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant != null)
            {
                tenant.Products.Clear();
            }
            return(tenant);
        }
Beispiel #5
0
        public List <TenantToken> GetTokens(string tenantName)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            return(tenant.Settings.Tokens);
        }
Beispiel #6
0
        public bool AddTopic(string tenant, string product, string component, string topicName, Topic topic)
        {
            if (_tenants.ContainsKey(tenant))
            {
                if (_tenants[tenant].Products.ContainsKey(product))
                {
                    if (_tenants[tenant].Products[product].Components.ContainsKey(component))
                    {
                        _tenants[tenant].Products[product].Components[component].Topics.TryAdd(topicName, topic);
                    }
                }
            }

            List <TenantConfiguration> tenantsConfig = TenantIOReader.ReadTenantsFromConfigFile();
            var tenantDetail = tenantsConfig.Find(x => x.Name == tenant);

            if (tenantDetail != null)
            {
                var productDetail = tenantDetail.Products.Find(x => x.Name == product);
                if (productDetail == null)
                {
                    return(false);
                }

                var componentDetails = productDetail.Components.Find(x => x.Name == component);
                if (componentDetails == null)
                {
                    return(false);
                }

                var topicDetails = componentDetails.Topics.Find(x => x.Name == topicName);
                if (topicDetails != null)
                {
                    return(false);
                }

                componentDetails.Topics.Add(new TopicConfiguration()
                {
                    Name = topicName
                });
                if (TenantIOWriter.WriteTenantsConfiguration(tenantsConfig) == true)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
        public string AddToken(string tenantName, TenantToken tenantToken)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            tenant.Settings.Tokens.Add(tenantToken);
            _tenantRepository.AddTenantToken(tenantName, tenantToken);

            // Write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                return(tenantToken.Token);
            }

            return(null);
        }
Beispiel #8
0
        public bool AddComponent(string tenant, string product, string componentName, Component component)
        {
            if (_tenants.ContainsKey(tenant))
            {
                if (_tenants[tenant].Products.ContainsKey(product))
                {
                    _tenants[tenant].Products[product].Components.TryAdd(componentName, component);
                }
            }

            //add component to tenants_config.json
            List <TenantConfiguration> tenantsConfig = TenantIOReader.ReadTenantsFromConfigFile();
            var tenantDetail = tenantsConfig.Find(x => x.Name == tenant);

            if (tenantDetail != null)
            {
                var productDetail = tenantDetail.Products.Find(x => x.Name == product);
                if (productDetail == null)
                {
                    return(false);
                }

                var componentDetails = productDetail.Components.Find(x => x.Name == componentName);
                if (componentDetails != null)
                {
                    return(true);
                }

                productDetail.Components.Add(new ComponentConfiguration()
                {
                    Name = componentName, Settings = component.Settings, Topics = new List <TopicConfiguration>()
                });
                if (TenantIOWriter.WriteTenantsConfiguration(tenantsConfig) == true)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #9
0
        public string AddToken(string tenantName, DateTime expireDate)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            string apiKey = KeyGenerators.GenerateApiKey();

            var tenantToken = new TenantToken()
            {
                ExpireDate = expireDate,
                Token      = apiKey,
                IsActive   = true,
                IssuedDate = DateTime.Now,
                IssuedFor  = $"Issued for tenant {tenantName}"
            };

            tenant.Settings.Tokens.Add(tenantToken);
            _tenantRepository.AddTenantToken(tenantName, tenantToken);

            // Write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                // Send to the Cluster
                _storageHubService.SendCreateTenantTokenStorage(new Model.Storages.Requests.Tenants.CreateTenantTokenDetails()
                {
                    Tenant = tenantName,
                    Token  = tenantToken,
                    StoragesAlreadySent = new List <string>()
                });

                return(apiKey);
            }

            return(null);
        }
Beispiel #10
0
        public string AddRetentionPolicy(string tenantName, string productName, string componentName, ComponentRetention retention)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            var product = tenant.Products.Find(x => x.Name == productName);

            if (product == null)
            {
                return(null);
            }

            var component = product.Components.Find(x => x.Name == componentName);

            if (component == null)
            {
                return(null);
            }


            component.Settings.RetentionPolicy = retention;
            // store token in memory!
            _tenantRepository.AddComponentRetention(tenantName, productName, componentName, retention);

            // Write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                return(retention.Name);
            }

            return(null);
        }
Beispiel #11
0
        public bool AddProduct(string tenant, string productName, Product product)
        {
            if (_tenants.ContainsKey(tenant))
            {
                _tenants[tenant].Products.TryAdd(productName, product);
            }

            // adding product to tenants_config
            List <TenantConfiguration> tenantsConfig = TenantIOReader.ReadTenantsFromConfigFile();
            var tenantDetail = tenantsConfig.Find(x => x.Name == tenant);

            if (tenantDetail != null)
            {
                if (tenantDetail.Products == null)
                {
                    tenantDetail.Products = new List <ProductConfiguration>();
                }

                var productDetail = tenantDetail.Products.Find(x => x.Name == productName);
                if (productDetail != null)
                {
                    return(true);
                }

                // register product to tenantConfiguration
                tenantDetail.Products.Add(new ProductConfiguration()
                {
                    Name = productName, Components = new List <ComponentConfiguration>()
                });
                if (TenantIOWriter.WriteTenantsConfiguration(tenantsConfig) == true)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #12
0
        public List <string> GetTenantsName()
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();

            return(tenants.Select(x => x.Name).ToList());
        }