Skip to content

Commit

Permalink
feat: Add codemie integration page (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik committed Aug 1, 2024
1 parent 8c5b694 commit f20494a
Show file tree
Hide file tree
Showing 194 changed files with 2,757 additions and 397 deletions.
7 changes: 0 additions & 7 deletions src/constants/delays.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/k8s/groups/EDP/Codebase/hooks/useCodebaseCRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CRUD_TYPES } from '../../../../../constants/crudTypes';
import { useResourceCRUDMutation } from '../../../../../hooks/useResourceCRUDMutation';
import { EDPKubeObjectInterface } from '../../../../../types/k8s';
import { CodebaseAuthData } from '../../../../../widgets/CreateEditCodebase/types';
import { createCodebaseSecretInstance } from '../../../default/Secret/utils/createCodebaseSecretInstance';
import { CodebaseKubeObject } from '../index';
import { CodebaseKubeObjectInterface } from '../types';
import { createCodebaseSecretInstance } from '../utils/createCodebaseSecretInstance';

interface CreateCodebaseProps {
codebaseData: CodebaseKubeObjectInterface;
Expand Down
11 changes: 11 additions & 0 deletions src/k8s/groups/EDP/Codemie/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { KubeObjectConfig } from '../../../../types/configs/k8s';

export const CodemieKubeObjectConfig: KubeObjectConfig = {
kind: 'Codemie',
name: {
singularForm: 'codemie',
pluralForm: 'codemies',
},
group: 'edp.epam.com',
version: 'v1alpha1',
};
21 changes: 21 additions & 0 deletions src/k8s/groups/EDP/Codemie/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiProxy, K8s } from '@kinvolk/headlamp-plugin/lib';
import { CodemieKubeObjectConfig } from './config';
import { CodemieKubeObjectInterface } from './types';

const {
name: { singularForm, pluralForm },
group,
version,
} = CodemieKubeObjectConfig;

export class CodemieKubeObject extends K8s.cluster.makeKubeObject<CodemieKubeObjectInterface>(singularForm) {
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);

static get className(): string {
return singularForm;
}

get spec(): CodemieKubeObjectInterface['spec'] {
return this.jsonData!.spec;
}
}
15 changes: 15 additions & 0 deletions src/k8s/groups/EDP/Codemie/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { KubeObjectInterface } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';

