private async Task HandleSingleParam(HttpContext context, ConfigurationIdentity clientIdentity) { switch (context.Request.Method) { case "GET": { var clientResourceCatalogue = await archive.GetArchiveConfigCatalogue(clientIdentity); await httpResponseFactory.BuildJsonResponse(context, clientResourceCatalogue); break; } case "DELETE": { if (context.Request.Query.TryGetValue("before", out var pram) && DateTime.TryParse(pram, out var dateParam)) { await archive.DeleteOldArchiveConfigs(dateParam, clientIdentity); httpResponseFactory.BuildNoContentResponse(context); break; } httpResponseFactory.BuildNotFoundStatusResponse(context); break; } default: { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } } }
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 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); } }
public Task Handle(HttpContext context, ConfigServerOptions options) { // / POST Save snapshot // /{snapShotId}DELETE: Deletes snapShot // /Group/{clientGroupId} GET: Gets SnapshotIds for clientGroupId // /{snapShotId}/to/{clientId} if (!CheckMethodAndAuthentication(context, options)) { return(Task.FromResult(true)); } var pathParams = context.ToPathParams(); switch (pathParams.Length) { case 0: return(HandleSaveSnapshot(context, options)); case 1: return(HandleDeleteSnapshot(context, pathParams[0], options)); case 2: return(HandleGetSnapshotForGroup(context, pathParams, options)); case 3: return(HandlePushSnapshotToClient(context, pathParams, options)); default: httpResponseFactory.BuildNotFoundStatusResponse(context); return(Task.FromResult(true)); } }
private async Task HandleGroupPath(HttpContext context, string groupId) { var group = await configurationClientService.GetClientGroupOrDefault(groupId); if (group != null) { await httpResponseFactory.BuildJsonResponse(context, group); } else { httpResponseFactory.BuildNotFoundStatusResponse(context); } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { var pathParams = context.ToPathParams(); // /{id} // /{id}/{resource} // /{id}/to/{id} if (!CheckMethodAndAuthentication(context, options, pathParams)) { return; } if (pathParams.Length == 0 || pathParams.Length > 3) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var clientIdentity = await GetIdentityFromPathOrDefault(pathParams[0]); if (clientIdentity == null) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } switch (pathParams.Length) { case 1: await GetResourceCatalogue(context, clientIdentity, options); break; case 2: await HandleTwoParams(context, pathParams, clientIdentity, options); break; case 3: await TransferResource(context, pathParams, clientIdentity, options); break; default: httpResponseFactory.BuildNotFoundStatusResponse(context); break; } }
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 static bool ChallengeClientRead(this HttpContext source, ConfigServerOptions option, ConfigurationClient client, IHttpResponseFactory responseFactory) { if (client == null) { responseFactory.BuildNotFoundStatusResponse(source); return(false); } if (string.IsNullOrWhiteSpace(option.ClientReadClaimType) || string.IsNullOrWhiteSpace(client.ReadClaim)) { return(source.ChallengeAuthentication(option.AllowAnomynousAccess, responseFactory)); } //If we have an expected claim then we do not want to allow anomynous if (!source.ChallengeAuthentication(false, responseFactory)) { return(false); } if (!source.User.HasClaim(c => option.ClientReadClaimType.Equals(c.Type, StringComparison.OrdinalIgnoreCase) && client.ReadClaim.Equals(c.Value, StringComparison.OrdinalIgnoreCase))) { responseFactory.BuildStatusResponse(source, 403); return(false); } return(true); }
public static bool ChallengeClientConfiguratorOrAdmin(this HttpContext source, ConfigServerOptions option, ConfigurationClient client, IHttpResponseFactory responseFactory) { if (client == null) { responseFactory.BuildNotFoundStatusResponse(source); return(false); } if (string.IsNullOrWhiteSpace(option.ClientAdminClaimType) || string.IsNullOrWhiteSpace(option.ClientConfiguratorClaimType) || string.IsNullOrWhiteSpace(client.ConfiguratorClaim)) { return(source.ChallengeAuthentication(option.AllowManagerAnomynousAccess, responseFactory)); } //If we have an expected claim then we do not want to allow anomynous if (!source.ChallengeAuthentication(false, responseFactory)) { return(false); } if (!(source.HasClaim(option.ClientConfiguratorClaimType, client.ConfiguratorClaim) || source.HasClaim(option.ClientAdminClaimType, ConfigServerConstants.AdminClaimValue))) { responseFactory.BuildStatusResponse(source, 403); return(false); } return(true); }
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) { var param = context.ToPathParams(); if (param.Length != 0) { httpResponseFactory.BuildNotFoundStatusResponse(context); } else if (context.Request.Method != "POST") { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); } else { await httpResponseFactory.BuildJsonResponse(context, Guid.NewGuid()); } }
public async Task Handle(HttpContext context, ConfigServerOptions options) { // GET: Gets all configuration set summaries if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length == 0) { await httpResponseFactory.BuildJsonResponse(context, GetConfigurationSetSummaries()); return; } httpResponseFactory.BuildNotFoundStatusResponse(context); return; }
public async Task Handle(HttpContext context, ConfigServerOptions options) { if (!CheckMethodAndAuthentication(context, options)) { return; } var pathParams = context.ToPathParams(); if (pathParams.Length != 0) { httpResponseFactory.BuildNotFoundStatusResponse(context); return; } var tags = registry.Select(model => model.RequiredClientTag).Where(model => model != null).Distinct().OrderBy(o => o.Value); await httpResponseFactory.BuildJsonResponse(context, tags); return; }
private Task HandleNotFound(HttpContext context) { httpResponseFactory.BuildNotFoundStatusResponse(context); return(Task.FromResult(true)); }