示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public bool RevokeToken(string tenantName, string token)
        {
            // Remove from the memory
            _tenantRepository.RemoveTenantToken(tenantName, token);
            // remove from config file

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

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

            // remove from config file.
            var tenantToken = tenant.Settings.Tokens.Find(x => x.Token == token);

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

            tenant.Settings.Tokens.Remove(tenantToken);

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

            return(false);
        }
示例#4
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);
        }
示例#5
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);
        }