Compare commits
No commits in common. "355a8928b0ccdb527ddb3daef6adfdbb84ea441b" and "74d6205d4c5f633df792ba8e7faaebfc6da20212" have entirely different histories.
355a8928b0
...
74d6205d4c
|
@ -102,5 +102,3 @@ dist
|
|||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
lib/**
|
||||
openapi.yaml
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
trailingComma: all
|
||||
useTabs: False
|
||||
tabWidth: 4
|
||||
arrowParens: avoid
|
||||
singleQuote: True
|
||||
semi: True
|
||||
printWidth: 120
|
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
if [ ! -f "openapi.yaml" ]; then
|
||||
printf 'No spec file found at %s/%s\n' "$PWD" "openapi.yaml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export TS_POST_PROCESS_FILE="yarn format"
|
||||
|
||||
exec yarn openapi-generator-cli generate -i openapi.yaml -g typescript-axios -o src/
|
5
index.ts
5
index.ts
|
@ -1,5 +0,0 @@
|
|||
export * from './src';
|
||||
|
||||
import { ScubaClient } from './src';
|
||||
|
||||
export default ScubaClient;
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
|
||||
"spaces": 4,
|
||||
"generator-cli": {
|
||||
"version": "6.5.0"
|
||||
}
|
||||
}
|
41
package.json
41
package.json
|
@ -1,41 +0,0 @@
|
|||
{
|
||||
"name": "scubaclient",
|
||||
"version": "1.0.0",
|
||||
"description": "Scuba API client",
|
||||
"main": "lib/index.js",
|
||||
"repository": "https://github.com/scality/scubaclient",
|
||||
"author": "Scality",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "tsc --strict",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier -w src && eslint --fix",
|
||||
"postinstall": "yarn build",
|
||||
"prepack": "yarn build",
|
||||
"prepare": "yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.2",
|
||||
"@babel/preset-env": "^7.20.2",
|
||||
"@babel/preset-typescript": "^7.18.6",
|
||||
"@openapitools/openapi-generator-cli": "^2.5.2",
|
||||
"@types/jest": "^29.2.3",
|
||||
"@types/node": "^18.11.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
||||
"@typescript-eslint/parser": "^5.45.0",
|
||||
"babel-jest": "^29.3.1",
|
||||
"eslint": "^8.28.0",
|
||||
"jest": "^29.3.1",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.8.7",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# Don't generate repo files
|
||||
.gitignore
|
||||
.npmignore
|
||||
.openapi-generator-ignore
|
||||
git_push.sh
|
||||
|
||||
# Don't overwrite our custom index.ts
|
||||
index.ts
|
|
@ -1,4 +0,0 @@
|
|||
api.ts
|
||||
base.ts
|
||||
common.ts
|
||||
configuration.ts
|
|
@ -1 +0,0 @@
|
|||
6.5.0
|
232
src/api.ts
232
src/api.ts
|
@ -1,232 +0,0 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* SCUBA
|
||||
* Scality Consumption Utilization and Billing API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from './configuration';
|
||||
import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import globalAxios from 'axios';
|
||||
// Some imports not used depending on template conditions
|
||||
// @ts-ignore
|
||||
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
|
||||
import type { RequestArgs } from './base';
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError } from './base';
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface MetricsClass
|
||||
*/
|
||||
export interface MetricsClass {
|
||||
}
|
||||
|
||||
/**
|
||||
* ScubaApi - axios parameter creator
|
||||
* @export
|
||||
*/
|
||||
export const ScubaApiAxiosParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @param {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getLatestMetrics: async (metricsClass: MetricsClass, resourceName: any, body?: any, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'metricsClass' is not null or undefined
|
||||
assertParamExists('getLatestMetrics', 'metricsClass', metricsClass)
|
||||
// verify required parameter 'resourceName' is not null or undefined
|
||||
assertParamExists('getLatestMetrics', 'resourceName', resourceName)
|
||||
const localVarPath = `/metrics/{metricsClass}/{resourceName}/latest`
|
||||
.replace(`{${"metricsClass"}}`, encodeURIComponent(String(metricsClass)))
|
||||
.replace(`{${"resourceName"}}`, encodeURIComponent(String(resourceName)));
|
||||
// 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 {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} metricsDate
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getMetrics: async (metricsClass: MetricsClass, resourceName: any, metricsDate: any, body?: any, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'metricsClass' is not null or undefined
|
||||
assertParamExists('getMetrics', '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}/{resourceName}/{metricsDate}`
|
||||
.replace(`{${"metricsClass"}}`, encodeURIComponent(String(metricsClass)))
|
||||
.replace(`{${"resourceName"}}`, encodeURIComponent(String(resourceName)))
|
||||
.replace(`{${"metricsDate"}}`, encodeURIComponent(String(metricsDate)));
|
||||
// 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,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* ScubaApi - functional programming interface
|
||||
* @export
|
||||
*/
|
||||
export const ScubaApiFp = function(configuration?: Configuration) {
|
||||
const localVarAxiosParamCreator = ScubaApiAxiosParamCreator(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @param {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async getLatestMetrics(metricsClass: MetricsClass, resourceName: any, body?: any, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.getLatestMetrics(metricsClass, resourceName, body, options);
|
||||
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 getMetrics(metricsClass: MetricsClass, resourceName: any, metricsDate: any, body?: any, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.getMetrics(metricsClass, resourceName, metricsDate, body, options);
|
||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* ScubaApi - factory interface
|
||||
* @export
|
||||
*/
|
||||
export const ScubaApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
||||
const localVarFp = ScubaApiFp(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @param {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getLatestMetrics(metricsClass: MetricsClass, resourceName: any, body?: any, options?: any): AxiosPromise<void> {
|
||||
return localVarFp.getLatestMetrics(metricsClass, resourceName, body, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} metricsDate
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getMetrics(metricsClass: MetricsClass, resourceName: any, metricsDate: any, body?: any, options?: any): AxiosPromise<void> {
|
||||
return localVarFp.getMetrics(metricsClass, resourceName, metricsDate, body, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* ScubaApi - object-oriented interface
|
||||
* @export
|
||||
* @class ScubaApi
|
||||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class ScubaApi extends BaseAPI {
|
||||
/**
|
||||
*
|
||||
* @param {MetricsClass} metricsClass
|
||||
* @param {any} resourceName
|
||||
* @param {any} [body]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof ScubaApi
|
||||
*/
|
||||
public getLatestMetrics(metricsClass: MetricsClass, resourceName: any, body?: any, options?: AxiosRequestConfig) {
|
||||
return ScubaApiFp(this.configuration).getLatestMetrics(metricsClass, resourceName, body, options).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 getMetrics(metricsClass: MetricsClass, resourceName: any, metricsDate: any, body?: any, options?: AxiosRequestConfig) {
|
||||
return ScubaApiFp(this.configuration).getMetrics(metricsClass, resourceName, metricsDate, body, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
72
src/base.ts
72
src/base.ts
|
@ -1,72 +0,0 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* SCUBA
|
||||
* Scality Consumption Utilization and Billing API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from './configuration';
|
||||
// Some imports not used depending on template conditions
|
||||
// @ts-ignore
|
||||
import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import globalAxios from 'axios';
|
||||
|
||||
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface RequestArgs
|
||||
*/
|
||||
export interface RequestArgs {
|
||||
url: string;
|
||||
options: AxiosRequestConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class BaseAPI
|
||||
*/
|
||||
export class BaseAPI {
|
||||
protected configuration: Configuration | undefined;
|
||||
|
||||
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
this.basePath = configuration.basePath || this.basePath;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class RequiredError
|
||||
* @extends {Error}
|
||||
*/
|
||||
export class RequiredError extends Error {
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
this.name = "RequiredError"
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
import { Configuration, ConfigurationParameters } from './configuration';
|
||||
import { ScubaApi } from './api';
|
||||
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
export type MetricsClass = 'account' | 'bucket' | 'service';
|
||||
|
||||
export type ScubaClientParameters = Omit<
|
||||
ConfigurationParameters,
|
||||
'username' | 'password' | 'accessToken' | 'formDataCtor'
|
||||
> & {
|
||||
host?: string;
|
||||
port?: number;
|
||||
useHttps?: boolean;
|
||||
key?: string;
|
||||
cert?: string;
|
||||
ca?: string;
|
||||
keepAlive?: boolean;
|
||||
};
|
||||
|
||||
export type ScubaMetrics = {
|
||||
objectsTotal: number;
|
||||
bytesTotal: number;
|
||||
metricClass: string;
|
||||
resourceName: string;
|
||||
};
|
||||
|
||||
function lpad(num: number, digits: number) {
|
||||
return num.toString().padStart(digits, '0');
|
||||
}
|
||||
|
||||
export default class ScubaClient {
|
||||
private _api: ScubaApi;
|
||||
private _defaultReqOptions: { httpAgent: http.Agent; httpsAgent: https.Agent };
|
||||
|
||||
constructor(params?: ScubaClientParameters) {
|
||||
const { basePath, host, port, useHttps, key, cert, ca, keepAlive } = params || {};
|
||||
const proto = useHttps ? 'https' : 'http';
|
||||
const _host = host || 'localhost';
|
||||
const _port = port || 8100;
|
||||
const _basePath = basePath || '';
|
||||
const connectionString = `${proto}://${_host}:${_port}${_basePath}`;
|
||||
|
||||
this._defaultReqOptions = {
|
||||
httpAgent: new http.Agent({ keepAlive: keepAlive || false }),
|
||||
httpsAgent: new https.Agent({
|
||||
keepAlive: keepAlive || false,
|
||||
cert: cert ? cert : undefined,
|
||||
key: key ? key : undefined,
|
||||
ca: ca ? [ca] : undefined,
|
||||
}),
|
||||
};
|
||||
|
||||
// If basePath is a FQDN then it overrides the baked in config from the spec
|
||||
this._api = new ScubaApi(new Configuration({ ...params, basePath: connectionString }));
|
||||
}
|
||||
|
||||
async getLatestMetrics(
|
||||
metricsClass: MetricsClass,
|
||||
resourceName: string,
|
||||
options?: AxiosRequestConfig,
|
||||
): Promise<ScubaMetrics> {
|
||||
const resp = (await this._api.getLatestMetrics(metricsClass, resourceName, undefined, {
|
||||
...this._defaultReqOptions,
|
||||
...options,
|
||||
})) as any;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
async getMetrics(
|
||||
metricsClass: MetricsClass,
|
||||
resourceName: string,
|
||||
date: Date,
|
||||
options?: AxiosRequestConfig,
|
||||
): Promise<ScubaMetrics> {
|
||||
const year = lpad(date.getFullYear(), 4);
|
||||
const month = lpad(date.getMonth(), 2);
|
||||
const day = lpad(date.getDate(), 2);
|
||||
const dateString = `${year}${month}${day}`;
|
||||
const resp = (await this._api.getMetrics(metricsClass, resourceName, dateString, undefined, {
|
||||
...this._defaultReqOptions,
|
||||
...options,
|
||||
})) as any;
|
||||
return resp.data;
|
||||
}
|
||||
}
|
150
src/common.ts
150
src/common.ts
|
@ -1,150 +0,0 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* SCUBA
|
||||
* Scality Consumption Utilization and Billing API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from "./configuration";
|
||||
import type { RequestArgs } from "./base";
|
||||
import type { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import { RequiredError } from "./base";
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const DUMMY_BASE_URL = 'https://example.com'
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws {RequiredError}
|
||||
* @export
|
||||
*/
|
||||
export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
|
||||
if (paramValue === null || paramValue === undefined) {
|
||||
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
|
||||
if (configuration && configuration.apiKey) {
|
||||
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
|
||||
? await configuration.apiKey(keyParamName)
|
||||
: await configuration.apiKey;
|
||||
object[keyParamName] = localVarApiKeyValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
|
||||
if (configuration && (configuration.username || configuration.password)) {
|
||||
object["auth"] = { username: configuration.username, password: configuration.password };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
|
||||
if (configuration && configuration.accessToken) {
|
||||
const accessToken = typeof configuration.accessToken === 'function'
|
||||
? await configuration.accessToken()
|
||||
: await configuration.accessToken;
|
||||
object["Authorization"] = "Bearer " + accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
|
||||
if (configuration && configuration.accessToken) {
|
||||
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
|
||||
? await configuration.accessToken(name, scopes)
|
||||
: await configuration.accessToken;
|
||||
object["Authorization"] = "Bearer " + localVarAccessTokenValue;
|
||||
}
|
||||
}
|
||||
|
||||
function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
|
||||
if (parameter == null) return;
|
||||
if (typeof parameter === "object") {
|
||||
if (Array.isArray(parameter)) {
|
||||
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
||||
}
|
||||
else {
|
||||
Object.keys(parameter).forEach(currentKey =>
|
||||
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (urlSearchParams.has(key)) {
|
||||
urlSearchParams.append(key, parameter);
|
||||
}
|
||||
else {
|
||||
urlSearchParams.set(key, parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const setSearchParams = function (url: URL, ...objects: any[]) {
|
||||
const searchParams = new URLSearchParams(url.search);
|
||||
setFlattenedQueryParams(searchParams, objects);
|
||||
url.search = searchParams.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
|
||||
const nonString = typeof value !== 'string';
|
||||
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
||||
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
||||
: nonString;
|
||||
return needsSerialization
|
||||
? JSON.stringify(value !== undefined ? value : {})
|
||||
: (value || "");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const toPathString = function (url: URL) {
|
||||
return url.pathname + url.search + url.hash
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
|
||||
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
||||
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
|
||||
return axios.request<T, R>(axiosRequestArgs);
|
||||
};
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* SCUBA
|
||||
* Scality Consumption Utilization and Billing API
|
||||
*
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
||||
basePath?: string;
|
||||
baseOptions?: any;
|
||||
formDataCtor?: new () => any;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
/**
|
||||
* base options for axios calls
|
||||
*
|
||||
* @type {any}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
baseOptions?: any;
|
||||
/**
|
||||
* The FormData constructor that will be used to create multipart form data
|
||||
* requests. You can inject this here so that execution environments that
|
||||
* do not support the FormData class can still run the generated client.
|
||||
*
|
||||
* @type {new () => FormData}
|
||||
*/
|
||||
formDataCtor?: new () => any;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
this.baseOptions = param.baseOptions;
|
||||
this.formDataCtor = param.formDataCtor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given MIME is a JSON MIME.
|
||||
* JSON MIME examples:
|
||||
* application/json
|
||||
* application/json; charset=UTF8
|
||||
* APPLICATION/JSON
|
||||
* application/vnd.company+json
|
||||
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
||||
* @return True if the given MIME is JSON, false otherwise.
|
||||
*/
|
||||
public isJsonMime(mime: string): boolean {
|
||||
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
||||
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
export * from './client';
|
||||
export { default as ScubaClient } from './client';
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./lib",
|
||||
"allowJs": false,
|
||||
"target": "es2016",
|
||||
"alwaysStrict": true,
|
||||
"skipLibCheck": false,
|
||||
"module": "commonjs",
|
||||
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
},
|
||||
"include": [
|
||||
"src/*.ts",
|
||||
"src/*/*.ts",
|
||||
"index.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"tests"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue