Exemplo n.º 1
0
        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);
        }
        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;
        }
Exemplo n.º 3
0
        private async Task HandleUploadConfigurationSet(HttpContext context, string configSetName, ConfigurationClient client)
        {
            var configSet = configCollection.SingleOrDefault(c => configSetName.Equals(c.ConfigSetType.Name, StringComparison.OrdinalIgnoreCase));

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

            var result = await commandBus.SubmitAsync(new UpdateConfigurationSetFromJsonUploadCommand(BuildIdentity(client), configSet.ConfigSetType, json));

            await httpResponseFactory.BuildResponseFromCommandResult(context, result);

            return;
        }