public static void Update(this FeatureEntry 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.Select(CreyIPAddress.ParseNetwork).ToList(); } if (prms.Description != null) { entry.Description = prms.Description; } }
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 async Task <FeatureDetail> UpdateFeature(string name, FeatureUpdateParams prms) { if (newGates_) { var table = featureStore_.Value.Storage; FeatureEntry entry = (await table.RetrieveAsync <FeatureEntryTableEntity>(FeatureGateStore.GatePartitionKey, name)).To <FeatureEntry>(); if (entry == null) { throw new ItemNotFoundException($"Feature gate [{name}] not found"); } entry.Update(prms); try { var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Replace(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 update feature, already removed or modified"); } } else { var table = featureStore_.Value.GatesTable; var entry = await table.GetRowAsync <LegacyFeatureEntry>(FeatureGateStore.GatePartitionKey, name); if (entry == null) { throw new ItemNotFoundException($"Feature gate [{name}] not found"); } entry.Update(prms); try { TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Replace(entry)); var newEntry = (LegacyFeatureEntry)tableResult.Result; return(newEntry.ToFeatureDetail()); } catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409) { throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to update feature, already removed or modified"); } } }
public Task <FeatureDetail> UpdateFeature(string name, [FromBody] FeatureUpdateParams prms) { return(featureGates_.Value.UpdateFeature(name, prms)); }