예제 #1
0
        public Task GetSettings()
        {
            ConfigurationEntryScope?scope = null;
            var scopeAsString             = GetStringQueryString("scope", required: false);

            if (scopeAsString != null)
            {
                if (Enum.TryParse <ConfigurationEntryScope>(scopeAsString, ignoreCase: true, out var value) == false)
                {
                    throw new BadRequestException($"Could not parse '{scopeAsString}' to a valid configuration entry scope.");
                }

                scope = value;
            }

            var feature = HttpContext.Features.Get <IHttpAuthenticationFeature>() as RavenServer.AuthenticateConnection;
            var status  = feature?.Status ?? RavenServer.AuthenticationStatus.ClusterAdmin;

            DatabaseRecord databaseRecord;

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                var dbId = Constants.Documents.Prefix + Database.Name;
                using (context.OpenReadTransaction())
                    using (var dbDoc = ServerStore.Cluster.Read(context, dbId, out long etag))
                    {
                        if (dbDoc == null)
                        {
                            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                            return(Task.CompletedTask);
                        }

                        databaseRecord = JsonDeserializationCluster.DatabaseRecord(dbDoc);
                    }
            }

            var settingsResult = new SettingsResult();

            foreach (var configurationEntryMetadata in RavenConfiguration.AllConfigurationEntries.Value)
            {
                if (scope.HasValue && scope != configurationEntryMetadata.Scope)
                {
                    continue;
                }

                var entry = new ConfigurationEntryDatabaseValue(Database.Configuration, databaseRecord, configurationEntryMetadata, status);
                settingsResult.Settings.Add(entry);
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, settingsResult.ToJson());
                }
            }

            return(Task.CompletedTask);
        }
        public Task GetSettings()
        {
            ConfigurationEntryScope?scope = null;
            var scopeAsString             = GetStringQueryString("scope", required: false);

            if (scopeAsString != null)
            {
                if (Enum.TryParse <ConfigurationEntryScope>(scopeAsString, ignoreCase: true, out var value) == false)
                {
                    throw new BadRequestException($"Could not parse '{scopeAsString}' to a valid configuration entry scope.");
                }

                scope = value;
            }

            var feature = HttpContext.Features.Get <IHttpAuthenticationFeature>() as RavenServer.AuthenticateConnection;
            var status  = feature?.Status ?? RavenServer.AuthenticationStatus.ClusterAdmin;

            var settingsResult = new SettingsResult();

            foreach (var configurationEntryMetadata in RavenConfiguration.AllConfigurationEntries.Value)
            {
                if (scope.HasValue && scope != configurationEntryMetadata.Scope)
                {
                    continue;
                }

                var entry = new ConfigurationEntryServerValue(Server.Configuration.Settings, configurationEntryMetadata, status);
                settingsResult.Settings.Add(entry);
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, settingsResult.ToJson());
                }
            }

            return(Task.CompletedTask);
        }