Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Make API responses consistent #119494

Merged
merged 34 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
36d275b
make apis consistent
juliaElastic Nov 23, 2021
83275b3
UI and test fixes
juliaElastic Nov 23, 2021
bc0662f
test fixes
juliaElastic Nov 24, 2021
174476c
Merge branch 'main' into make-api-consistent
kibanamachine Nov 29, 2021
b0d66b8
Merge branch 'main' into make-api-consistent
kibanamachine Nov 30, 2021
d04bbc9
fixed test
juliaElastic Nov 30, 2021
d655d66
fix tests
juliaElastic Nov 30, 2021
ecf57de
fix test
juliaElastic Dec 1, 2021
a9cce4c
removed deprecated shared_id from openapi spec
juliaElastic Dec 1, 2021
fb3de3b
added back list prop as deprecated
juliaElastic Dec 1, 2021
f375d17
Merge branch 'main' into make-api-consistent
kibanamachine Dec 2, 2021
117ba90
renamed apis with hyphens
juliaElastic Dec 2, 2021
5ffacf8
openapi update
juliaElastic Dec 2, 2021
bda9ad2
fix checks
juliaElastic Dec 3, 2021
9fd739d
Merge branch 'main' into make-api-consistent
kibanamachine Dec 3, 2021
ff7690f
fix test
juliaElastic Dec 3, 2021
9b3d478
renamed epm api path and response
juliaElastic Dec 3, 2021
edad68b
fix tests
juliaElastic Dec 3, 2021
7c1e098
fix ml
juliaElastic Dec 3, 2021
34200ce
Merge branch 'main' into make-api-consistent
kibanamachine Dec 6, 2021
ab7f561
moved splitPkgKey
juliaElastic Dec 6, 2021
be085f4
fixed edit package policy page
juliaElastic Dec 6, 2021
62473c6
fixed storybook
juliaElastic Dec 6, 2021
e73c8ce
Merge branch 'main' into make-api-consistent
juliaElastic Dec 6, 2021
127eeed
fix prettier after conflict
juliaElastic Dec 6, 2021
877b040
fix tests
juliaElastic Dec 6, 2021
839d545
fix tests
juliaElastic Dec 6, 2021
d7930e7
fix tests
juliaElastic Dec 6, 2021
ad53433
fix test
juliaElastic Dec 7, 2021
1c60944
fix test
juliaElastic Dec 7, 2021
154322e
added back semver validation
juliaElastic Dec 7, 2021
9aa9a61
fix test
juliaElastic Dec 7, 2021
023af3e
pkgVersion optional
juliaElastic Dec 7, 2021
d0d095d
fix tests
juliaElastic Dec 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
"schema": {
"type": "object",
"properties": {
"list": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/agent"
Expand All @@ -512,7 +512,7 @@
}
},
"required": [
"list",
"items",
"total",
"page",
"perPage"
Expand Down Expand Up @@ -1305,7 +1305,7 @@
"schema": {
"type": "object",
"properties": {
"list": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/enrollment_api_key"
Expand All @@ -1322,7 +1322,7 @@
}
},
"required": [
"list",
"items",
"page",
"perPage",
"total"
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ paths:
schema:
type: object
properties:
list:
items:
type: array
items:
$ref: '#/components/schemas/agent'
Expand All @@ -319,7 +319,7 @@ paths:
perPage:
type: number
required:
- list
- items
- total
- page
- perPage
Expand Down Expand Up @@ -795,7 +795,7 @@ paths:
schema:
type: object
properties:
list:
items:
type: array
items:
$ref: '#/components/schemas/enrollment_api_key'
Expand All @@ -806,7 +806,7 @@ paths:
total:
type: number
required:
- list
- items
- page
- perPage
- total
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/common/openapi/paths/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ get:
schema:
type: object
properties:
list:
items:
type: array
items:
$ref: ../components/schemas/agent.yaml
Expand All @@ -20,7 +20,7 @@ get:
perPage:
type: number
required:
- list
- items
- total
- page
- perPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ get:
schema:
type: object
properties:
list:
items:
type: array
items:
$ref: ../components/schemas/enrollment_api_key.yaml
Expand All @@ -20,7 +20,7 @@ get:
total:
type: number
required:
- list
- items
- page
- perPage
- total
Expand Down
13 changes: 4 additions & 9 deletions x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@

import type { Agent, AgentAction, NewAgentAction } from '../models';

import type { ListResult, ListWithKuery } from './common';

export interface GetAgentsRequest {
query: {
page: number;
perPage: number;
kuery?: string;
query: ListWithKuery & {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a slight difference here as page and perPage are optional in ListWithKuery, hopefully not a problem. I feel it's still better to use the common interface.

showInactive: boolean;
showUpgradeable?: boolean;
};
}

export interface GetAgentsResponse {
list: Agent[];
total: number;
export interface GetAgentsResponse extends ListResult<Agent> {
totalInactive: number;
page: number;
perPage: number;
}

export interface GetOneAgentRequest {
Expand Down
9 changes: 2 additions & 7 deletions x-pack/plugins/fleet/common/types/rest_spec/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { AgentPolicy, NewAgentPolicy, FullAgentPolicy } from '../models';

import type { ListWithKuery } from './common';
import type { ListResult, ListWithKuery } from './common';

export interface GetAgentPoliciesRequest {
query: ListWithKuery & {
Expand All @@ -17,12 +17,7 @@ export interface GetAgentPoliciesRequest {

export type GetAgentPoliciesResponseItem = AgentPolicy & { agents?: number };

export interface GetAgentPoliciesResponse {
items: GetAgentPoliciesResponseItem[];
total: number;
page: number;
perPage: number;
}
export type GetAgentPoliciesResponse = ListResult<GetAgentPoliciesResponseItem>;

export interface GetOneAgentPolicyRequest {
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@

import type { EnrollmentAPIKey } from '../models';

import type { ListResult, ListWithKuery } from './common';

export interface GetEnrollmentAPIKeysRequest {
query: {
page: number;
perPage: number;
kuery?: string;
};
query: ListWithKuery;
}

export interface GetEnrollmentAPIKeysResponse {
list: EnrollmentAPIKey[];
total: number;
page: number;
perPage: number;
}
export type GetEnrollmentAPIKeysResponse = ListResult<EnrollmentAPIKey>;

export interface GetOneEnrollmentAPIKeyRequest {
params: {
Expand Down
9 changes: 3 additions & 6 deletions x-pack/plugins/fleet/common/types/rest_spec/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import type { Output } from '../models';

import type { ListResult } from './common';

export interface GetOneOutputResponse {
item: Output;
}
Expand Down Expand Up @@ -53,9 +55,4 @@ export interface PutOutputResponse {
item: Output;
}

export interface GetOutputsResponse {
items: Output[];
total: number;
page: number;
perPage: number;
}
export type GetOutputsResponse = ListResult<Output>;
15 changes: 4 additions & 11 deletions x-pack/plugins/fleet/common/types/rest_spec/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ import type {
PackagePolicyPackage,
} from '../models';

import type { ListResult, ListWithKuery } from './common';

export interface GetPackagePoliciesRequest {
query: {
page: number;
perPage: number;
kuery?: string;
};
query: ListWithKuery;
}

export interface GetPackagePoliciesResponse {
items: PackagePolicy[];
total: number;
page: number;
perPage: number;
}
export type GetPackagePoliciesResponse = ListResult<PackagePolicy>;

export interface GetOnePackagePolicyRequest {
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
inactive: agentsRequest.data.totalInactive,
});

setAgents(agentsRequest.data.list);
setAgents(agentsRequest.data.items);
setTotalAgents(agentsRequest.data.total);
setTotalInactiveAgents(agentsRequest.data.totalInactive);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const FleetServerUpgradeModal: React.FunctionComponent<Props> = ({ onClos
throw res.error;
}

for (const agent of res.data?.list ?? []) {
for (const agent of res.data?.items ?? []) {
if (!agent.policy_id || agentPoliciesAlreadyChecked[agent.policy_id]) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => {

const total = enrollmentAPIKeysRequest?.data?.total ?? 0;
const rowItems =
enrollmentAPIKeysRequest?.data?.list.filter((enrollmentKey) => {
enrollmentAPIKeysRequest?.data?.items.filter((enrollmentKey) => {
if (!agentPolicies.length || !enrollmentKey.policy_id) return false;
const agentPolicy = agentPoliciesById[enrollmentKey.policy_id];
return !agentPolicy?.is_managed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const AdvancedAgentAuthenticationSettings: FunctionComponent<Props> = ({
onKeyChange,
}) => {
const { notifications } = useStartServices();
const [enrollmentAPIKeys, setEnrollmentAPIKeys] = useState<GetEnrollmentAPIKeysResponse['list']>(
const [enrollmentAPIKeys, setEnrollmentAPIKeys] = useState<GetEnrollmentAPIKeysResponse['items']>(
[]
);

Expand Down Expand Up @@ -143,7 +143,7 @@ export const AdvancedAgentAuthenticationSettings: FunctionComponent<Props> = ({
throw new Error('No data while fetching enrollment API keys');
}

const enrollmentAPIKeysResponse = res.data.list.filter(
const enrollmentAPIKeysResponse = res.data.items.filter(
(key) => key.policy_id === agentPolicyId && key.active === true
);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/routes/agent/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const getAgentsHandler: RequestHandler<
: 0;

const body: GetAgentsResponse = {
list: agents,
items: agents,
total,
totalInactive,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const getEnrollmentApiKeysHandler: RequestHandler<
perPage: request.query.perPage,
kuery: request.query.kuery,
});
const body: GetEnrollmentAPIKeysResponse = { list: items, total, page, perPage };
const body: GetEnrollmentAPIKeysResponse = { items, total, page, perPage };

return response.ok({ body });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const endpointListApiPathHandlerMocks = ({
[INGEST_API_FLEET_AGENTS]: (): GetAgentsResponse => {
return {
total: totalAgentsUsingEndpoint,
list: [],
items: [],
totalInactive: 0,
page: 1,
perPage: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function (providerContext: FtrProviderContext) {
async function getEnrollmentKeyForPolicyId(policyId: string) {
const listRes = await supertest.get(`/api/fleet/enrollment-api-keys`).expect(200);

const key = listRes.body.list.find(
const key = listRes.body.items.find(
(item: { policy_id: string; id: string }) => item.policy_id === policyId
);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/fleet_api_integration/apis/agents/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function ({ getService }: FtrProviderContext) {
.expect(200);

expect(apiResponse.total).to.eql(1);
const agent = apiResponse.list[0];
const agent = apiResponse.items[0];
expect(agent.access_api_key_id).to.eql('api-key-2');
});
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/fleet_api_integration/apis/epm/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function (providerContext: FtrProviderContext) {
.set('Authorization', `Bearer ${token.value}`)
.set('kbn-xsrf', 'xxx')
.expect(200);
const enrollmentApiKeyId = response.body.list[0].id;
const enrollmentApiKeyId = response.body.items[0].id;
await supertestWithoutAuth
.get(`/api/fleet/enrollment-api-keys/${enrollmentApiKeyId}`)
.set('Authorization', `Bearer ${token.value}`)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/fleet_cypress/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AgentManager extends Manager {
this.params.kibanaUrl + '/api/fleet/enrollment-api-keys',
this.requestOptions
);
const policy = apiKeys.list[1];
const policy = apiKeys.items[1];

this.log.info('Running the agent');

Expand Down Expand Up @@ -87,7 +87,7 @@ export class AgentManager extends Manager {
`${this.params.kibanaUrl}/api/fleet/agents`,
this.requestOptions
);
done = agents.list[0]?.status === 'online';
done = agents.items[0]?.status === 'online';
if (++retries > 12) {
this.log.error('Giving up on enrolling the agent after a minute');
throw new Error('Agent timed out while coming online');
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/osquery_cypress/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class AgentManager extends Manager {
this.params.kibanaUrl + '/api/fleet/enrollment-api-keys',
this.requestOptions
);
const policy = apiKeys.list[1];
const policy = apiKeys.items[1];

this.log.info('Enrolling the agent');
const args = [
Expand Down Expand Up @@ -100,7 +100,7 @@ export class AgentManager extends Manager {
`${this.params.kibanaUrl}/api/fleet/agents`,
this.requestOptions
);
done = agents.list[0]?.status === 'online';
done = agents.items[0]?.status === 'online';
if (++retries > 12) {
this.log.error('Giving up on enrolling the agent after a minute');
throw new Error('Agent timed out while coming online');
Expand Down