From 10fcbd2e6c00d63d124b24e2907dac0c74ad127c Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Fri, 7 Apr 2023 08:48:09 -0500 Subject: [PATCH] mustache template adjustments --- configuration.ts | 217 --------------------------- index.ts | 19 +-- sdk-resources/api.mustache | 2 +- sdk-resources/baseApi.mustache | 2 +- sdk-resources/common.mustache | 2 +- sdk-resources/configuration.mustache | 38 +---- 6 files changed, 11 insertions(+), 269 deletions(-) delete mode 100644 configuration.ts diff --git a/configuration.ts b/configuration.ts deleted file mode 100644 index c2e60169..00000000 --- a/configuration.ts +++ /dev/null @@ -1,217 +0,0 @@ -import axios from "axios"; -import * as os from 'os'; -import * as path from 'path'; -import * as yaml from "js-yaml"; -import * as fs from "fs"; -import { IAxiosRetryConfig } from "axios-retry"; - -export interface ConfigurationParameters { - baseurl?: string; - clientId?: string; - clientSecret?: string; - accessToken?: string; - tokenUrl?: string; -} - -export interface Configuration { - activeenvironment?: string; - authtype?: string; - customexporttemplatespath?: string; - customsearchtemplatespath?: string; - debug?: boolean; - environments?: {[key: string]: Environment}; -} - -export interface Environment { - baseurl: string; - pat: Pat; - tenanturl: string; -} - -export interface Pat { - clientid: string; - clientsecret: string; -} - -export class Configuration { - - /** - * parameter for apiKey security - * @param name security name - * @memberof Configuration - */ - apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); - - /** - * parameter for clientId - * - * @type {string} - * @memberof Configuration - */ - clientId?: string; - /** - * parameter for clientSecret - * - * @type {string} - * @memberof Configuration - */ - clientSecret?: string; - /** - * parameter for clientSecret - * - * @type {string} - * @memberof Configuration - */ - /** - * parameter for oauth2 security - * @param name security name - * @param scopes oauth2 scope - * @memberof Configuration - */ - accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); - - /** - * parameter for clientId - * - * @type {string} - * @memberof Configuration - */ - tokenUrl?: string; - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - username?: string; - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - password?: string; - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePathBeta?: string; - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePathV3?: string; - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePathV2?: string; - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePathCC?: 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; - /** - * axios retry configuration - * - * @type {IAxiosRetryConfig} - * @memberof Configuration - */ - retriesConfig?: IAxiosRetryConfig - - constructor(param?: ConfigurationParameters) { - - if (!param) { - param = this.getParams() - } - - this.basePathBeta = param.baseurl + `/beta` - this.basePathV3 = param.baseurl + `/v3` - this.basePathV2 = param.baseurl + `/v2` - this.basePathCC = param.baseurl - this.tokenUrl = param.tokenUrl - this.clientId = param.clientId; - this.clientSecret = param.clientSecret; - const url = `${this.tokenUrl}?grant_type=client_credentials&client_id=${this.clientId}&client_secret=${this.clientSecret}`; - if (!this.accessToken) { - this.accessToken = this.getAccessToken(url); - } - - } - - private getParams(): ConfigurationParameters { - const config: ConfigurationParameters = {} - try { - const homeDir = os.homedir() - const configPath = path.join(homeDir, '.sailpoint','config.yaml') - const doc = yaml.load(fs.readFileSync(configPath, 'utf8')) as Configuration - if (doc.authtype && doc.authtype.toLowerCase() === 'pat') { - config.baseurl = doc.environments[doc.activeenvironment].baseurl - config.clientId = doc.environments[doc.activeenvironment].pat.clientid - config.clientSecret = doc.environments[doc.activeenvironment].pat.clientsecret - } - } catch (error) { - console.log('unable to find config file') - } - config.baseurl = process.env["SAIL_BASE_URL"] ? process.env["BASE_URL"] : config.baseurl - config.clientId = process.env["SAIL_CLIENT_ID"] ? process.env["CLIENT_ID"] : config.clientId - config.clientSecret = process.env["SAIL_CLIENT_SECRET"] ? process.env["CLIENT_SECRET"] : config.clientSecret - - config.tokenUrl = config.baseurl + '/oauth/token' - - return config - } - - private async getAccessToken(url: string): Promise { - try { - const {data, status} = await axios.post(url) - if (status === 200) { - return data.access_token; - } else { - throw new Error("Unauthorized") - } - } catch (error) { - console.error("Unable to fetch access token. Aborting."); - throw new Error(error); - } - } - - - /** - * 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'); - } -} diff --git a/index.ts b/index.ts index 6c712a8a..b1008a8f 100644 --- a/index.ts +++ b/index.ts @@ -1,23 +1,6 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * IdentityNow V3 API - * Use these APIs to interact with the IdentityNow platform to achieve repeatable, automated processes with greater scalability. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs. - * - * The version of the OpenAPI document: 3.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - export * from "./sdk-output/api"; -export {Configuration as ConfigurationBeta, ConfigurationParameters as ConfigurationParameter} from "./sdk-output/configuration"; -export {Configuration, ConfigurationParameters} from "./configuration"; +export {Configuration, ConfigurationParameters} from "./sdk-output/configuration"; export * from "./paginator"; diff --git a/sdk-resources/api.mustache b/sdk-resources/api.mustache index 2335ea54..707faf3a 100644 --- a/sdk-resources/api.mustache +++ b/sdk-resources/api.mustache @@ -3,7 +3,7 @@ {{>licenseInfo}} {{^withSeparateModelsAndApi}} -import { Configuration } from '../configuration'; +import { Configuration } from './configuration'; import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; {{#withNodeImports}} // URLSearchParams not necessarily used diff --git a/sdk-resources/baseApi.mustache b/sdk-resources/baseApi.mustache index 1642d4b8..500fab4d 100644 --- a/sdk-resources/baseApi.mustache +++ b/sdk-resources/baseApi.mustache @@ -2,7 +2,7 @@ /* eslint-disable */ {{>licenseInfo}} -import { Configuration } from "../configuration"; +import { Configuration } from "./configuration"; // Some imports not used depending on template conditions // @ts-ignore import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; diff --git a/sdk-resources/common.mustache b/sdk-resources/common.mustache index 8016864b..2e113c30 100644 --- a/sdk-resources/common.mustache +++ b/sdk-resources/common.mustache @@ -2,7 +2,7 @@ /* eslint-disable */ {{>licenseInfo}} -import { Configuration } from "../configuration"; +import { Configuration } from "./configuration"; import { RequiredError, RequestArgs } from "./base"; import { AxiosInstance, AxiosResponse } from 'axios'; import axiosRetry from "axios-retry"; diff --git a/sdk-resources/configuration.mustache b/sdk-resources/configuration.mustache index 7c8eca18..2f927265 100644 --- a/sdk-resources/configuration.mustache +++ b/sdk-resources/configuration.mustache @@ -3,13 +3,10 @@ {{>licenseInfo}} export interface ConfigurationParameters { + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); - username?: string; - password?: string; - accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); basePath?: string; - baseOptions?: any; - formDataCtor?: new () => any; + } export class Configuration { @@ -19,27 +16,7 @@ export class Configuration { * @memberof Configuration */ apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); - /** - * 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 | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + /** * override base path * @@ -47,6 +24,7 @@ export class Configuration { * @memberof Configuration */ basePath?: string; + /** * base options for axios calls * @@ -54,6 +32,7 @@ export class Configuration { * @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 @@ -64,13 +43,10 @@ export class Configuration { 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; + } /**