-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add support for reading request ID from X-Opaque-Id header #71019
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6c20c08
Add IP type to kbn/config-schema
joshdover b638bcd
Add support for reading request ID from X-Opaque-Id header
joshdover a6b970e
Merge remote-tracking branch 'upstream/master' into al/x-opaque-id
joshdover 891f3a7
Default allowFromAnyIp to false
joshdover 7ee769f
Fix fake requests in tests
joshdover 4eb455d
Default to `internal` for fake requests
joshdover 3f5db53
Merge remote-tracking branch 'upstream/master' into al/x-opaque-id
joshdover 46b069f
Add support for new ES client
joshdover 074dea5
Fix integration tests
joshdover 9028c0a
Handle undefined socket
joshdover a33b18f
Merge remote-tracking branch 'upstream/master' into al/x-opaque-id
joshdover 1144ebe
Rename server.requestOpaqueId to server.requestId
joshdover d4815c0
Merge remote-tracking branch 'upstream/master' into al/x-opaque-id
joshdover 1d2c017
Merge branch 'master' into al/x-opaque-id
elasticmachine c5e7ce4
Merge branch 'master' into al/x-opaque-id
elasticmachine 12f35d8
Merge remote-tracking branch 'upstream/master' into al/x-opaque-id
joshdover 275b58c
Review nits
joshdover ec9a96d
rm unused import
joshdover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
docs/development/core/server/kibana-plugin-core-server.kibanarequest.id.md
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,18 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [KibanaRequest](./kibana-plugin-core-server.kibanarequest.md) > [id](./kibana-plugin-core-server.kibanarequest.id.md) | ||
|
||
## KibanaRequest.id property | ||
|
||
A identifier to identify this request. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly id: string; | ||
``` | ||
|
||
## Remarks | ||
|
||
Depending on the user's configuration, this value may be sourced from the incoming request's `X-Opaque-Id` header which is not guaranteed to be unique per request. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { schema } from '..'; | ||
|
||
const { ip } = schema; | ||
|
||
describe('ip validation', () => { | ||
test('accepts ipv4', () => { | ||
expect(ip().validate('1.1.1.1')).toEqual('1.1.1.1'); | ||
}); | ||
test('accepts ipv6', () => { | ||
expect(ip().validate('1200:0000:AB00:1234:0000:2552:7777:1313')).toEqual( | ||
'1200:0000:AB00:1234:0000:2552:7777:1313' | ||
); | ||
}); | ||
test('rejects ipv6 when not specified', () => { | ||
expect(() => | ||
ip({ versions: ['ipv4'] }).validate('1200:0000:AB00:1234:0000:2552:7777:1313') | ||
).toThrowErrorMatchingInlineSnapshot(`"value must be a valid ipv4 address"`); | ||
}); | ||
test('rejects ipv4 when not specified', () => { | ||
expect(() => ip({ versions: ['ipv6'] }).validate('1.1.1.1')).toThrowErrorMatchingInlineSnapshot( | ||
`"value must be a valid ipv6 address"` | ||
); | ||
}); | ||
test('rejects invalid ip addresses', () => { | ||
expect(() => ip().validate('1.1.1.1/24')).toThrowErrorMatchingInlineSnapshot( | ||
`"value must be a valid ipv4 or ipv6 address"` | ||
); | ||
expect(() => ip().validate('99999.1.1.1')).toThrowErrorMatchingInlineSnapshot( | ||
`"value must be a valid ipv4 or ipv6 address"` | ||
); | ||
expect(() => | ||
ip().validate('ZZZZ:0000:AB00:1234:0000:2552:7777:1313') | ||
).toThrowErrorMatchingInlineSnapshot(`"value must be a valid ipv4 or ipv6 address"`); | ||
expect(() => ip().validate('blah 1234')).toThrowErrorMatchingInlineSnapshot( | ||
`"value must be a valid ipv4 or ipv6 address"` | ||
); | ||
}); | ||
}); | ||
|
||
test('returns error when not string', () => { | ||
expect(() => ip().validate(123)).toThrowErrorMatchingInlineSnapshot( | ||
`"expected value of type [string] but got [number]"` | ||
); | ||
|
||
expect(() => ip().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( | ||
`"expected value of type [string] but got [Array]"` | ||
); | ||
|
||
expect(() => ip().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( | ||
`"expected value of type [string] but got [RegExp]"` | ||
); | ||
}); |
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,46 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import typeDetect from 'type-detect'; | ||
import { internals } from '../internals'; | ||
import { Type, TypeOptions } from './type'; | ||
|
||
export type IpVersion = 'ipv4' | 'ipv6'; | ||
export type IpOptions = TypeOptions<string> & { | ||
/** | ||
* IP versions to accept, defaults to ['ipv4', 'ipv6']. | ||
*/ | ||
versions: IpVersion[]; | ||
}; | ||
|
||
export class IpType extends Type<string> { | ||
constructor(options: IpOptions = { versions: ['ipv4', 'ipv6'] }) { | ||
const schema = internals.string().ip({ version: options.versions, cidr: 'forbidden' }); | ||
super(schema, options); | ||
} | ||
|
||
protected handleError(type: string, { value, version }: Record<string, any>) { | ||
switch (type) { | ||
case 'string.base': | ||
return `expected value of type [string] but got [${typeDetect(value)}]`; | ||
case 'string.ipVersion': | ||
return `value must be a valid ${version.join(' or ')} address`; | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cidr not needed right now, so I just set to
forbidden
. Can be exposed in the future if needed.