public async Task <CommandResult> Handle(CreateSnapshotCommand command) { var client = await clientService.GetClientOrDefault(command.ClientId); if (client == null || string.IsNullOrWhiteSpace(client.Group)) { return(CommandResult.Failure("Could not find client with group. Can only create snapshot for client with group")); } var models = configurationModelRegistry.GetConfigurationRegistrations(true); var version = configurationModelRegistry.GetVersion(); var configurationIdentity = new ConfigurationIdentity(client, version); var snapshotInfo = new SnapshotEntryInfo { Id = Guid.NewGuid().ToString(), GroupId = client.Group, Name = command.Name, TimeStamp = DateTime.UtcNow }; var configurations = new List <ConfigInstance>(); foreach (var model in models) { var configurationInstance = await configurationService.GetAsync(model.ConfigType, configurationIdentity); configurations.Add(configurationInstance); } await snapshotRepository.SaveSnapshot(new ConfigurationSnapshotEntry { Info = snapshotInfo, Configurations = configurations }); return(CommandResult.Success()); }
private async Task <ConfigurationIdentity> GetIdentityFromPathOrDefault(string pathParam) { var client = await configClientService.GetClientOrDefault(pathParam); var clientIdentity = new ConfigurationIdentity(client, registry.GetVersion()); return(clientIdentity); }
private async Task <ConfigurationIdentity> GetIdentityFromPathOrDefault(string pathParam) { if (string.Equals(pathParam, clientGroupImagePath, StringComparison.OrdinalIgnoreCase)) { return(new ConfigurationIdentity(new ConfigurationClient(clientGroupImagePath), registry.GetVersion())); } var client = await configClientService.GetClientOrDefault(pathParam); var clientIdentity = new ConfigurationIdentity(client, registry.GetVersion()); return(clientIdentity); }
public async Task <CommandResult> Handle(PushSnapshotToClientCommand command) { var version = registry.GetVersion(); var snapshotEntry = await repo.GetSnapshot(command.SnapshotId, new ConfigurationIdentity(command.TargetClient, version)); foreach (var instance in GetConfigurations(snapshotEntry, command)) { await configRepository.UpdateConfigAsync(instance); await eventService.Publish(new ConfigurationUpdatedEvent(instance)); } return(CommandResult.Success()); }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // Model/{ Client Id}/{ Configuration Set} // GET: Model for configuration set if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } var configSet = configCollection.SingleOrDefault(c => pathParams[1].Equals(c.ConfigSetType.Name, StringComparison.OrdinalIgnoreCase)); if (configSet == null) { return; } await httpResponseFactory.BuildJsonResponse(context, await modelPayloadMapper.Map(configSet, new ConfigurationIdentity(client, configCollection.GetVersion()))); return; }
public async Task <ResourceEntry> GetResourceAsync(string name, string clientId) { var client = await configurationClientService.GetClientOrDefault(clientIdProvider.GetCurrentClientId()); return(await resourceStore.GetResource(name, new ConfigurationIdentity(client, registry.GetVersion())).ConfigureAwait(false)); }
private ConfigurationIdentity BuildIdentity(ConfigurationClient client) => new ConfigurationIdentity(client, configCollection.GetVersion());
public async Task <ConfigInstance> GetConfigInstanceOrDefault(ConfigurationClient client, string configId) { if (client == null) { return(null); } var configModelResult = configModelCollection.SingleOrDefault(s => string.Equals(s.Type.Name, configId, StringComparison.OrdinalIgnoreCase)); if (configModelResult == null) { return(null); } var config = await configurationService.GetAsync(configModelResult.Type, new ConfigurationIdentity(client, registry.GetVersion())); return(config); }
public async Task <IEnumerable <TConfig> > GetCollectionConfigAsync <TConfig>(string clientId) where TConfig : class, new() { var client = await configurationClientService.GetClientOrDefault(clientId); var config = await configProvider.GetCollectionAsync <TConfig>(new ConfigurationIdentity(client, registry.GetVersion())).ConfigureAwait(false); return(config); }
private async Task HandlePostRequest(HttpContext context, ConfigurationClient client, string configType) { var configModel = configCollection.SelectMany(s => s.Configs).SingleOrDefault(s => s.Type.Name.Equals(configType, StringComparison.OrdinalIgnoreCase)); if (configModel == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var command = new UpdateConfigurationFromEditorCommand(new ConfigurationIdentity(client, configCollection.GetVersion()), configModel.Type, await context.ReadBodyTextAsync()); var result = await commandBus.SubmitAsync(command); await httpResponseFactory.BuildResponseFromCommandResult(context, result); }
private async Task <FilePayload> GetPayloadOrDefault(string[] pathParams, ConfigurationClient client) { if (pathParams.Length == 2) { var configurationSet = configCollection.SingleOrDefault(s => pathParams[1].Equals($"{s.ConfigSetType.Name}{jsonExtension}", StringComparison.OrdinalIgnoreCase)); if (configurationSet == null) { return(null); } return(new FilePayload(await GetConfigurationSet(configurationSet, client), $"{configurationSet.ConfigSetType.Name}{jsonExtension}")); } if (pathParams.Length == 3) { var configurationSetModel = configCollection.SingleOrDefault(s => pathParams[1].Equals(s.ConfigSetType.Name, StringComparison.OrdinalIgnoreCase)); if (configurationSetModel == null) { return(null); } var configModel = configurationSetModel.Configs.SingleOrDefault(s => pathParams[2].Equals($"{s.Type.Name}{jsonExtension}", StringComparison.OrdinalIgnoreCase)); if (configModel == null) { return(null); } var configurationSet = await configurationSetService.GetConfigurationSet(configurationSetModel.ConfigSetType, new ConfigurationIdentity(client, configCollection.GetVersion())); return(new FilePayload(configModel.GetConfigurationFromConfigurationSet(configurationSet), $"{configModel.Type.Name}{jsonExtension}")); } return(null); }