Exemplo n.º 1
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());
            }
        }
        public async Task <bool> TryHandle(HttpContext context)
        {
            var routePath = context.Request.Path;

            if (string.IsNullOrWhiteSpace(routePath))
            {
                await responseFactory.BuildResponse(context, GetConfigurationSetSummaries());

                return(true);
            }
            PathString remainingPath;

            if (routePath.StartsWithSegments("/Model", out remainingPath))
            {
                var queryResult = configCollection.TryMatchPath(c => c.ConfigSetType.Name, remainingPath);
                if (queryResult.HasResult)
                {
                    await responseFactory.BuildResponse(context, modelPayloadMapper.Map(queryResult.QueryResult));
                }
                return(queryResult.HasResult);
            }
            if (routePath.StartsWithSegments("/Value", out remainingPath))
            {
                var configInstance = await configInstanceRouter.GetConfigInstanceOrDefault(remainingPath);

                if (configInstance == null || !(context.Request.Method == "GET" || context.Request.Method == "POST"))
                {
                    return(false);
                }
                await HandleValueRequest(context, configInstance);

                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public async Task <bool> TryHandle(HttpContext context)
        {
            var config = await router.GetConfigInstanceOrDefault(context.Request.Path);

            if (config == null)
            {
                return(false);
            }
            await responseFactory.BuildResponse(context, config.GetConfiguration());

            return(true);
        }
        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)));
            }
        }
Exemplo n.º 5
0
        public async Task <bool> TryHandle(HttpContext context)
        {
            var routePath = context.Request.Path;

            if (context.Request.Method != "POST")
            {
                return(false);
            }
            PathString remainingPath;

            if (routePath.StartsWithSegments("/Configuration", out remainingPath))
            {
                var configInstance = await configInstanceRouter.GetConfigInstanceOrDefault(remainingPath);

                if (configInstance == null)
                {
                    return(false);
                }
                await HandleUploadRequest(context, configInstance);

                return(true);
            }
            if (routePath.StartsWithSegments("/ConfigurationSet", out remainingPath))
            {
                var clients = await configRepository.GetClientsAsync();

                var clientsResult = clients.TryMatchPath(c => c.ClientId, remainingPath);
                if (!clientsResult.HasResult)
                {
                    return(false);
                }
                var configSetResult = configCollection.TryMatchPath(c => c.ConfigSetType.Name, clientsResult.RemainingPath);
                if (!configSetResult.HasResult)
                {
                    return(false);
                }
                await HandleUploadRequest(context, clientsResult.QueryResult.ClientId, configSetResult.QueryResult);

                return(true);
            }
            return(false);
        }