[Fleet] Remove preconfiguration API route (#147199)

This commit is contained in:
Nicolas Chaulet 2022-12-07 12:53:31 -05:00 committed by GitHub
parent 42319a79b3
commit 29d274576b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 3 additions and 615 deletions

View file

@ -175,7 +175,6 @@ export const INSTALL_SCRIPT_API_ROUTES = `${API_ROOT}/install/{osType}`;
// Policy preconfig API routes
export const PRECONFIGURATION_API_ROUTES = {
UPDATE_PATTERN: `${API_ROOT}/setup/preconfiguration`,
RESET_PATTERN: `${INTERNAL_ROOT}/reset_preconfigured_agent_policies`,
RESET_ONE_PATTERN: `${INTERNAL_ROOT}/reset_preconfigured_agent_policies/{agentPolicyId}`,
};

View file

@ -59,76 +59,6 @@
]
}
},
"/setup/preconfiguration": {
"put": {
"summary": "Preconfiguration",
"operationId": "put-preconfiguration",
"tags": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"agentPolicies": {
"type": "object",
"items": {}
},
"packages": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"version": {
"type": "string"
}
}
}
}
}
}
}
}
},
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"body": {
"type": "object",
"properties": {
"agentPolicies": {
"$ref": "#/components/schemas/preconfigured_agent_policies"
},
"packages": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"version": {
"type": "string"
}
},
"required": [
"name",
"version"
]
}
}
}
}
}
}
}
}
}
},
"/settings": {
"get": {
"summary": "Settings",
@ -4496,141 +4426,6 @@
"nonFatalErrors"
]
},
"preconfigured_agent_policies": {
"title": "Preconfigured agent policies",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"is_managed": {
"type": "string"
},
"unenroll_timeout": {
"type": "number"
},
"monitoring_enabled": {
"type": "array",
"items": {
"type": "string",
"enum": [
"logs",
"metrics"
]
}
},
"namespace": {
"type": "string"
},
"id": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"is_default": {
"type": "boolean",
"deprecated": true
},
"is_default_fleet_server": {
"type": "boolean",
"deprecated": true
},
"has_fleet_server": {
"type": "boolean"
},
"data_output_id": {
"type": "string"
},
"monitoring_output_id": {
"type": "string"
},
"package_policies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"name": {
"type": "string"
},
"package": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"description": {
"type": "string"
},
"namespace": {
"type": "string"
},
"inputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"keep_enabled": {
"type": "boolean"
},
"vars": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {
"type": "string"
},
"frozen": {
"type": "boolean"
}
}
}
},
"required": [
"type"
]
}
}
}
}
}
},
"required": [
"name",
"namespace",
"package_policies"
]
},
"settings": {
"title": "Settings",
"type": "object",

View file

@ -36,50 +36,6 @@ paths:
operationId: setup
parameters:
- $ref: '#/components/parameters/kbn_xsrf'
/setup/preconfiguration:
put:
summary: Preconfiguration
operationId: put-preconfiguration
tags: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
agentPolicies:
type: object
items: {}
packages:
type: object
properties:
name:
type: string
version:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
body:
type: object
properties:
agentPolicies:
$ref: '#/components/schemas/preconfigured_agent_policies'
packages:
type: object
properties:
name:
type: string
version:
type: string
required:
- name
- version
/settings:
get:
summary: Settings
@ -2797,91 +2753,6 @@ components:
required:
- isInitialized
- nonFatalErrors
preconfigured_agent_policies:
title: Preconfigured agent policies
type: object
properties:
name:
type: string
description:
type: string
is_managed:
type: string
unenroll_timeout:
type: number
monitoring_enabled:
type: array
items:
type: string
enum:
- logs
- metrics
namespace:
type: string
id:
oneOf:
- type: string
- type: number
is_default:
type: boolean
deprecated: true
is_default_fleet_server:
type: boolean
deprecated: true
has_fleet_server:
type: boolean
data_output_id:
type: string
monitoring_output_id:
type: string
package_policies:
type: array
items:
type: object
properties:
id:
oneOf:
- type: string
- type: number
name:
type: string
package:
type: object
properties:
name:
type: string
description:
type: string
namespace:
type: string
inputs:
type: array
items:
type: object
properties:
type:
type: string
enabled:
type: boolean
keep_enabled:
type: boolean
vars:
type: object
properties:
name:
type: string
type:
type: string
value:
type: string
frozen:
type: boolean
required:
- type
required:
- name
- namespace
- package_policies
settings:
title: Settings
type: object

View file

@ -1,26 +0,0 @@
title: Preconfiguration Error
type: object
properties:
package:
type: object
properties:
name:
type: string
version:
type: string
agentPolicy:
type: object
properties:
name:
type: string
error:
type: object
properties:
name:
type: string
message:
type: string
stack:
type: string
required:
- error

View file

@ -1,84 +0,0 @@
title: Preconfigured agent policies
type: object
properties:
name:
type: string
description:
type: string
is_managed:
type: string
unenroll_timeout:
type: number
monitoring_enabled:
type: array
items:
type: string
enum:
- 'logs'
- 'metrics'
namespace:
type: string
id:
oneOf:
- type: string
- type: number
is_default:
type: boolean
deprecated: true
is_default_fleet_server:
type: boolean
deprecated: true
has_fleet_server:
type: boolean
data_output_id:
type: string
monitoring_output_id:
type: string
package_policies:
type: array
items:
type: object
properties:
id:
oneOf:
- type: string
- type: number
name:
type: string
package:
type: object
properties:
name:
type: string
description:
type: string
namespace:
type: string
inputs:
type: array
items:
type: object
properties:
type:
type: string
enabled:
type: boolean
keep_enabled:
type: boolean
vars:
type: object
properties:
name:
type: string
type:
type: string
value:
type: string
frozen:
type: boolean
required:
- type
required:
- name
- namespace
- package_policies

View file

@ -16,8 +16,6 @@ paths:
# plugin-wide endpoint(s)
/setup:
$ref: paths/setup.yaml
/setup/preconfiguration:
$ref: paths/setup_preconfiguration.yaml
/settings:
$ref: paths/settings.yaml
# App endpoints

View file

@ -1,43 +0,0 @@
put:
summary: Preconfiguration
operationId: put-preconfiguration
tags: []
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
agentPolicies:
type: object
items: {}
packages:
type: object
properties:
name:
type: string
version:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
body:
type: object
properties:
agentPolicies:
$ref: ../components/schemas/preconfigured_agent_policies.yaml
packages:
type: object
properties:
name:
type: string
version:
type: string
required:
- name
- version

View file

@ -7,51 +7,11 @@
import type { TypeOf } from '@kbn/config-schema';
import type { PreconfiguredAgentPolicy } from '../../../common/types';
import type { FleetRequestHandler } from '../../types';
import type {
PutPreconfigurationSchema,
PostResetOnePreconfiguredAgentPoliciesSchema,
} from '../../types';
import type { PostResetOnePreconfiguredAgentPoliciesSchema } from '../../types';
import { defaultFleetErrorHandler } from '../../errors';
import {
ensurePreconfiguredPackagesAndPolicies,
outputService,
downloadSourceService,
} from '../../services';
import { resetPreconfiguredAgentPolicies } from '../../services/preconfiguration/reset_agent_policies';
export const updatePreconfigurationHandler: FleetRequestHandler<
undefined,
undefined,
TypeOf<typeof PutPreconfigurationSchema.body>
> = async (context, request, response) => {
const coreContext = await context.core;
const fleetContext = await context.fleet;
const soClient = coreContext.savedObjects.client;
const esClient = coreContext.elasticsearch.client.asInternalUser;
const defaultOutput = await outputService.ensureDefaultOutput(soClient);
const defaultDownloadSource = await downloadSourceService.ensureDefault(soClient);
const spaceId = fleetContext.spaceId;
const { agentPolicies, packages } = request.body;
try {
const body = await ensurePreconfiguredPackagesAndPolicies(
soClient,
esClient,
(agentPolicies as PreconfiguredAgentPolicy[]) ?? [],
packages ?? [],
defaultOutput,
defaultDownloadSource,
spaceId
);
return response.ok({ body });
} catch (error) {
return defaultFleetErrorHandler({ error, response });
}
};
export const resetOnePreconfigurationHandler: FleetRequestHandler<
TypeOf<typeof PostResetOnePreconfiguredAgentPoliciesSchema.params>,
undefined,

View file

@ -6,17 +6,10 @@
*/
import { PRECONFIGURATION_API_ROUTES } from '../../constants';
import {
PutPreconfigurationSchema,
PostResetOnePreconfiguredAgentPoliciesSchema,
} from '../../types';
import { PostResetOnePreconfiguredAgentPoliciesSchema } from '../../types';
import type { FleetAuthzRouter } from '../security';
import {
updatePreconfigurationHandler,
resetPreconfigurationHandler,
resetOnePreconfigurationHandler,
} from './handler';
import { resetPreconfigurationHandler, resetOnePreconfigurationHandler } from './handler';
export const registerRoutes = (router: FleetAuthzRouter) => {
router.post(
@ -39,15 +32,4 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
},
resetOnePreconfigurationHandler
);
router.put(
{
path: PRECONFIGURATION_API_ROUTES.UPDATE_PATTERN,
validate: PutPreconfigurationSchema,
fleetAuthz: {
fleet: { all: true },
},
},
updatePreconfigurationHandler
);
};

