-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathContainersApi.ts
More file actions
277 lines (259 loc) · 7.9 KB
/
ContainersApi.ts
File metadata and controls
277 lines (259 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import { BaseAPIRequestFactory } from "../../datadog-api-client-common/baseapi";
import {
Configuration,
applySecurityAuthentication,
} from "../../datadog-api-client-common/configuration";
import {
RequestContext,
HttpMethod,
ResponseContext,
} from "../../datadog-api-client-common/http/http";
import { logger } from "../../../logger";
import { ObjectSerializer } from "../models/ObjectSerializer";
import { ApiException } from "../../datadog-api-client-common/exception";
import { APIErrorResponse } from "../models/APIErrorResponse";
import { ContainerItem } from "../models/ContainerItem";
import { ContainersResponse } from "../models/ContainersResponse";
export class ContainersApiRequestFactory extends BaseAPIRequestFactory {
public async listContainers(
filterTags?: string,
groupBy?: string,
sort?: string,
pageSize?: number,
pageCursor?: string,
_options?: Configuration
): Promise<RequestContext> {
const _config = _options || this.configuration;
// Path Params
const localVarPath = "/api/v2/containers";
// Make Request Context
const requestContext = _config
.getServer("v2.ContainersApi.listContainers")
.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Query Params
if (filterTags !== undefined) {
requestContext.setQueryParam(
"filter[tags]",
ObjectSerializer.serialize(filterTags, "string", ""),
""
);
}
if (groupBy !== undefined) {
requestContext.setQueryParam(
"group_by",
ObjectSerializer.serialize(groupBy, "string", ""),
""
);
}
if (sort !== undefined) {
requestContext.setQueryParam(
"sort",
ObjectSerializer.serialize(sort, "string", ""),
""
);
}
if (pageSize !== undefined) {
requestContext.setQueryParam(
"page[size]",
ObjectSerializer.serialize(pageSize, "number", "int32"),
""
);
}
if (pageCursor !== undefined) {
requestContext.setQueryParam(
"page[cursor]",
ObjectSerializer.serialize(pageCursor, "string", ""),
""
);
}
// Apply auth methods
applySecurityAuthentication(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
"AuthZ",
]);
return requestContext;
}
}
export class ContainersApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to listContainers
* @throws ApiException if the response code was not in [200, 299]
*/
public async listContainers(
response: ResponseContext
): Promise<ContainersResponse> {
const contentType = ObjectSerializer.normalizeMediaType(
response.headers["content-type"]
);
if (response.httpStatusCode === 200) {
const body: ContainersResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"ContainersResponse"
) as ContainersResponse;
return body;
}
if (
response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 429
) {
const bodyText = ObjectSerializer.parse(
await response.body.text(),
contentType
);
let body: APIErrorResponse;
try {
body = ObjectSerializer.deserialize(
bodyText,
"APIErrorResponse"
) as APIErrorResponse;
} catch (error) {
logger.debug(`Got error deserializing error: ${error}`);
throw new ApiException<APIErrorResponse>(
response.httpStatusCode,
bodyText
);
}
throw new ApiException<APIErrorResponse>(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: ContainersResponse = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"ContainersResponse",
""
) as ContainersResponse;
return body;
}
const body = (await response.body.text()) || "";
throw new ApiException<string>(
response.httpStatusCode,
'Unknown API Status Code!\nBody: "' + body + '"'
);
}
}
export interface ContainersApiListContainersRequest {
/**
* Comma-separated list of tags to filter containers by.
* @type string
*/
filterTags?: string;
/**
* Comma-separated list of tags to group containers by.
* @type string
*/
groupBy?: string;
/**
* Attribute to sort containers by.
* @type string
*/
sort?: string;
/**
* Maximum number of results returned.
* @type number
*/
pageSize?: number;
/**
* String to query the next page of results.
* This key is provided with each valid response from the API in `meta.pagination.next_cursor`.
* @type string
*/
pageCursor?: string;
}
export class ContainersApi {
private requestFactory: ContainersApiRequestFactory;
private responseProcessor: ContainersApiResponseProcessor;
private configuration: Configuration;
public constructor(
configuration: Configuration,
requestFactory?: ContainersApiRequestFactory,
responseProcessor?: ContainersApiResponseProcessor
) {
this.configuration = configuration;
this.requestFactory =
requestFactory || new ContainersApiRequestFactory(configuration);
this.responseProcessor =
responseProcessor || new ContainersApiResponseProcessor();
}
/**
* Get all containers for your organization.
* @param param The request object
*/
public listContainers(
param: ContainersApiListContainersRequest = {},
options?: Configuration
): Promise<ContainersResponse> {
const requestContextPromise = this.requestFactory.listContainers(
param.filterTags,
param.groupBy,
param.sort,
param.pageSize,
param.pageCursor,
options
);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.listContainers(responseContext);
});
});
}
/**
* Provide a paginated version of listContainers returning a generator with all the items.
*/
public async *listContainersWithPagination(
param: ContainersApiListContainersRequest = {},
options?: Configuration
): AsyncGenerator<ContainerItem> {
let pageSize = 1000;
if (param.pageSize !== undefined) {
pageSize = param.pageSize;
}
param.pageSize = pageSize;
while (true) {
const requestContext = await this.requestFactory.listContainers(
param.filterTags,
param.groupBy,
param.sort,
param.pageSize,
param.pageCursor,
options
);
const responseContext =
await this.configuration.httpApi.send(requestContext);
const response =
await this.responseProcessor.listContainers(responseContext);
const responseData = response.data;
if (responseData === undefined) {
break;
}
const results = responseData;
for (const item of results) {
yield item;
}
if (results.length < pageSize) {
break;
}
const cursorMeta = response.meta;
if (cursorMeta === undefined) {
break;
}
const cursorMetaPagination = cursorMeta.pagination;
if (cursorMetaPagination === undefined) {
break;
}
const cursorMetaPaginationNextCursor = cursorMetaPagination.nextCursor;
if (cursorMetaPaginationNextCursor === undefined) {
break;
}
param.pageCursor = cursorMetaPaginationNextCursor;
}
}
}