Esempio n. 1
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);
        }
Esempio n. 2
0
        public async Task CreateComponentTokenToThisNode(CreateComponentTokenDetails createComponentTokenDetails)
        {
            if (_tenantRepository.GetComponentToken(createComponentTokenDetails.Tenant, createComponentTokenDetails.Product, createComponentTokenDetails.Component, createComponentTokenDetails.Token.Token) == null)
            {
                _componentApiService.AddComponentToken(createComponentTokenDetails.Tenant, createComponentTokenDetails.Product, createComponentTokenDetails.Component, createComponentTokenDetails.Token, false);
            }

            // send to other nodes....
            await _storageHubService.SendCreateComponentTokenStorage(createComponentTokenDetails);
        }