View file

@ -41,9 +41,6 @@ export default function ({ loadTestFile, getService }) {
// Settings
loadTestFile(require.resolve('./settings'));
// Preconfiguration
loadTestFile(require.resolve('./preconfiguration'));
// Service tokens
loadTestFile(require.resolve('./service_tokens'));

View file

@ -1,12 +0,0 @@
/*
* 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.
*/
export default function loadTests({ loadTestFile }) {
describe('Preconfiguration Endpoints', () => {
loadTestFile(require.resolve('./preconfiguration'));
});
}

View file

@ -1,49 +0,0 @@
/*
* 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 expect from '@kbn/expect';
import { PRECONFIGURATION_API_ROUTES } from '@kbn/fleet-plugin/common/constants';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
// use function () {} and not () => {} here
// because `this` has to point to the Mocha context
// see https://mochajs.org/#arrow-functions
describe('Preconfiguration', async () => {
skipIfNoDockerRegistry(providerContext);
before(async () => {
await getService('kibanaServer').savedObjects.cleanStandardList();
await getService('esArchiver').load(
'x-pack/test/functional/es_archives/fleet/empty_fleet_server'
);
});
after(async () => {
await getService('esArchiver').unload(
'x-pack/test/functional/es_archives/fleet/empty_fleet_server'
);
await getService('kibanaServer').savedObjects.cleanStandardList();
});
// Basic health check for the API; functionality is covered by the unit tests
it('should succeed with an empty payload', async () => {
const { body } = await supertest
.put(PRECONFIGURATION_API_ROUTES.UPDATE_PATTERN)
.set('kbn-xsrf', 'xxxx')
.send({})
.expect(200);
expect(body.nonFatalErrors).to.eql([]);
});
});
}