public static void Update(this LegacyFeatureEntry entry, FeatureUpdateParams prms) { if (prms.Enabled.HasValue) { entry.Disabled = !prms.Enabled.Value; } if (prms.RequiredRoles != null) { entry.RequiredRoles = prms.RequiredRoles; } if (prms.Users != null) { entry.Users = prms.Users; } if (prms.Countries != null) { entry.Countries = prms.Countries; } if (prms.Continents != null) { entry.Continents = prms.Continents; } if (prms.AllowedIPs != null) { entry.AllowedIPs = prms.AllowedIPs; } if (prms.Description != null) { entry.Description = prms.Description; } }
public async Task <FeatureDetail> CreateFeature(string name, FeatureUpdateParams prms) { var sessionInfo = idInfo_.GetSessionInfo(); if (!sessionInfo.IsUser) { throw new AccessDeniedException($"Login required"); } if (newGates_) { var entry = new FeatureEntry() { Name = name, Issuer = sessionInfo.AccountId, Disabled = true, }; entry.Update(prms); try { var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Insert(entry.To <FeatureEntryTableEntity>())); var newEntry = (FeatureEntryTableEntity)tableResult.Result; return(newEntry.To <FeatureEntry>().ToFeatureDetail()); } catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409) { throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created"); } } else { var entry = new LegacyFeatureEntry() { PartitionKey = FeatureGateStore.GatePartitionKey, Name = name, Issuer = sessionInfo.AccountId, Disabled = true, }; entry.Update(prms); try { TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Insert(entry)); var newEntry = (LegacyFeatureEntry)tableResult.Result; return(newEntry.ToFeatureDetail()); } catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409) { throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created"); } } }
public static FeatureDetail ToFeatureDetail(this LegacyFeatureEntry entry) { return(new FeatureDetail { Name = entry.Name, Enabled = !entry.Disabled, RequiredRoles = entry.RequiredRoles, Users = entry.Users, Countries = entry.Countries, Continents = entry.Continents, AllowedIPs = entry.AllowedIPs, ReleaseDate = entry.ReleaseDate, LastModification = entry.Timestamp, Issuer = entry.Issuer, Description = entry.Description, }); }