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); }