Skip to content

Commit 8baa382

Browse files
Restrict query type when querying API keys (#2460) (#2461)
* Ok? * Update specification/security/query_api_keys/types.ts Co-authored-by: Laurent Saint-Félix <[email protected]> * make contrib --------- Co-authored-by: Laurent Saint-Félix <[email protected]> (cherry picked from commit 6c85668) Co-authored-by: Albert Zaharovits <[email protected]>
1 parent 55fd1c2 commit 8baa382

File tree

2 files changed

+108
-8
lines changed

2 files changed

+108
-8
lines changed

specification/security/query_api_keys/QueryApiKeysRequest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
*/
1919

2020
import { Dictionary } from '@spec_utils/Dictionary'
21-
import { APIKeyAggregationContainer } from './types'
21+
import { APIKeyAggregationContainer, APIKeyQueryContainer } from './types'
2222
import { RequestBase } from '@_types/Base'
2323
import { integer } from '@_types/Numeric'
24-
import { QueryContainer } from '@_types/query_dsl/abstractions'
2524
import { Sort, SortResults } from '@_types/sort'
2625

2726
/**
@@ -59,7 +58,7 @@ export interface Request extends RequestBase {
5958
* You can query the following public information associated with an API key: `id`, `type`, `name`,
6059
* `creation`, `expiration`, `invalidated`, `invalidation`, `username`, `realm`, and `metadata`.
6160
*/
62-
query?: QueryContainer
61+
query?: APIKeyQueryContainer
6362
/**
6463
* Starting document offset.
6564
* By default, you cannot page through more than 10,000 hits using the from and size parameters.

specification/security/query_api_keys/types.ts

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@
1818
*/
1919

2020
import { Dictionary } from '@spec_utils/Dictionary'
21-
import { Metadata } from '@_types/common'
22-
import { QueryContainer } from '@_types/query_dsl/abstractions'
21+
import { SingleKeyDictionary } from '@spec_utils/Dictionary'
22+
import { Metadata, Field } from '@_types/common'
23+
import { BoolQuery } from '@_types/query_dsl/compound'
2324
import {
25+
ExistsQuery,
26+
IdsQuery,
27+
PrefixQuery,
28+
RangeQuery,
29+
TermQuery,
30+
TermsQuery,
31+
WildcardQuery
32+
} from '@_types/query_dsl/term'
33+
import { MatchQuery, SimpleQueryStringQuery } from '@_types/query_dsl/fulltext'
34+
import { MatchAllQuery } from '@_types/query_dsl/MatchAllQuery'
35+
import {
36+
BucketAggregationBase,
2437
CompositeAggregation,
2538
DateRangeAggregation,
26-
FiltersAggregation,
2739
MissingAggregation,
2840
RangeAggregation,
2941
TermsAggregation
@@ -33,6 +45,7 @@ import {
3345
ValueCountAggregation
3446
} from '@_types/aggregations/metric'
3547
import {
48+
Buckets,
3649
CardinalityAggregate,
3750
ValueCountAggregate,
3851
StringTermsAggregate,
@@ -83,12 +96,12 @@ export class APIKeyAggregationContainer {
8396
* A single bucket aggregation that narrows the set of documents to those that match a query.
8497
* @doc_id search-aggregations-bucket-filter-aggregation
8598
*/
86-
filter?: QueryContainer
99+
filter?: APIKeyQueryContainer
87100
/**
88101
* A multi-bucket aggregation where each bucket contains the documents that match a query.
89102
* @doc_id search-aggregations-bucket-filters-aggregation
90103
*/
91-
filters?: FiltersAggregation
104+
filters?: APIKeyFiltersAggregation
92105
missing?: MissingAggregation
93106
/**
94107
* A multi-bucket value source based aggregation that enables the user to define a set of ranges - each representing a bucket.
@@ -125,3 +138,91 @@ export type APIKeyAggregate =
125138
| RangeAggregate
126139
| DateRangeAggregate
127140
| CompositeAggregate
141+
142+
/**
143+
* @variants container
144+
* @non_exhaustive
145+
*/
146+
export class APIKeyQueryContainer {
147+
/**
148+
* matches documents matching boolean combinations of other queries.
149+
* @doc_id query-dsl-bool-query
150+
*/
151+
bool?: BoolQuery
152+
/**
153+
* Returns documents that contain an indexed value for a field.
154+
* @doc_id query-dsl-exists-query
155+
*/
156+
exists?: ExistsQuery
157+
/**
158+
* Returns documents based on their IDs.
159+
* This query uses document IDs stored in the `_id` field.
160+
* @doc_id query-dsl-ids-query
161+
*/
162+
ids?: IdsQuery
163+
/**
164+
* Returns documents that match a provided text, number, date or boolean value.
165+
* The provided text is analyzed before matching.
166+
* @doc_id query-dsl-match-query
167+
*/
168+
match?: SingleKeyDictionary<Field, MatchQuery>
169+
/**
170+
* Matches all documents, giving them all a `_score` of 1.0.
171+
* @doc_id query-dsl-match-all-query
172+
*/
173+
match_all?: MatchAllQuery
174+
/**
175+
* Returns documents that contain a specific prefix in a provided field.
176+
* @doc_id query-dsl-prefix-query
177+
*/
178+
prefix?: SingleKeyDictionary<Field, PrefixQuery>
179+
/**
180+
* Returns documents that contain terms within a provided range.
181+
* @doc_id query-dsl-range-query
182+
*/
183+
range?: SingleKeyDictionary<Field, RangeQuery>
184+
/**
185+
* Returns documents based on a provided query string, using a parser with a limited but fault-tolerant syntax.
186+
* @doc_id query-dsl-simple-query-string-query
187+
*/
188+
simple_query_string?: SimpleQueryStringQuery
189+
/**
190+
* Returns documents that contain an exact term in a provided field.
191+
* To return a document, the query term must exactly match the queried field's value, including whitespace and capitalization.
192+
* @doc_id query-dsl-term-query
193+
*/
194+
term?: SingleKeyDictionary<Field, TermQuery>
195+
/**
196+
* Returns documents that contain one or more exact terms in a provided field.
197+
* To return a document, one or more terms must exactly match a field value, including whitespace and capitalization.
198+
* @doc_id query-dsl-terms-query
199+
*/
200+
terms?: TermsQuery
201+
/**
202+
* Returns documents that contain terms matching a wildcard pattern.
203+
* @doc_id query-dsl-wildcard-query
204+
*/
205+
wildcard?: SingleKeyDictionary<Field, WildcardQuery>
206+
}
207+
208+
export class APIKeyFiltersAggregation extends BucketAggregationBase {
209+
/**
210+
* Collection of queries from which to build buckets.
211+
*/
212+
filters?: Buckets<APIKeyQueryContainer>
213+
/**
214+
* Set to `true` to add a bucket to the response which will contain all documents that do not match any of the given filters.
215+
*/
216+
other_bucket?: boolean
217+
/**
218+
* The key with which the other bucket is returned.
219+
* @server_default _other_
220+
*/
221+
other_bucket_key?: string
222+
/**
223+
* By default, the named filters aggregation returns the buckets as an object.
224+
* Set to `false` to return the buckets as an array of objects.
225+
* @server_default true
226+
*/
227+
keyed?: boolean
228+
}

0 commit comments

Comments
 (0)