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); }
public async Task CanGetClient() { var result = await target.GetClientOrDefault(clientOne); Assert.Equal(clientOne, result.ClientId); Assert.Equal("One", result.Name); Assert.Equal(groupOne, result.Group); }
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 Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 2) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configurationClientService.GetClientOrDefault(pathParams[0]); if (!context.ChallengeClientRead(options, client, httpResponseFactory)) { return; } var config = await router.GetConfigInstanceOrDefault(client, pathParams[1]); if (config == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else { await httpResponseFactory.BuildJsonResponse(context, config.GetConfiguration()); } }
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()); }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } // clientId/ConfigSet.json // clientId/ConfigSet/Config.json 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 payload = await GetPayloadOrDefault(pathParams, client); if (payload == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else { await httpResponseFactory.BuildJsonFileResponse(context, payload.Payload, payload.FileName); } }
private async Task HandlePushSnapshotToClient(HttpContext context, string[] pathParams, ConfigServerOptions options) { if (context.Request.Method != "POST") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return; } var client = await configurationClientService.GetClientOrDefault(pathParams[2]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } var request = await context.GetObjectFromJsonBodyAsync <PushSnapshotToClientRequest>(); if (client != null && request != null && pathParams[1].Equals("to", StringComparison.OrdinalIgnoreCase)) { var command = new PushSnapshotToClientCommand { SnapshotId = pathParams[0], TargetClient = client, ConfigsToCopy = request.ConfigsToCopy ?? new string[0] }; var commmandResult = await commandBus.SubmitAsync(command); await httpResponseFactory.BuildResponseFromCommandResult(context, commmandResult); return; } httpResponseFactory.BuildNotFoundStatusResponse(context); }
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 HandleClientPath(HttpContext context, string clientId, ConfigServerOptions options) { var client = await configurationClientService.GetClientOrDefault(clientId); if (context.ChallengeClientConfiguratorOrAdmin(options, client, httpResponseFactory)) { await httpResponseFactory.BuildJsonResponse(context, Map(client)); } }
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 Handle(HttpContext context, ConfigServerOptions options) { // /ConfigurationSet/{clientId}/{Configuration Set} // POST: Uploads configuration set file // /Configuration/{clientId}/{Config name} // POST: Uploads configuration file // /Editor/{clientId}/{Config name} // POST: Uploads configuration file if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 3) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var client = await configClientService.GetClientOrDefault(pathParams[1]); if (!context.ChallengeClientConfigurator(options, client, httpResponseFactory)) { return; } if (pathParams[0].Equals("Configuration", StringComparison.OrdinalIgnoreCase)) { await HandleUploadConfiguration(context, pathParams[2], client); } else if (pathParams[0].Equals("ConfigurationSet", StringComparison.OrdinalIgnoreCase)) { await HandleUploadConfigurationSet(context, pathParams[2], client); } else if (pathParams[0].Equals("Editor", StringComparison.OrdinalIgnoreCase)) { await HandleUploadToEditor(context, pathParams[2], client); } else { httpResponseFactory.BuildNotFoundStatusResponse(context); } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // /{ Client Id}/{ config name} // GET: Gets Config model for editor // POST: Sets Config from editor model 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; } switch (context.Request.Method) { case "GET": await HandleGetRequest(context, client, pathParams[1]); break; case "POST": await HandlePostRequest(context, client, pathParams[1]); break; default: httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } return; }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (context.Request.Method != "GET") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); return; } var permissions = GetPermissionFromPrincipal(context.User, options); var pathParams = context.ToPathParams(); if (pathParams.Length == 0) { await httpResponseFactory.BuildJsonResponse(context, permissions); } else { var client = await clientService.GetClientOrDefault(pathParams[0]); var clientPermission = MapToClientPermission(permissions, client); await httpResponseFactory.BuildJsonResponse(context, clientPermission); } }
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)); }