-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Allow to restrict namespace prefix (#188003)
- Loading branch information
Showing
34 changed files
with
899 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
x-pack/plugins/fleet/server/routes/settings/settings_handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
|
||
import type { | ||
FleetRequestHandler, | ||
PutSettingsRequestSchema, | ||
PutSpaceSettingsRequestSchema, | ||
} from '../../types'; | ||
import { defaultFleetErrorHandler } from '../../errors'; | ||
import { settingsService, agentPolicyService, appContextService } from '../../services'; | ||
import { getSpaceSettings, saveSpaceSettings } from '../../services/spaces/space_settings'; | ||
|
||
export const getSpaceSettingsHandler: FleetRequestHandler = async (context, request, response) => { | ||
try { | ||
const soClient = (await context.fleet).internalSoClient; | ||
const settings = await getSpaceSettings(soClient.getCurrentNamespace()); | ||
const body = { | ||
item: settings, | ||
}; | ||
return response.ok({ body }); | ||
} catch (error) { | ||
return defaultFleetErrorHandler({ error, response }); | ||
} | ||
}; | ||
|
||
export const putSpaceSettingsHandler: FleetRequestHandler< | ||
undefined, | ||
undefined, | ||
TypeOf<typeof PutSpaceSettingsRequestSchema.body> | ||
> = async (context, request, response) => { | ||
try { | ||
const soClient = (await context.fleet).internalSoClient; | ||
await saveSpaceSettings({ | ||
settings: { | ||
allowed_namespace_prefixes: request.body.allowed_namespace_prefixes, | ||
}, | ||
spaceId: soClient.getCurrentNamespace(), | ||
}); | ||
const settings = await settingsService.getSettings(soClient); | ||
const body = { | ||
item: settings, | ||
}; | ||
return response.ok({ body }); | ||
} catch (error) { | ||
return defaultFleetErrorHandler({ error, response }); | ||
} | ||
}; | ||
|
||
export const getSettingsHandler: FleetRequestHandler = async (context, request, response) => { | ||
const soClient = (await context.fleet).internalSoClient; | ||
|
||
try { | ||
const settings = await settingsService.getSettings(soClient); | ||
const body = { | ||
item: settings, | ||
}; | ||
return response.ok({ body }); | ||
} catch (error) { | ||
if (error.isBoom && error.output.statusCode === 404) { | ||
return response.notFound({ | ||
body: { message: `Settings not found` }, | ||
}); | ||
} | ||
|
||
return defaultFleetErrorHandler({ error, response }); | ||
} | ||
}; | ||
|
||
export const putSettingsHandler: FleetRequestHandler< | ||
undefined, | ||
undefined, | ||
TypeOf<typeof PutSettingsRequestSchema.body> | ||
> = async (context, request, response) => { | ||
const soClient = (await context.fleet).internalSoClient; | ||
const esClient = (await context.core).elasticsearch.client.asInternalUser; | ||
const user = appContextService.getSecurityCore().authc.getCurrentUser(request) || undefined; | ||
|
||
try { | ||
const settings = await settingsService.saveSettings(soClient, request.body); | ||
await agentPolicyService.bumpAllAgentPolicies(esClient, { user }); | ||
const body = { | ||
item: settings, | ||
}; | ||
return response.ok({ body }); | ||
} catch (error) { | ||
if (error.isBoom && error.output.statusCode === 404) { | ||
return response.notFound({ | ||
body: { message: `Settings not found` }, | ||
}); | ||
} | ||
|
||
return defaultFleetErrorHandler({ error, response }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.