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));
            }
        }
        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;
        }
Esempio n. 3
0
        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());
            }
        }
Esempio n. 4
0
        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;
            }
            }
        }
Esempio n. 5
0
        private async Task HandleEmptyPath(HttpContext context)
        {
            switch (context.Request.Method)
            {
            case "GET":
                await httpResponseFactory.BuildJsonResponse(context, await configurationClientService.GetGroups());

                break;

            case "POST":
                await HandleGroupSaveRequest(context);

                break;

            default:
                httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context);
                break;
            }
        }
        private async Task HandleGetRequest(HttpContext context, ConfigurationClient client, string configType)
        {
            var configInstance = await configInstanceRouter.GetConfigInstanceOrDefault(client, configType);

            if (configInstance == null)
            {
                httpResponseFactory.BuildNotFoundStatusResponse(context);
            }
            else
            {
                await httpResponseFactory.BuildJsonResponse(context, configurationEditModelMapper.MapToEditConfig(configInstance, GetConfigurationModel(configInstance)));
            }
        }
        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);
            }
        }
Esempio n. 8
0
        private async Task GetResourceCatalogue(HttpContext context, ConfigurationIdentity clientIdentity, ConfigServerOptions options)
        {
            if (context.Request.Method != "GET")
            {
                httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context);
                return;
            }
            if (!context.ChallengeClientConfigurator(options, clientIdentity.Client, httpResponseFactory))
            {
                return;
            }
            var clientResourceCatalogue = await resourceStore.GetResourceCatalogue(clientIdentity);

            await httpResponseFactory.BuildJsonResponse(context, clientResourceCatalogue);
        }
Esempio n. 9
0
        private async Task HandleUploadToEditor(HttpContext context, string configName, ConfigurationClient client)
        {
            var configModel = configCollection.SelectMany(s => s.Configs).SingleOrDefault(c => c.Type.Name.Equals(configName, StringComparison.OrdinalIgnoreCase));

            if (configModel == null)
            {
                httpResponseFactory.BuildNotFoundStatusResponse(context);
                return;
            }
            var json = await context.ReadBodyTextAsync();

            var result = uploadToEditorModelMapper.MapUploadToEditModel(json, BuildIdentity(client), configModel);
            await httpResponseFactory.BuildJsonResponse(context, result);

            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;
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        private async Task HandleGetSnapshotForGroup(HttpContext context, string[] pathParams, ConfigServerOptions options)
        {
            if (context.Request.Method != "GET")
            {
                httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context);
                return;
            }

            if (pathParams[0].Equals("group", StringComparison.OrdinalIgnoreCase))
            {
                var info = await snapShotRepository.GetSnapshots();

                await httpResponseFactory.BuildJsonResponse(context, info.Where(w => string.Equals(w.GroupId, pathParams[1], StringComparison.OrdinalIgnoreCase)));

                return;
            }

            httpResponseFactory.BuildNotFoundStatusResponse(context);
        }