Skip to content

Commit 221884f

Browse files
Support for aggregations in Security's Query API Key Information API (#2455)
* Done * Restrict aggs types * types.ts * make contrib --------- Co-authored-by: Laurent Saint-Félix <[email protected]>
1 parent 7ffc441 commit 221884f

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

specification/security/query_api_keys/QueryApiKeysRequest.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* under the License.
1818
*/
1919

20+
import { Dictionary } from '@spec_utils/Dictionary'
21+
import { APIKeyAggregationContainer } from './types'
2022
import { RequestBase } from '@_types/Base'
2123
import { integer } from '@_types/Numeric'
2224
import { QueryContainer } from '@_types/query_dsl/abstractions'
@@ -32,7 +34,7 @@ import { Sort, SortResults } from '@_types/sort'
3234
export interface Request extends RequestBase {
3335
query_parameters: {
3436
/**
35-
* Return the snapshot of the owner user's role descriptors associated with the API key.
37+
* Return the snapshot of the owner user's role descriptors associated with the API key.
3638
* An API key's actual permission is the intersection of its assigned role descriptors and the owner user's role descriptors.
3739
* @availability stack since=8.5.0
3840
* @availability serverless
@@ -41,10 +43,21 @@ export interface Request extends RequestBase {
4143
with_limited_by?: boolean
4244
}
4345
body: {
46+
/**
47+
* Any aggregations to run over the corpus of returned API keys.
48+
* Aggregations and queries work together. Aggregations are computed only on the API keys that match the query.
49+
* This supports only a subset of aggregation types, namely: `terms`, `range`, `date_range`, `missing`,
50+
* `cardinality`, `value_count`, `composite`, `filter`, and `filters`.
51+
* Additionally, aggregations only run over the same subset of fields that query works with.
52+
* @aliases aggs */
53+
aggregations?: Dictionary<string, APIKeyAggregationContainer>
4454
/**
4555
* A query to filter which API keys to return.
46-
* The query supports a subset of query types, including `match_all`, `bool`, `term`, `terms`, `ids`, `prefix`, `wildcard`, and `range`.
47-
* You can query all public information associated with an API key.
56+
* If the query parameter is missing, it is equivalent to a `match_all` query.
57+
* The query supports a subset of query types, including `match_all`, `bool`, `term`, `terms`, `match`,
58+
* `ids`, `prefix`, `wildcard`, `exists`, `range`, and `simple_query_string`.
59+
* You can query the following public information associated with an API key: `id`, `type`, `name`,
60+
* `creation`, `expiration`, `invalidated`, `invalidation`, `username`, `realm`, and `metadata`.
4861
*/
4962
query?: QueryContainer
5063
/**

specification/security/query_api_keys/QueryApiKeysResponse.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import { ApiKey } from '@security/_types/ApiKey'
2121
import { integer } from '@_types/Numeric'
22+
import { Dictionary } from '@spec_utils/Dictionary'
23+
import { AggregateName } from '@_types/common'
24+
import { APIKeyAggregate } from './types'
2225

2326
export class Response {
2427
body: {
@@ -34,5 +37,9 @@ export class Response {
3437
* A list of API key information.
3538
*/
3639
api_keys: ApiKey[]
40+
/**
41+
* The aggregations result, if requested.
42+
*/
43+
aggregations?: Dictionary<AggregateName, APIKeyAggregate>
3744
}
3845
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Dictionary } from '@spec_utils/Dictionary'
21+
import { Metadata } from '@_types/common'
22+
import { QueryContainer } from '@_types/query_dsl/abstractions'
23+
import {
24+
CompositeAggregation,
25+
DateRangeAggregation,
26+
FiltersAggregation,
27+
MissingAggregation,
28+
RangeAggregation,
29+
TermsAggregation
30+
} from '@_types/aggregations/bucket'
31+
import {
32+
CardinalityAggregation,
33+
ValueCountAggregation
34+
} from '@_types/aggregations/metric'
35+
import {
36+
CardinalityAggregate,
37+
ValueCountAggregate,
38+
StringTermsAggregate,
39+
LongTermsAggregate,
40+
DoubleTermsAggregate,
41+
UnmappedTermsAggregate,
42+
MultiTermsAggregate,
43+
MissingAggregate,
44+
FilterAggregate,
45+
RangeAggregate,
46+
DateRangeAggregate,
47+
FiltersAggregate,
48+
CompositeAggregate
49+
} from '@_types/aggregations/Aggregate'
50+
51+
/**
52+
* @variants container
53+
* @non_exhaustive
54+
*/
55+
export class APIKeyAggregationContainer {
56+
/**
57+
* Sub-aggregations for this aggregation.
58+
* Only applies to bucket aggregations.
59+
* @variant container_property
60+
* @aliases aggs
61+
*/
62+
aggregations?: Dictionary<string, APIKeyAggregationContainer>
63+
/**
64+
* @variant container_property
65+
*/
66+
meta?: Metadata
67+
/**
68+
* A single-value metrics aggregation that calculates an approximate count of distinct values.
69+
* @doc_id search-aggregations-metrics-cardinality-aggregation
70+
*/
71+
cardinality?: CardinalityAggregation
72+
/**
73+
* A multi-bucket aggregation that creates composite buckets from different sources.
74+
* Unlike the other multi-bucket aggregations, you can use the `composite` aggregation to paginate *all* buckets from a multi-level aggregation efficiently.
75+
*/
76+
composite?: CompositeAggregation
77+
/**
78+
* A multi-bucket value source based aggregation that enables the user to define a set of date ranges - each representing a bucket.
79+
* @doc_id search-aggregations-bucket-daterange-aggregation
80+
*/
81+
date_range?: DateRangeAggregation
82+
/**
83+
* A single bucket aggregation that narrows the set of documents to those that match a query.
84+
* @doc_id search-aggregations-bucket-filter-aggregation
85+
*/
86+
filter?: QueryContainer
87+
/**
88+
* A multi-bucket aggregation where each bucket contains the documents that match a query.
89+
* @doc_id search-aggregations-bucket-filters-aggregation
90+
*/
91+
filters?: FiltersAggregation
92+
missing?: MissingAggregation
93+
/**
94+
* A multi-bucket value source based aggregation that enables the user to define a set of ranges - each representing a bucket.
95+
* @doc_id search-aggregations-bucket-range-aggregation
96+
*/
97+
range?: RangeAggregation
98+
/**
99+
* A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value.
100+
* @doc_id search-aggregations-bucket-terms-aggregation
101+
*/
102+
terms?: TermsAggregation
103+
/**
104+
* A single-value metrics aggregation that counts the number of values that are extracted from the aggregated documents.
105+
* @doc_id search-aggregations-metrics-valuecount-aggregation
106+
*/
107+
value_count?: ValueCountAggregation
108+
}
109+
110+
/**
111+
* @variants external
112+
* @non_exhaustive
113+
*/
114+
export type APIKeyAggregate =
115+
| CardinalityAggregate
116+
| ValueCountAggregate
117+
| StringTermsAggregate
118+
| LongTermsAggregate
119+
| DoubleTermsAggregate
120+
| UnmappedTermsAggregate
121+
| MultiTermsAggregate
122+
| MissingAggregate
123+
| FilterAggregate
124+
| FiltersAggregate
125+
| RangeAggregate
126+
| DateRangeAggregate
127+
| CompositeAggregate

0 commit comments

Comments
 (0)