From 615a9bebe0c255a5e67f4e1aa9f74e44fce72d73 Mon Sep 17 00:00:00 2001 From: Dimitrios Vasilas Date: Tue, 26 Nov 2024 10:13:57 +0200 Subject: [PATCH] SCUBA-186: Add GetMetricsBatch API --- src/api.ts | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/client.ts | 18 ++++++++++- src/index.ts | 2 +- 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/api.ts b/src/api.ts index e080a25..591bc10 100644 --- a/src/api.ts +++ b/src/api.ts @@ -47,6 +47,11 @@ export enum AdminActions { */ export interface MetricsClass {} +export type GetMetricsBatchBody = { + resourceNames: string[]; + dates?: string[]; +}; + /** * ScubaApi - axios parameter creator * @export @@ -154,6 +159,57 @@ export const ScubaApiAxiosParamCreator = function (configuration?: Configuration options: localVarRequestOptions, }; }, + /** + * + * @param {MetricsClass} metricsClass + * @param {any} resourceName + * @param {any} metricsDate + * @param {any} [body] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getMetricsBatch: async ( + metricsClass: MetricsClass, + body: GetMetricsBatchBody, + options: AxiosRequestConfig = {}, + ): Promise => { + // verify required parameter 'metricsClass' is not null or undefined + assertParamExists('getMetricsBatch', 'metricsClass', metricsClass); + // // verify required parameter 'resourceName' is not null or undefined + // assertParamExists('getMetrics', 'resourceName', resourceName); + // // verify required parameter 'metricsDate' is not null or undefined + // assertParamExists('getMetrics', 'metricsDate', metricsDate); + const localVarPath = `/metrics/{metricsClass}`.replace( + `{${'metricsClass'}}`, + encodeURIComponent(String(metricsClass)), + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @param {*} [options] Override http request option. @@ -290,6 +346,23 @@ export const ScubaApiFp = function (configuration?: Configuration) { ); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @param {MetricsClass} metricsClass + * @param {any} resourceName + * @param {any} metricsDate + * @param {any} [body] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getMetricsBatch( + metricsClass: MetricsClass, + body: GetMetricsBatchBody, + options?: AxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getMetrics(metricsClass, body, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -418,6 +491,22 @@ export class ScubaApi extends BaseAPI { .then(request => request(this.axios, this.basePath)); } + /** + * + * @param {MetricsClass} metricsClass + * @param {any} resourceName + * @param {any} metricsDate + * @param {any} [body] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ScubaApi + */ + public getMetricsBatch(metricsClass: MetricsClass, body: GetMetricsBatchBody, options?: AxiosRequestConfig) { + return ScubaApiFp(this.configuration) + .getMetrics(metricsClass, body, options) + .then(request => request(this.axios, this.basePath)); + } + /** * Health check endpoint * @param {*} [options] Override http request option. diff --git a/src/client.ts b/src/client.ts index 6aa1e25..1ecffba 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,7 +6,7 @@ import globalAxios, { AxiosRequestConfig, AxiosInstance, AxiosHeaders } from 'ax import { Sha256 } from '@aws-crypto/sha256-js'; import { URL } from 'url'; import { parse as parseQuerystring } from 'querystring'; -import { ScubaApi, AdminActions } from './api'; +import { ScubaApi, AdminActions, GetMetricsBatchBody } from './api'; import { Configuration, ConfigurationParameters } from './configuration'; export type MetricsClass = 'account' | 'bucket' | 'service'; @@ -170,6 +170,22 @@ export default class ScubaClient { return resp.data; } + async getMetricsBatch( + metricsClass: MetricsClass, + body: GetMetricsBatchBody, + options?: AxiosRequestConfig, + ): Promise { + // const year = lpad(date.getUTCFullYear(), 4); + // const month = lpad(date.getUTCMonth() + 1, 2); + // const day = lpad(date.getUTCDate(), 2); + // const dateString = `${year}-${month}-${day}`; + const resp = (await this._api.getMetricsBatch(metricsClass, body, { + ...this._defaultReqOptions, + ...options, + })) as any; + return resp.data; + } + async healthCheck(options?: AxiosRequestConfig): Promise { const resp = (await this._api.healthCheck({ ...this._defaultReqOptions, ...options })) as any; return resp.data; diff --git a/src/index.ts b/src/index.ts index 5f97fb3..c360d73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ export * from './client'; export { default as ScubaClient } from './client'; -export { AdminActions } from './api'; +export { AdminActions, GetMetricsBatchBody } from './api';