Skip to content

Commit

Permalink
settings routes
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Sep 10, 2024
1 parent 8ad1aaf commit b2504a4
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 6 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/server/routes/schema/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const genericErrorResponse = () =>
}
);

export const notFoundResponse = () =>
schema.object({
message: schema.string(),
});

export const internalErrorResponse = () =>
schema.object(
{
Expand Down
165 changes: 160 additions & 5 deletions x-pack/plugins/fleet/server/routes/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';

import { parseExperimentalConfigValue } from '../../../common/experimental_features';
import { API_VERSIONS } from '../../../common/constants';
Expand All @@ -18,6 +19,8 @@ import {
} from '../../types';
import type { FleetConfigType } from '../../config';

import { genericErrorResponse, notFoundResponse } from '../schema/errors';

import { getEnrollmentSettingsHandler } from './enrollment_settings_handler';

import {
Expand All @@ -27,6 +30,36 @@ import {
putSpaceSettingsHandler,
} from './settings_handler';

const spaceSettingsResponse = () =>
schema.object({
item: schema.object({
managed_by: schema.maybe(schema.string()),
allowed_namespace_prefixes: schema.arrayOf(schema.string()),
}),
});

const settingsResponse = () =>
schema.object({
item: schema.object({
has_seen_add_data_notice: schema.maybe(schema.boolean()),
fleet_server_hosts: schema.maybe(schema.arrayOf(schema.string())),
prerelease_integrations_enabled: schema.boolean(),
id: schema.string(),
version: schema.maybe(schema.string()),
preconfigured_fields: schema.maybe(schema.arrayOf(schema.literal('fleet_server_hosts'))),
secret_storage_requirements_met: schema.maybe(schema.boolean()),
output_secret_storage_requirements_met: schema.maybe(schema.boolean()),
use_space_awareness_migration_status: schema.maybe(
schema.oneOf([
schema.literal('pending'),
schema.literal('success'),
schema.literal('error'),
])
),
use_space_awareness_migration_started_at: schema.maybe(schema.string()),
}),
});

export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType) => {
const experimentalFeatures = parseExperimentalConfigValue(config.enableExperimental);
if (experimentalFeatures.useSpaceAwareness) {
Expand All @@ -45,7 +78,14 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: GetSpaceSettingsRequestSchema },
validate: {
request: GetSpaceSettingsRequestSchema,
response: {
200: {
body: spaceSettingsResponse,
},
},
},
},
getSpaceSettingsHandler
);
Expand All @@ -61,7 +101,14 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: PutSpaceSettingsRequestSchema },
validate: {
request: PutSpaceSettingsRequestSchema,
response: {
200: {
body: spaceSettingsResponse,
},
},
},
},
putSpaceSettingsHandler
);
Expand All @@ -74,11 +121,27 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
fleet: { readSettings: true },
},
description: `Get settings`,
options: {
tags: ['Fleet internals'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: GetSettingsRequestSchema },
validate: {
request: GetSettingsRequestSchema,
response: {
200: {
body: settingsResponse,
},
400: {
body: genericErrorResponse,
},
404: {
body: notFoundResponse,
},
},
},
},
getSettingsHandler
);
Expand All @@ -89,11 +152,27 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
fleet: { allSettings: true },
},
description: `Update settings`,
options: {
tags: ['Fleet internals'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: PutSettingsRequestSchema },
validate: {
request: PutSettingsRequestSchema,
response: {
200: {
body: settingsResponse,
},
400: {
body: genericErrorResponse,
},
404: {
body: notFoundResponse,
},
},
},
},
putSettingsHandler
);
Expand All @@ -104,11 +183,87 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
return authz.fleet.addAgents || authz.fleet.addFleetServers;
},
description: `Get enrollment settings`,
options: {
tags: ['Fleet internals'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: GetEnrollmentSettingsRequestSchema },
validate: {
request: GetEnrollmentSettingsRequestSchema,
response: {
200: {
body: () =>
schema.object({
fleet_server: schema.object({
policies: schema.arrayOf(
schema.object({
id: schema.string(),
name: schema.string(),
is_managed: schema.boolean(),
is_default_fleet_server: schema.maybe(schema.boolean()),
has_fleet_server: schema.maybe(schema.boolean()),
fleet_server_host_id: schema.nullable(schema.maybe(schema.string())),
download_source_id: schema.nullable(schema.maybe(schema.string())),
space_ids: schema.maybe(schema.arrayOf(schema.string())),
})
),
has_active: schema.boolean(),
host: schema.maybe(
schema.object({
id: schema.string(),
name: schema.string(),
host_urls: schema.arrayOf(schema.string()),
is_default: schema.boolean(),
is_preconfigured: schema.boolean(),
is_internal: schema.maybe(schema.boolean()),
proxy_id: schema.nullable(schema.maybe(schema.string())),
})
),
host_proxy: schema.maybe(
schema.object({
id: schema.string(),
proxy_headers: schema.maybe(
schema.recordOf(
schema.string(),
schema.oneOf([schema.string(), schema.number(), schema.boolean()])
)
),
name: schema.string(),
url: schema.string(),
certificate_authorities: schema.nullable(schema.maybe(schema.string())),
certificate: schema.nullable(schema.maybe(schema.string())),
certificate_key: schema.nullable(schema.maybe(schema.string())),
is_preconfigured: schema.boolean(),
})
),
}),
download_source: schema.maybe(
schema.object({
id: schema.string(),
name: schema.string(),
host: schema.string(),
is_default: schema.boolean(),
proxy_id: schema.nullable(
schema.maybe(
schema.string({
meta: {
description:
'The ID of the proxy to use for this download source. See the proxies API for more information.',
},
})
)
),
})
),
}),
},
400: {
body: genericErrorResponse,
},
},
},
},
getEnrollmentSettingsHandler
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema } from '@kbn/config-schema';

import type { FleetAuthzRouter } from '../../services/security';

Expand All @@ -27,7 +28,23 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
.addVersion(
{
version: API_VERSIONS.internal.v1,
validate: { request: PostStandaloneAgentAPIKeyRequestSchema },
validate: {
request: PostStandaloneAgentAPIKeyRequestSchema,
response: {
200: {
body: () =>
schema.object({
item: schema.object({
id: schema.string(),
api_key: schema.string(),
name: schema.string(),
encoded: schema.string(),
expiration: schema.maybe(schema.number()),
}),
}),
},
},
},
},
createStandaloneAgentApiKeyHandler
);
Expand Down

0 comments on commit b2504a4

Please sign in to comment.