diff --git a/packages/dashboard-backend/src/routes/api/helpers/getCertificateAuthority.ts b/packages/dashboard-backend/src/routes/api/helpers/getCertificateAuthority.ts index 2fa3b45303..30f7d8dc41 100644 --- a/packages/dashboard-backend/src/routes/api/helpers/getCertificateAuthority.ts +++ b/packages/dashboard-backend/src/routes/api/helpers/getCertificateAuthority.ts @@ -15,19 +15,12 @@ import path from 'path'; import * as axios from 'axios'; import https from 'https'; -export interface ICrtConfig { - ssCrtPath?: string; - publicCrtPath?: string; -} - -const DEFAULT_CHE_SELF_SIGNED_MOUNT_PATH = '/public-certs/che-self-signed'; +const DEFAULT_CHE_SELF_SIGNED_MOUNT_PATH = '/public-certs'; const CHE_SELF_SIGNED_MOUNT_PATH = process.env.CHE_SELF_SIGNED_MOUNT_PATH; -const certificateAuthority = getCertificateAuthority({ - publicCrtPath: CHE_SELF_SIGNED_MOUNT_PATH - ? CHE_SELF_SIGNED_MOUNT_PATH - : DEFAULT_CHE_SELF_SIGNED_MOUNT_PATH, -}); +const certificateAuthority = getCertificateAuthority( + CHE_SELF_SIGNED_MOUNT_PATH ? CHE_SELF_SIGNED_MOUNT_PATH : DEFAULT_CHE_SELF_SIGNED_MOUNT_PATH, +); export const axiosInstance = certificateAuthority ? axios.default.create({ @@ -37,21 +30,46 @@ export const axiosInstance = certificateAuthority }) : axios.default; -function getCertificateAuthority(config: ICrtConfig): Buffer[] | undefined { - const certificateAuthority: Buffer[] = []; - if (config.ssCrtPath && fs.existsSync(config.ssCrtPath)) { - certificateAuthority.push(fs.readFileSync(config.ssCrtPath)); - } +function searchCertificate( + certPath: string, + certificateAuthority: Buffer[], + subdirLevel = 1, +): void { + const maxSubdirQuantity = 10; + const maxSubdirLevel = 5; - if (config.publicCrtPath && fs.existsSync(config.publicCrtPath)) { - const publicCertificates = fs.readdirSync(config.publicCrtPath); + const tmpPaths: string[] = []; + try { + const publicCertificates = fs.readdirSync(certPath); for (const publicCertificate of publicCertificates) { - if (publicCertificate.endsWith('.crt')) { - const certPath = path.join(config.publicCrtPath, publicCertificate); - certificateAuthority.push(fs.readFileSync(certPath)); + const newPath = path.join(certPath, publicCertificate); + if (fs.lstatSync(newPath).isDirectory()) { + if (tmpPaths.length < maxSubdirQuantity) { + tmpPaths.push(newPath); + } + } else { + const fullPath = path.join(certPath, publicCertificate); + certificateAuthority.push(fs.readFileSync(fullPath)); } } + } catch (e) { + // no-op + } + + if (subdirLevel < maxSubdirLevel) { + for (const path of tmpPaths) { + searchCertificate(path, certificateAuthority, ++subdirLevel); + } + } +} + +function getCertificateAuthority(certPath: string): Buffer[] | undefined { + if (!fs.existsSync(certPath)) { + return undefined; } + const certificateAuthority: Buffer[] = []; + searchCertificate(certPath, certificateAuthority); + return certificateAuthority.length > 0 ? certificateAuthority : undefined; } diff --git a/packages/dashboard-frontend/src/containers/Loader/Factory/Steps/Apply/Devfile/index.tsx b/packages/dashboard-frontend/src/containers/Loader/Factory/Steps/Apply/Devfile/index.tsx index c2d427b9e5..58e1a99aa4 100644 --- a/packages/dashboard-frontend/src/containers/Loader/Factory/Steps/Apply/Devfile/index.tsx +++ b/packages/dashboard-frontend/src/containers/Loader/Factory/Steps/Apply/Devfile/index.tsx @@ -282,9 +282,12 @@ class StepApplyDevfile extends AbstractLoaderStep { } private async createWorkspaceFromDevfile(devfile: devfileApi.Devfile): Promise { - const params = Object.fromEntries(this.props.searchParams); const optionalFilesContent = this.props.factoryResolver?.optionalFilesContent || {}; - await this.props.createWorkspaceFromDevfile(devfile, params, optionalFilesContent); + await this.props.createWorkspaceFromDevfile( + devfile, + this.state.factoryParams, + optionalFilesContent, + ); } private handleCreateWorkspaceError(): void { diff --git a/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx b/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx index f8243078cd..c431cc69b3 100644 --- a/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx +++ b/packages/dashboard-frontend/src/pages/GetStarted/__tests__/GetStarted.spec.tsx @@ -93,7 +93,7 @@ describe('Quick Add page', () => { devfileButton.click(); expect(createWorkspaceFromDevfileMock).toHaveBeenCalledWith(dummyDevfile, { - stackName: 'dummyStackName', + factoryId: 'dummyStackName', }); }); diff --git a/packages/dashboard-frontend/src/pages/GetStarted/index.tsx b/packages/dashboard-frontend/src/pages/GetStarted/index.tsx index d563eb2c8b..f512e02b14 100644 --- a/packages/dashboard-frontend/src/pages/GetStarted/index.tsx +++ b/packages/dashboard-frontend/src/pages/GetStarted/index.tsx @@ -37,6 +37,7 @@ import { selectWorkspaceByQualifiedName } from '../../store/Workspaces/selectors import { selectDefaultNamespace } from '../../store/InfrastructureNamespaces/selectors'; import getRandomString from '../../services/helpers/random'; import devfileApi from '../../services/devfileApi'; +import { FactoryParams } from '../../containers/Loader/buildFactoryParams'; const SamplesListTab = React.lazy(() => import('./GetStartedTab')); @@ -116,9 +117,9 @@ export class GetStarted extends React.PureComponent { [fileName: string]: string; }, ): Promise { - const attr: { [key: string]: string } = {}; + const attr: Partial = {}; if (stackName) { - attr.stackName = stackName; + attr.factoryId = stackName; } if (isCheDevfile(devfile) && !devfile.metadata.name && devfile.metadata.generateName) { const name = devfile.metadata.generateName + getRandomString(4).toLowerCase(); @@ -130,8 +131,12 @@ export class GetStarted extends React.PureComponent { : this.props.defaultNamespace.name; let workspace: Workspace | undefined; try { - await this.props.createWorkspaceFromDevfile(devfile, attr, optionalFilesContent); - this.props.setWorkspaceQualifiedName(namespace, devfile.metadata.name as string); + await this.props.createWorkspaceFromDevfile( + devfile, + attr as FactoryParams, + optionalFilesContent, + ); + this.props.setWorkspaceQualifiedName(namespace, devfile.metadata.name); workspace = this.props.activeWorkspace; } catch (e) { const errorMessage = common.helpers.errors.getMessage(e); diff --git a/packages/dashboard-frontend/src/services/workspace-client/helpers.ts b/packages/dashboard-frontend/src/services/workspace-client/helpers.ts index dc72ba6540..024a197941 100644 --- a/packages/dashboard-frontend/src/services/workspace-client/helpers.ts +++ b/packages/dashboard-frontend/src/services/workspace-client/helpers.ts @@ -11,12 +11,10 @@ */ import common from '@eclipse-che/common'; -import axios from 'axios'; import devfileApi from '../devfileApi'; import { load, dump } from 'js-yaml'; import { ICheEditorYaml } from './devworkspace/devWorkspaceClient'; import { CHE_EDITOR_YAML_PATH } from './'; -import { EDITOR_ATTR } from '../../containers/Loader/const'; import { AppState } from '../../store'; import { ThunkDispatch } from 'redux-thunk'; import { KnownAction } from '../../store/DevfileRegistries'; diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts index e62c7ad65d..2563d918ab 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/__tests__/actions.spec.ts @@ -30,6 +30,7 @@ import { DevWorkspaceBuilder } from '../../../__mocks__/devWorkspaceBuilder'; import { FakeStoreBuilder } from '../../../__mocks__/storeBuilder'; import { checkRunningWorkspacesLimit } from '../checkRunningWorkspacesLimit'; import { dump } from 'js-yaml'; +import { FactoryParams } from "../../../../containers/Loader/buildFactoryParams"; jest.mock('../../../../services/dashboard-backend-client/serverConfigApi'); jest.mock('../../../../services/helpers/delay', () => ({ @@ -636,11 +637,14 @@ describe('DevWorkspace store, actions', () => { namespace: 'user-che', }, }; + const attr: Partial = {}; mockCreateDevWorkspace.mockResolvedValueOnce({ devWorkspace, headers: {} }); mockUpdateDevWorkspace.mockResolvedValueOnce({ devWorkspace, headers: {} }); - await store.dispatch(testStore.actionCreators.createWorkspaceFromDevfile(devfile, {}, {})); + await store.dispatch( + testStore.actionCreators.createWorkspaceFromDevfile(devfile, attr as FactoryParams, {}), + ); const actions = store.getActions(); @@ -670,11 +674,14 @@ describe('DevWorkspace store, actions', () => { namespace: 'user-che', }, }; + const attr: Partial = {}; mockCreateDevWorkspace.mockRejectedValueOnce(new Error('Something unexpected happened.')); try { - await store.dispatch(testStore.actionCreators.createWorkspaceFromDevfile(devfile, {}, {})); + await store.dispatch( + testStore.actionCreators.createWorkspaceFromDevfile(devfile, attr as FactoryParams, {}), + ); } catch (e) { // no-op } diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts index 0410d9da06..b6d057fba7 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/index.ts @@ -160,7 +160,7 @@ export type ActionCreators = { updateWorkspace: (workspace: devfileApi.DevWorkspace) => AppThunk>; createWorkspaceFromDevfile: ( devfile: devfileApi.Devfile, - attributes: Partial, + attributes: FactoryParams, optionalFilesContent: { [fileName: string]: string; }, @@ -168,7 +168,7 @@ export type ActionCreators = { createWorkspaceFromResources: ( devWorkspace: devfileApi.DevWorkspace, devWorkspaceTemplate: devfileApi.DevWorkspaceTemplate, - editor?: string, + editorId?: string, ) => AppThunk>; handleWebSocketMessage: ( @@ -574,7 +574,7 @@ export const actionCreators: ActionCreators = { createWorkspaceFromDevfile: ( devfile: devfileApi.Devfile, - attributes: Partial, + attributes: FactoryParams, optionalFilesContent: { [fileName: string]: string; }, diff --git a/packages/dashboard-frontend/src/store/Workspaces/index.ts b/packages/dashboard-frontend/src/store/Workspaces/index.ts index 014d04ab09..31f31a44dd 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/index.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/index.ts @@ -108,7 +108,7 @@ export type ActionCreators = { updateWorkspace: (workspace: Workspace) => AppThunk>; createWorkspaceFromDevfile: ( devfile: devfileApi.Devfile, - attributes: Partial, + attributes: FactoryParams, optionalFilesContent?: { [fileName: string]: string; }, @@ -215,7 +215,7 @@ export const actionCreators: ActionCreators = { createWorkspaceFromDevfile: ( devfile: devfileApi.Devfile, - attributes: Partial, + attributes: FactoryParams, optionalFilesContent?: { [fileName: string]: string; },