From 090ed19a26d8d79185b341d993059a6a04544595 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 28 Feb 2023 11:26:20 +0800 Subject: [PATCH] feat: add supports for initialize preset plugins --- ...pi-console-halo-run-v1alpha1-plugin-api.ts | 223 ++++++++++++++---- packages/api-client/src/base.ts | 2 +- .../api-client/src/models/plugin-status.ts | 6 + src/views/system/Setup.vue | 25 ++ 4 files changed, 215 insertions(+), 41 deletions(-) diff --git a/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts b/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts index 5b183b96..65fc98f3 100644 --- a/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts +++ b/packages/api-client/src/api/api-console-halo-run-v1alpha1-plugin-api.ts @@ -129,13 +129,18 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con }, /** * Install a plugin by uploading a Jar file. - * @param {File} file + * @param {File} [file] + * @param {string} [source] Install source. Default is file. + * @param {string} [presetName] Plugin preset name. We will find the plugin from plugin presets * @param {*} [options] Override http request option. * @throws {RequiredError} */ - installPlugin: async (file: File, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'file' is not null or undefined - assertParamExists('installPlugin', 'file', file) + installPlugin: async ( + file?: File, + source?: string, + presetName?: string, + options: AxiosRequestConfig = {}, + ): Promise => { const localVarPath = `/apis/api.console.halo.run/v1alpha1/plugins/install` // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) @@ -161,6 +166,14 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con localVarFormParams.append('file', file as any) } + if (source !== undefined) { + localVarFormParams.append('source', source as any) + } + + if (presetName !== undefined) { + localVarFormParams.append('presetName', presetName as any) + } + localVarHeaderParameter['Content-Type'] = 'multipart/form-data' setSearchParams(localVarUrlObj, localVarQueryParameter) @@ -173,15 +186,50 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con options: localVarRequestOptions, } }, + /** + * List all plugin presets in the system. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listPluginPresets: async (options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/apis/api.console.halo.run/v1alpha1/plugin-presets` + // 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: 'GET', ...baseOptions, ...options } + const localVarHeaderParameter = {} as any + const localVarQueryParameter = {} as any + + // authentication BasicAuth required + // http basic authentication required + setBasicAuthToObject(localVarRequestOptions, configuration) + + // authentication BearerAuth required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + setSearchParams(localVarUrlObj, localVarQueryParameter) + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {} + localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers } + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + } + }, /** * List plugins using query criteria and sort params * @param {Array} [sort] Sort property and direction of the list result. Supported fields: creationTimestamp * @param {string} [keyword] Keyword of plugin name or description * @param {boolean} [enabled] Whether the plugin is enabled * @param {number} [size] Size of one page. Zero indicates no limit. - * @param {number} [page] The page number. Zero indicates no page. * @param {Array} [labelSelector] Label selector for filtering. * @param {Array} [fieldSelector] Field selector for filtering. + * @param {number} [page] The page number. Zero indicates no page. * @param {*} [options] Override http request option. * @throws {RequiredError} */ @@ -190,9 +238,9 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con keyword?: string, enabled?: boolean, size?: number, - page?: number, labelSelector?: Array, fieldSelector?: Array, + page?: number, options: AxiosRequestConfig = {}, ): Promise => { const localVarPath = `/apis/api.console.halo.run/v1alpha1/plugins` @@ -231,10 +279,6 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con localVarQueryParameter['size'] = size } - if (page !== undefined) { - localVarQueryParameter['page'] = page - } - if (labelSelector) { localVarQueryParameter['labelSelector'] = labelSelector } @@ -243,6 +287,10 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con localVarQueryParameter['fieldSelector'] = fieldSelector } + if (page !== undefined) { + localVarQueryParameter['page'] = page + } + setSearchParams(localVarUrlObj, localVarQueryParameter) let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {} localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers } @@ -347,15 +395,21 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con /** * Upgrade a plugin by uploading a Jar file * @param {string} name - * @param {File} file + * @param {File} [file] + * @param {string} [source] Install source. Default is file. + * @param {string} [presetName] Plugin preset name. We will find the plugin from plugin presets * @param {*} [options] Override http request option. * @throws {RequiredError} */ - upgradePlugin: async (name: string, file: File, options: AxiosRequestConfig = {}): Promise => { + upgradePlugin: async ( + name: string, + file?: File, + source?: string, + presetName?: string, + options: AxiosRequestConfig = {}, + ): Promise => { // verify required parameter 'name' is not null or undefined assertParamExists('upgradePlugin', 'name', name) - // verify required parameter 'file' is not null or undefined - assertParamExists('upgradePlugin', 'file', file) const localVarPath = `/apis/api.console.halo.run/v1alpha1/plugins/{name}/upgrade`.replace( `{${'name'}}`, encodeURIComponent(String(name)), @@ -384,6 +438,14 @@ export const ApiConsoleHaloRunV1alpha1PluginApiAxiosParamCreator = function (con localVarFormParams.append('file', file as any) } + if (source !== undefined) { + localVarFormParams.append('source', source as any) + } + + if (presetName !== undefined) { + localVarFormParams.append('presetName', presetName as any) + } + localVarHeaderParameter['Content-Type'] = 'multipart/form-data' setSearchParams(localVarUrlObj, localVarQueryParameter) @@ -434,15 +496,30 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (configuration?: Co }, /** * Install a plugin by uploading a Jar file. - * @param {File} file + * @param {File} [file] + * @param {string} [source] Install source. Default is file. + * @param {string} [presetName] Plugin preset name. We will find the plugin from plugin presets * @param {*} [options] Override http request option. * @throws {RequiredError} */ async installPlugin( - file: File, + file?: File, + source?: string, + presetName?: string, options?: AxiosRequestConfig, ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.installPlugin(file, options) + const localVarAxiosArgs = await localVarAxiosParamCreator.installPlugin(file, source, presetName, options) + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration) + }, + /** + * List all plugin presets in the system. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listPluginPresets( + options?: AxiosRequestConfig, + ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.listPluginPresets(options) return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration) }, /** @@ -451,9 +528,9 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (configuration?: Co * @param {string} [keyword] Keyword of plugin name or description * @param {boolean} [enabled] Whether the plugin is enabled * @param {number} [size] Size of one page. Zero indicates no limit. - * @param {number} [page] The page number. Zero indicates no page. * @param {Array} [labelSelector] Label selector for filtering. * @param {Array} [fieldSelector] Field selector for filtering. + * @param {number} [page] The page number. Zero indicates no page. * @param {*} [options] Override http request option. * @throws {RequiredError} */ @@ -462,9 +539,9 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (configuration?: Co keyword?: string, enabled?: boolean, size?: number, - page?: number, labelSelector?: Array, fieldSelector?: Array, + page?: number, options?: AxiosRequestConfig, ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.listPlugins( @@ -472,9 +549,9 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (configuration?: Co keyword, enabled, size, - page, labelSelector, fieldSelector, + page, options, ) return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration) @@ -510,16 +587,20 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFp = function (configuration?: Co /** * Upgrade a plugin by uploading a Jar file * @param {string} name - * @param {File} file + * @param {File} [file] + * @param {string} [source] Install source. Default is file. + * @param {string} [presetName] Plugin preset name. We will find the plugin from plugin presets * @param {*} [options] Override http request option. * @throws {RequiredError} */ async upgradePlugin( name: string, - file: File, + file?: File, + source?: string, + presetName?: string, options?: AxiosRequestConfig, ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.upgradePlugin(name, file, options) + const localVarAxiosArgs = await localVarAxiosParamCreator.upgradePlugin(name, file, source, presetName, options) return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration) }, } @@ -567,10 +648,20 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFactory = function ( * @throws {RequiredError} */ installPlugin( - requestParameters: ApiConsoleHaloRunV1alpha1PluginApiInstallPluginRequest, + requestParameters: ApiConsoleHaloRunV1alpha1PluginApiInstallPluginRequest = {}, options?: AxiosRequestConfig, ): AxiosPromise { - return localVarFp.installPlugin(requestParameters.file, options).then((request) => request(axios, basePath)) + return localVarFp + .installPlugin(requestParameters.file, requestParameters.source, requestParameters.presetName, options) + .then((request) => request(axios, basePath)) + }, + /** + * List all plugin presets in the system. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listPluginPresets(options?: AxiosRequestConfig): AxiosPromise> { + return localVarFp.listPluginPresets(options).then((request) => request(axios, basePath)) }, /** * List plugins using query criteria and sort params @@ -588,9 +679,9 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFactory = function ( requestParameters.keyword, requestParameters.enabled, requestParameters.size, - requestParameters.page, requestParameters.labelSelector, requestParameters.fieldSelector, + requestParameters.page, options, ) .then((request) => request(axios, basePath)) @@ -632,7 +723,13 @@ export const ApiConsoleHaloRunV1alpha1PluginApiFactory = function ( options?: AxiosRequestConfig, ): AxiosPromise { return localVarFp - .upgradePlugin(requestParameters.name, requestParameters.file, options) + .upgradePlugin( + requestParameters.name, + requestParameters.file, + requestParameters.source, + requestParameters.presetName, + options, + ) .then((request) => request(axios, basePath)) }, } @@ -677,7 +774,21 @@ export interface ApiConsoleHaloRunV1alpha1PluginApiInstallPluginRequest { * @type {File} * @memberof ApiConsoleHaloRunV1alpha1PluginApiInstallPlugin */ - readonly file: File + readonly file?: File + + /** + * Install source. Default is file. + * @type {string} + * @memberof ApiConsoleHaloRunV1alpha1PluginApiInstallPlugin + */ + readonly source?: string + + /** + * Plugin preset name. We will find the plugin from plugin presets + * @type {string} + * @memberof ApiConsoleHaloRunV1alpha1PluginApiInstallPlugin + */ + readonly presetName?: string } /** @@ -714,13 +825,6 @@ export interface ApiConsoleHaloRunV1alpha1PluginApiListPluginsRequest { */ readonly size?: number - /** - * The page number. Zero indicates no page. - * @type {number} - * @memberof ApiConsoleHaloRunV1alpha1PluginApiListPlugins - */ - readonly page?: number - /** * Label selector for filtering. * @type {Array} @@ -734,6 +838,13 @@ export interface ApiConsoleHaloRunV1alpha1PluginApiListPluginsRequest { * @memberof ApiConsoleHaloRunV1alpha1PluginApiListPlugins */ readonly fieldSelector?: Array + + /** + * The page number. Zero indicates no page. + * @type {number} + * @memberof ApiConsoleHaloRunV1alpha1PluginApiListPlugins + */ + readonly page?: number } /** @@ -789,7 +900,21 @@ export interface ApiConsoleHaloRunV1alpha1PluginApiUpgradePluginRequest { * @type {File} * @memberof ApiConsoleHaloRunV1alpha1PluginApiUpgradePlugin */ - readonly file: File + readonly file?: File + + /** + * Install source. Default is file. + * @type {string} + * @memberof ApiConsoleHaloRunV1alpha1PluginApiUpgradePlugin + */ + readonly source?: string + + /** + * Plugin preset name. We will find the plugin from plugin presets + * @type {string} + * @memberof ApiConsoleHaloRunV1alpha1PluginApiUpgradePlugin + */ + readonly presetName?: string } /** @@ -839,11 +964,23 @@ export class ApiConsoleHaloRunV1alpha1PluginApi extends BaseAPI { * @memberof ApiConsoleHaloRunV1alpha1PluginApi */ public installPlugin( - requestParameters: ApiConsoleHaloRunV1alpha1PluginApiInstallPluginRequest, + requestParameters: ApiConsoleHaloRunV1alpha1PluginApiInstallPluginRequest = {}, options?: AxiosRequestConfig, ) { return ApiConsoleHaloRunV1alpha1PluginApiFp(this.configuration) - .installPlugin(requestParameters.file, options) + .installPlugin(requestParameters.file, requestParameters.source, requestParameters.presetName, options) + .then((request) => request(this.axios, this.basePath)) + } + + /** + * List all plugin presets in the system. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleHaloRunV1alpha1PluginApi + */ + public listPluginPresets(options?: AxiosRequestConfig) { + return ApiConsoleHaloRunV1alpha1PluginApiFp(this.configuration) + .listPluginPresets(options) .then((request) => request(this.axios, this.basePath)) } @@ -864,9 +1001,9 @@ export class ApiConsoleHaloRunV1alpha1PluginApi extends BaseAPI { requestParameters.keyword, requestParameters.enabled, requestParameters.size, - requestParameters.page, requestParameters.labelSelector, requestParameters.fieldSelector, + requestParameters.page, options, ) .then((request) => request(this.axios, this.basePath)) @@ -916,7 +1053,13 @@ export class ApiConsoleHaloRunV1alpha1PluginApi extends BaseAPI { options?: AxiosRequestConfig, ) { return ApiConsoleHaloRunV1alpha1PluginApiFp(this.configuration) - .upgradePlugin(requestParameters.name, requestParameters.file, options) + .upgradePlugin( + requestParameters.name, + requestParameters.file, + requestParameters.source, + requestParameters.presetName, + options, + ) .then((request) => request(this.axios, this.basePath)) } } diff --git a/packages/api-client/src/base.ts b/packages/api-client/src/base.ts index b62944c9..b57a438f 100644 --- a/packages/api-client/src/base.ts +++ b/packages/api-client/src/base.ts @@ -18,7 +18,7 @@ import type { Configuration } from './configuration' import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios' import globalAxios from 'axios' -export const BASE_PATH = 'http://localhost:8090'.replace(/\/+$/, '') +export const BASE_PATH = 'http://127.0.0.1:8090'.replace(/\/+$/, '') /** * diff --git a/packages/api-client/src/models/plugin-status.ts b/packages/api-client/src/models/plugin-status.ts index b32abd1b..220e94f9 100644 --- a/packages/api-client/src/models/plugin-status.ts +++ b/packages/api-client/src/models/plugin-status.ts @@ -58,6 +58,12 @@ export interface PluginStatus { * @memberof PluginStatus */ logo?: string + /** + * Load location of the plugin, often a path. + * @type {string} + * @memberof PluginStatus + */ + loadLocation?: string } export const PluginStatusPhaseEnum = { diff --git a/src/views/system/Setup.vue b/src/views/system/Setup.vue index 5e87ef46..f8c12642 100644 --- a/src/views/system/Setup.vue +++ b/src/views/system/Setup.vue @@ -83,6 +83,31 @@ const handleSubmit = async () => { await Promise.all(menuItemPromises); await apiClient.extension.menu.createv1alpha1Menu({ menu: menu }); + // Install preset plugins + const { data: presetPlugins } = await apiClient.plugin.listPluginPresets(); + const installPluginPromises = presetPlugins.map((plugin) => { + return apiClient.plugin.installPlugin({ + source: "PRESET", + presetName: plugin.metadata.name as string, + }); + }); + const installPluginResponses = await Promise.all(installPluginPromises); + + await Promise.all( + installPluginResponses.map((response) => { + return apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ + name: response.data.metadata.name as string, + plugin: { + ...response.data, + spec: { + ...response.data.spec, + enabled: true, + }, + }, + }); + }) + ); + // Create system-states ConfigMap await apiClient.extension.configMap.createv1alpha1ConfigMap({ configMap: {