* [NP] Allow custom validations in HTTP Routes apart from @kbn/config-schema
* API docs
* Allow validate function in the route handler (run-code validation)
* Prefix RouteXXX + Params and Body Validation Aliases
* Fix test broken by lodash
* Update API docs
* Add default types for simpler manual declaration
* Add run-time validation of the RouteValidateSpec
* Expose RouteValidationError instead of SchemaTypeError
* RouteValidator as a class to match config-schema interface
* Test for not-inline handler (need to check IRouter for #47047)
* Add preValidation of the input for a safer custom validation
* Better types for RouteHandlers
* [NP] Move route validation to RouteValidator wrapper
* Use the class only internally but maintain the same API
* Fix types
* Ensure RouteValidator instance in KibanaRequest.from
* Fix validator.tests (Buffer.from instead of new Buffer)
* Default precheck should allow null values
* Also allow undefined in preChecks
* MR feedback fixes
* Provide RouteValidationResolver to the validation function
* Add functional tests
* Fix new functional tests
* Fix validator additional test
* Fix test with new resolver
* Remove unused import
* Rename ValidationResolver to ValidationResultFactory and change the interface to look more like the KibanaResponseFactory
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* register app, create functional test
* formatting
* update tests
* adjust test data for endpoint
* add endpoint tests for testing spaces, app enabled, disabled, etc
* linting
* add read privileges to endpoint
* rename variable since its used now
* remove deprecated context
* remove unused variable
* fix type check
* correct test suite message
Co-Authored-By: Larry Gregory <lgregorydev@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Larry Gregory <lgregorydev@gmail.com>
* Implement `log_entries/item` api
* Use endpoint in the `useLogFlyout` hook
* Clean up GraphQL implementation and types
* Extract type for log entries cursor
* fixup! Extract type for log entries cursor
* gives time to the events to be loaded
* gives time to the element to be loaded
* fixes events viewer tests
* fixes inspect tests
* fixes url state tests
* adds fields counts
* fixes fields browser test
* fixes typecheck error
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
When an Alert is updated its interval is stored but isn't applied to the underlying scheduled task.
In this PR we make use of the new runNow api to "refresh" the task whenever the alert's schedule is updated.
* re-structure detection engine + change routing name
* add editing/details feature for a rule
add feature to not edit immutable rule
* review I
* review II
* change constant
* review III
* Remove legacy index_patterns import
We'd already brought in the new interface in a previous commit; this was
just used as an unnecessary type assertion.
* Update snapshots following new docLink mocks
* Remove unused manual mocks
These are not picked up by jest; calling
jest.mock('lib/compose/kibana_core') has the same effect whether or not
these files exist.
* WIP: Use kibana core mock everywhere we're doing it manually
The timeline tests are the last place we're explicitly mocking
useKibanaCore; removing the mocks cause tests to hang. I think hey're
relying on the side effects of importing the mock/ui_settings file, but
I'll figure that out next.
* Replace ui/documentation_links with core NP service
In most instances, this meant using the useContext hook with our NP core
context.
This also updates our mocks to leverage the factory so graciously
provided by platform.
There are a few failing tests, mostly due to links being previously
undefined in tests.
* Use new mocks on timeline test that doesn't hang
The rest of these do, though.
* Remove remaining uses of mockUiSettings in useKibanaCore mocks
These have to be evaluated immediately so that we always return the
same core object. Otherwise we get stuck in a loop between
render/useEffect/setState due to the savedObjects client being different
on each invocation.
* Invoke platform's mock factory at mock time
Previously, we were invoking it any time someone called `useKibanaCore`,
getting a new object back each time. This both caused some bugs (looping
with useEffect) and was not representative of how the actual hook
worked.
This also moves that invokation into the mock function, along with
shaping the mocked module so that we don't have to do it in every call
to jest.mock.
* WIP: migrating to use kibana_react's provider and helpers
We're re-exporting these locally to have more control around mocking
them (until platform implements that).
This breaks everything that was using the old mocks. Will fix.
* WIP: Migrating to use kibana_react
Instead of our homegrown hooks we can use these utilities instead.
Unfortunately kibana_react doesn't yet have mocks, so we had to implement
that ourselves. Luckily, we already had local mocks for the settings
service. This migrates to a the new format. For clarity and consistency,
we also re-export new platform's mocks here and use them to populate our
kibana_react mocks.
We started by migrating the UiSettings service to new platform, and let
that drive the rest. With the mocks in place for kibana_react, removing
the usage of useKibanaCore was a natural step as well.
The next step is removing the usage of chrome.getUiSettingsClient with
our useUiSetting$ hook, and with that (and maybe some config setup; I'm
seeing errors at runtime), we should be ready to start migrating other
services.
* Bind a copy of kibana at mock creation
We were previously returning a new copy any time e.g. useKibana was
called, which is not the contract that consumers are expecting. and in
fact caused looping with components employing useEffect etc.
* Remove internal context providers and last usage
We're now using kibana_react fully.
* Fix tests failing due to wrong mocks
Remaining failures are either due to a date format issue, or something
being rendered differently. Those are up next.
Still haven't touched use of chrome.getUiSettingsClient, that's after.
* Fix test failures related to date formatting
* mocks missing UI Setting (DEFAULT_TIMEZONE_BROWSER) which is required
by our formatted_date utilities
* mock timepicker ranges in the one test that uses it (SuperDatePicker)
* Remove unnecessary and/or redundant mocks
Since our TestProvider now mocks new platform, the only tests that
should need to mock uiSettings related stuff (e.g. timezone preferences)
would be the tests that (directly or no) use kibana_react to get it.
* Refactor kibana_react mocks
* adds a mock for the non-observable useUiSetting
* removes the unmockable HOC withKibana
* Replace usage of chrome.getUiSettingsClient with useUiSetting
We're opting for the non-observable behavior here because I believe
that's more analagous.
There are a few remaining usages in non-react code.
Tests are still using the mocks, those'll be removed next.
* Remove ui_settings mocks
Now that we're not using this hook there's no need for the mocks. Tests
are green.
* Remove siem's UI settings hook
We're now using the ones provided by kibana_react.
* Use withKibana HOC on our component classes
React was kind enough to remind me that I can't put hooks in classes.
Whoops.
* Set defaults for some unknown UI settings
The service claims not to know about these settings we're retrieving.
Until I can figure out where they should come from, we're going to
initialize them with what seem to be the defaults at plugin
initialization.
* Remove old hooks
These have now been replaced with kibana_react's equivalents.
* Fix type error on usage of useKibana hook
This is one of the few places where we're using another plugin, which
are not present in the default typings due to their opt-in nature.
* Fix type error on ML call
The indexPattern we get back is actually an array. The endpoint seems to
handle this just fine (at least, it doesn't blow up), but once we
started retrieving a typed value this error surfaced.
* Export a 'bound' version of the useKibana function
Rather than having to type this on each invocation. This requires us to
define which plugins we depend on, which is a good thing.
* Instantiate our mock function
We aren't using these right now I didn't notice, but that wasn't the
right reference.
* Fix test that relies on unmocked service
Our QueryBar component relies very (very, very) indirectly on a storage
service that does not exist in New Platform, nor its corresponding
mocks. To get it passing for now, we're just gonna pretend like it's
there.
* Remove use of ui/chrome in our charts
Replaces with hooks that accomplish the same.
* Remove last use of chrome.getUiSettingsClient
This function is itself a hook, so we should be good here.
* Remove unnecessary non-null assertions
Now that we're using our typed version of the useKibana hook, typescript
knows that these services will be available (once we actually enforce
that in our kibana.json, of course).
* Fix chart tests
These rely on a kibana hook now, so we need to mock it out for these
renders lest we blow up when the context isn't there.
* Replace missing mock
I deleted this in a previous commit, thinking it unneeded.
However, getHostDetailsBreadcrumbs ultimately asks for some
default date parameters for the timerange boundaries.
* Add back tests for our theming hook
* Style: cleanup
* Remove unneeded default UI Settings values
We were previously getting errors due to these values not being known to
the client, but it looks like that was either fixed upstream, or a
temporary issue caused by some improper context setup.
* Simplify kibana_react mocks
Let's leave JSX out of it.
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* Added license check for actions server API
* Added license check for alerting server API
* Fixed typecheck errors and duplication tests
* Moved all license checks to New Platform
* Clean up not used shims options
* Update x-pack/legacy/plugins/alerting/server/extend_route_with_license_check.test.ts
Co-Authored-By: Gidi Meir Morris <github@gidi.io>
* Update x-pack/legacy/plugins/actions/server/lib/license_state.ts
Co-Authored-By: Gidi Meir Morris <github@gidi.io>
* Refactored due to comments
* Fixed typo
Co-authored-by: Gidi Meir Morris <github@gidi.io>
## Summary
* Adds Bulk REST API and routes added for create, update, and delete
* Loops over data and calls `alertClient` until alerting team gives us bulk to push down
* Adds Unit tests
Testing/Usage:
Create in bulk:
```ts
POST /api/detection_engine/rules/_bulk_create
[{ ... rule_1}, { ... rule_2}]
```
see script
```ts
./post_rule_bulk.sh
```
Update in bulk:
```ts
PUT /api/detection_engine/rules/_bulk_update
[{ ... rule_1}, { ... rule_2}]
```
see script
```ts
./update_rule_bulk.sh
```
Delete in bulk:
```ts
DELETE /api/detection_engine/rules/_bulk_delete
[{"id": "rule_1"}, {"id": "rule_2"}]
```
or in case your client does not support bodies in DELETE
```ts
POST /api/detection_engine/rules/_bulk_delete
[{"id": "rule_1"}, {"id": "rule_2"}]
```
But try to use DELETE where possible
see script
```ts
./delete_bulk.sh
```
Caveats and error handling....If you do not validate correctly you will still get back a `400` return code. If you do validate correctly but one or more objects have errors involving a conflict or not found, you will get back a 200, but the body message will contain an array of errors or successes.
Examples:
If you delete in bulk for two objects but both do not have any values you get a response of `200` but then these errors in the array:
```ts
./delete_bulk.sh
[
{
"id": "query-rule-id-1",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-1\" not found"
}
},
{
"id": "query-rule-id-2",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-2\" not found"
}
}
]
```
If one has a valid deleted value but the second does not you get a status of `200` and one object back as being deleted but the second as an error:
```ts
./delete_bulk.sh
[
{
"created_at": "2019-12-19T04:12:26.470Z",
"updated_at": "2019-12-19T04:12:26.470Z",
"created_by": "elastic_kibana",
"description": "Query with a rule_id that acts like an external id",
"enabled": true,
"false_positives": [],
"from": "now-6m",
"id": "46d83e70-982a-4ba8-9ac1-fc386643c014",
"immutable": false,
"interval": "5m",
"rule_id": "query-rule-id-1",
"language": "kuery",
"output_index": ".siem-signals-frank-hassanabad-default",
"max_signals": 100,
"risk_score": 1,
"name": "Query with a rule id Number 1",
"query": "user.name: root or user.name: admin",
"references": [],
"severity": "high",
"updated_by": "elastic_kibana",
"tags": [],
"to": "now",
"type": "query",
"threats": [],
"version": 1
},
{
"id": "query-rule-id-2",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-2\" not found"
}
}
]
```
Another example where an update has two errors because it tried to update two docs but both do not exist yet you get back a response of `200` but this array of errors:
```ts
./update_rule_bulk.sh <<<
[
{
"id": "query-rule-id-1",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-1\" not found"
}
},
{
"id": "query-rule-id-2",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-2\" not found"
}
}
]
```
If one is updatable but the other is not you get back a response of `200` and one update back but the other is an error:
```ts
./update_rule_bulk.sh
[
{
"created_at": "2019-12-19T04:15:43.739Z",
"updated_at": "2019-12-19T04:16:01.633Z",
"created_by": "elastic_kibana",
"description": "Query with a rule_id that acts like an external id",
"enabled": true,
"false_positives": [],
"from": "now-6m",
"id": "c1fcea2c-cbc6-4f28-b7e7-32b4d7cb799d",
"immutable": false,
"interval": "5m",
"rule_id": "query-rule-id-1",
"language": "kuery",
"output_index": ".siem-signals-frank-hassanabad-default",
"max_signals": 100,
"risk_score": 1,
"name": "Rule id Number 1 with an updated name",
"query": "user.name: root or user.name: admin",
"references": [],
"severity": "high",
"updated_by": "elastic_kibana",
"tags": [],
"to": "now",
"type": "query",
"threats": [],
"version": 2
},
{
"id": "query-rule-id-2",
"error": {
"statusCode": 404,
"message": "rule_id: \"query-rule-id-2\" not found"
}
}
]
```
Same thing goes with posts and any other bulk actions.
### Checklist
Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR.
~~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~~
~~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~
~~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~
- [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
~~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~
### For maintainers
~~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~
- [x] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
* text styling
* label style editor UI
* wire up styles to mb
* allow string values
* remove console.log
* default getFields to provide ordinal fields for vector source
* fix vector_style jest test
* add label styles to docs
* fix prettier errors
* use index-pattern field formatter to format label
* rename LABEL to LABEL_TEXT
* review feedback
* fix problem with icons not displaying with labels
* fix functional tests
* fix canno read name of null error
* update jest expect
* fix eslint errors
* do not display label text in legend
* always show all label styling properties in editor
* review feedback
* Add user info on the option of the request
* fix type
* review
* fix test
* fix bug
* add an unauthenticated user concept for timeline
* add favorite flter with unauthenticated user
* provide a list of breaking changes in licensing plugin
* Apply suggestions from code review
Co-Authored-By: Rudolf Meijering <skaapgif@gmail.com>
* add ToC
* fix comment
* introduce core provider plugin for integration tests
* platform functional tests use core_provider_plugin for testing
* add 3 scenario for licensing plugins: server, client, legacy
* remove unused code
* run all licensing_plugin tests on CI
* remove duplicated config
* address comments
* declare global type for core provider
* mention uiSettingsClient in the context docs
* autogenerated docs for logger method
* describe what's available via request context handler. how to extend it
* make type optional