export interface CodemieKubeObjectInterface extends KubeObjectInterface {
spec: {
oidc: {
secretRef: {
clientKey: string;
secretKey: string;
name: string;
};
tokenEndpoint: string;
};
url: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CODEMIE_FORM_NAMES } from '../../../../../../widgets/ManageCodeMie/names';
import { createCodemieInstance } from './index';

describe('testing createCodemieInstance', () => {
it('should return valid kube object', () => {
const object = createCodemieInstance(CODEMIE_FORM_NAMES, {
name: 'codemie',
tokenEndpoint: 'test-token-endpoint',
apiUrl: 'test-api-url',
});

expect(object).toMatchObject({
apiVersion: 'edp.epam.com/v1alpha1',
kind: 'Codemie',
metadata: { name: 'codemie' },
spec: {
oidc: {
secretRef: {
name: 'codemie',
clientKey: 'client_id',
secretKey: 'client_secret',
},
tokenEndpoint: 'test-token-endpoint',
},
url: 'test-api-url',
},
});
});
});
41 changes: 41 additions & 0 deletions src/k8s/groups/EDP/Codemie/utils/createCodemieInstance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { set } from 'lodash';
import { FormNameObject } from '../../../../../../types/forms';
import { DeepPartial } from '../../../../../../types/global';
import { CodemieFormValues } from '../../../../../../widgets/ManageCodeMie/types';
import { CodemieKubeObjectConfig } from '../../config';
import { CodemieKubeObjectInterface } from '../../types';

const { kind, group, version } = CodemieKubeObjectConfig;

export const createCodemieInstance = (
names: {
[key: string]: FormNameObject;
},
formValues: CodemieFormValues
): CodemieKubeObjectInterface => {
const { name, ...restProps } = formValues;

const base: DeepPartial<CodemieKubeObjectInterface> = {
apiVersion: `${group}/${version}`,
kind,
metadata: {
name: name,
},
spec: {
oidc: {
secretRef: {
name,
clientKey: 'client_id',
secretKey: 'client_secret',
},
},
},
};

for (const [propKey, propValue] of Object.entries(restProps)) {
const propPath = names[propKey].path;
set(base, propPath, propValue);
}

return base as CodemieKubeObjectInterface;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CODEMIE_SECRET_FORM_NAMES } from '../../../../../../widgets/ManageCodeMie/names';
import {
SECRET_LABEL_ASSOCIATED_KIND,
SECRET_LABEL_SECRET_TYPE,
} from '../../../../default/Secret/labels';
import { CodemieKubeObjectConfig } from '../../config';
import { createCodemieSecretInstance } from './index';

describe('testing createCodemieSecretInstance', () => {
it('should return valid kube object', () => {
const object = createCodemieSecretInstance(CODEMIE_SECRET_FORM_NAMES, {
name: 'codemie',
clientId: 'test-client-id',
clientSecret: 'test-client-secret',
});

expect(object).toMatchObject({
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name: 'codemie',
labels: {
[SECRET_LABEL_SECRET_TYPE]: 'codemie',
[SECRET_LABEL_ASSOCIATED_KIND]: CodemieKubeObjectConfig.kind,
},
},
type: 'Opaque',
data: {
client_id: 'dGVzdC1jbGllbnQtaWQ=',
client_secret: 'dGVzdC1jbGllbnQtc2VjcmV0',
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { set } from 'lodash';
import { FormNameObject } from '../../../../../../types/forms';
import { DeepPartial } from '../../../../../../types/global';
import { EDPKubeObjectInterface } from '../../../../../../types/k8s';
import { safeEncode } from '../../../../../../utils/decodeEncode';
import { CodemieSecretFormValues } from '../../../../../../widgets/ManageCodeMie/types';
import {
SECRET_LABEL_ASSOCIATED_KIND,
SECRET_LABEL_SECRET_TYPE,
} from '../../../../default/Secret/labels';
import { CodemieKubeObjectConfig } from '../../config';

export const createCodemieSecretInstance = (
names: {
[key: string]: FormNameObject;
},
formValues: CodemieSecretFormValues
): DeepPartial<EDPKubeObjectInterface> => {
const { clientId, clientSecret, name, ...restProps } = formValues;

const base: DeepPartial<EDPKubeObjectInterface> = {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
name,
labels: {
[SECRET_LABEL_SECRET_TYPE]: 'codemie',
[SECRET_LABEL_ASSOCIATED_KIND]: CodemieKubeObjectConfig.kind,
},
},
data: {
client_id: safeEncode(clientId),
client_secret: safeEncode(clientSecret),
},
type: 'Opaque',
};

for (const [propKey, propValue] of Object.entries(restProps)) {
const propPath = names[propKey].path;
set(base, propPath, propValue);
}

return base;
};
11 changes: 11 additions & 0 deletions src/k8s/groups/EDP/CodemieProject/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { KubeObjectConfig } from '../../../../types/configs/k8s';

export const CodemieProjectKubeObjectConfig: KubeObjectConfig = {
kind: 'CodemieProject',
name: {
singularForm: 'codemieproject',
pluralForm: 'codemieprojects',
},
group: 'edp.epam.com',
version: 'v1alpha1',
};
21 changes: 21 additions & 0 deletions src/k8s/groups/EDP/CodemieProject/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiProxy, K8s } from '@kinvolk/headlamp-plugin/lib';
import { CodemieProjectKubeObjectConfig } from './config';
import { CodemieProjectKubeObjectInterface } from './types';

const {
name: { singularForm, pluralForm },
group,
version,
} = CodemieProjectKubeObjectConfig;

export class CodemieProjectKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectKubeObjectInterface>(singularForm) {
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);

static get className(): string {
return singularForm;
}

get spec(): CodemieProjectKubeObjectInterface['spec'] {
return this.jsonData!.spec;
}
}
11 changes: 11 additions & 0 deletions src/k8s/groups/EDP/CodemieProject/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { KubeObjectInterface } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';

export interface CodemieProjectKubeObjectInterface extends KubeObjectInterface {
spec: {
codemieRef: {
kind: 'Codemie';
name: string;
};
name: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CODEMIE_PROJECT_FORM_NAMES } from '../../../../../../widgets/ManageCodeMie/names';
import { createCodemieProjectInstance } from './index';

describe('testing createCodemieProjectInstance', () => {
it('should return valid kube object', () => {
const object = createCodemieProjectInstance(CODEMIE_PROJECT_FORM_NAMES, {
projectName: 'test-project-name',
codemieRefName: 'codemie',
});

expect(object).toMatchObject({
apiVersion: 'edp.epam.com/v1alpha1',
kind: 'CodemieProject',
metadata: { name: 'test-project-name' },
spec: {
name: 'test-project-name',
codemieRef: { kind: 'Codemie', name: 'codemie' },
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { set } from 'lodash';
import { FormNameObject } from '../../../../../../types/forms';
import { DeepPartial } from '../../../../../../types/global';
import { CodemieProjectFormValues } from '../../../../../../widgets/ManageCodeMie/types';
import { CodemieProjectKubeObjectConfig } from '../../config';
import { CodemieProjectKubeObjectInterface } from '../../types';

const { kind, group, version } = CodemieProjectKubeObjectConfig;

export const createCodemieProjectInstance = (
names: {
[key: string]: FormNameObject;
},
formValues: CodemieProjectFormValues
): CodemieProjectKubeObjectInterface => {
const { projectName, ...restProps } = formValues;

const base: DeepPartial<CodemieProjectKubeObjectInterface> = {
apiVersion: `${group}/${version}`,
kind,
metadata: {
name: projectName,
},
spec: {
name: projectName,
codemieRef: {
kind: 'Codemie',
},
},
};

for (const [propKey, propValue] of Object.entries(restProps)) {
const propPath = names[propKey].path;
set(base, propPath, propValue);
}

return base as CodemieProjectKubeObjectInterface;
};
11 changes: 11 additions & 0 deletions src/k8s/groups/EDP/CodemieProjectSettings/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { KubeObjectConfig } from '../../../../types/configs/k8s';

export const CodemieProjectSettingsKubeObjectConfig: KubeObjectConfig = {
kind: 'CodemieProjectSettings',
name: {
singularForm: 'codemieprojectsettings',
pluralForm: 'codemieprojectsettings',
},
group: 'edp.epam.com',
version: 'v1alpha1',
};
23 changes: 23 additions & 0 deletions src/k8s/groups/EDP/CodemieProjectSettings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ApiProxy, K8s } from '@kinvolk/headlamp-plugin/lib';
import { CodemieProjectSettingsKubeObjectConfig } from './config';
import { CodemieProjectSettingsKubeObjectInterface } from './types';

const {
name: { singularForm, pluralForm },
group,
version,
} = CodemieProjectSettingsKubeObjectConfig;

export class CodemieProjectSettingsKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectSettingsKubeObjectInterface>(
singularForm
) {
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);

static get className(): string {
return singularForm;
}

get spec(): CodemieProjectSettingsKubeObjectInterface['spec'] {
return this.jsonData!.spec;
}
}
21 changes: 21 additions & 0 deletions src/k8s/groups/EDP/CodemieProjectSettings/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { KubeObjectInterface } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';

export interface CodemieProjectSettingsKubeObjectInterface extends KubeObjectInterface {
spec: {
alias: string;
codemieRef: {
kind: string;
name: string;
};
gitCredential: {
secretRef: {
name: string;
secretKey: string;
};
tokenName: string;
url: string;
};
projectName: string;
type: string;
};
}
Loading

0 comments on commit f20494a

Please sign in to comment.