Skip to content

Commit

Permalink
[Cases] Guardrails getConnectors API (#161282)
Browse files Browse the repository at this point in the history
Connected to #146945

## Summary

| Description  | Limit | Done? | Documented?
| ------------- | ---- | :---: | ---- |
| Total number of supported connectors returned | 1000 |
✅ | Yes |

### Checklist

Delete any items that are not applicable to this PR.

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### Release Notes

The getConnectors API will now limit the number of supported connectors
returned to 1000.
  • Loading branch information
adcoelho authored Jul 7, 2023
1 parent 715a578 commit 2774812
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const MAX_CATEGORY_FILTER_LENGTH = 100 as const;
export const MAX_TAGS_FILTER_LENGTH = 100 as const;
export const MAX_ASSIGNEES_FILTER_LENGTH = 100 as const;
export const MAX_REPORTERS_FILTER_LENGTH = 100 as const;
export const MAX_SUPPORTED_CONNECTORS_RETURNED = 1000 as const;

/**
* Validation
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/docs/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,8 @@
"type": "integer"
}
}
}
},
"maxItems": 1000
},
"examples": {
"findConnectorResponse": {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/docs/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ paths:
type: string
referencedByCount:
type: integer
maxItems: 1000
examples:
findConnectorResponse:
$ref: '#/components/examples/find_connector_response'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ get:
application/json:
schema:
type: array
items:
items:
type: object
properties:
$ref: '../components/schemas/connector_response_properties.yaml'
maxItems: 1000
examples:
findConnectorResponse:
$ref: '../components/examples/find_connector_response.yaml'
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { actionsClientMock } from '@kbn/actions-plugin/server/mocks';
import type { CasesClientArgs } from '../types';
import { getConnectors, get, update } from './client';
import { createCasesClientInternalMock, createCasesClientMockArgs } from '../mocks';
import { MAX_SUPPORTED_CONNECTORS_RETURNED } from '../../../common/constants';

describe('client', () => {
const clientArgs = createCasesClientMockArgs();
Expand Down Expand Up @@ -219,6 +220,15 @@ describe('client', () => {
},
]);
});

it('limits connectors returned to 1000', async () => {
actionsClient.listTypes.mockImplementation(async () => actionTypes.slice(0, 1));
actionsClient.getAll.mockImplementation(async () =>
Array(MAX_SUPPORTED_CONNECTORS_RETURNED + 1).fill(connectors[0])
);

expect((await getConnectors(args)).length).toEqual(MAX_SUPPORTED_CONNECTORS_RETURNED);
});
});

describe('get', () => {
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
} from '../../../common/types/api';
import type { ConnectorMappings, ConnectorMappingResponse } from '../../../common/api';
import { FindActionConnectorResponseRt, decodeWithExcessOrThrow } from '../../../common/api';
import { MAX_CONCURRENT_SEARCHES } from '../../../common/constants';
import {
MAX_CONCURRENT_SEARCHES,
MAX_SUPPORTED_CONNECTORS_RETURNED,
} from '../../../common/constants';
import { createCaseError } from '../../common/error';
import type { CasesClientInternal } from '../client_internal';
import type { CasesClientArgs } from '../types';
Expand Down Expand Up @@ -207,9 +210,9 @@ export async function getConnectors({
return types;
}, {} as Record<string, ActionType>);

const res = (await actionsClient.getAll()).filter((action) =>
isConnectorSupported(action, actionTypes)
);
const res = (await actionsClient.getAll())
.filter((action) => isConnectorSupported(action, actionTypes))
.slice(0, MAX_SUPPORTED_CONNECTORS_RETURNED);

return decodeOrThrow(FindActionConnectorResponseRt)(res);
} catch (error) {
Expand Down

0 comments on commit 2774812

Please sign in to comment.