Skip to content

Commit

Permalink
Merge pull request #1496 from cloud-pi-native/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ArnaudTA authored Jan 8, 2025
2 parents 5b0fd4c + 1f393f1 commit e15a02a
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 57 deletions.
4 changes: 2 additions & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"@fastify/session": "^10.9.0",
"@fastify/swagger": "^8.15.0",
"@fastify/swagger-ui": "^4.2.0",
"@gitbeaker/core": "^41.3.0",
"@gitbeaker/rest": "^41.3.0",
"@gitbeaker/core": "~40.6.0",
"@gitbeaker/rest": "~40.6.0",
"@kubernetes-models/argo-cd": "^2.6.2",
"@kubernetes/client-node": "^0.22.3",
"@prisma/client": "^6.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Project" ADD COLUMN "lastSuccessProvisionningVersion" TEXT;
40 changes: 21 additions & 19 deletions apps/server/src/prisma/schema/project.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,27 @@ model ProjectRole {
}

model Project {
id String @id @unique @default(uuid()) @db.Uuid
name String
organizationId String @db.Uuid
description String @default("")
status ProjectStatus @default(initializing)
locked Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
everyonePerms BigInt @default(896)
ownerId String @db.Uuid
environments Environment[]
logs Log[]
organization Organization @relation(fields: [organizationId], references: [id])
owner User @relation(fields: [ownerId], references: [id])
members ProjectMembers[]
plugins ProjectPlugin[]
roles ProjectRole[]
repositories Repository[]
clusters Cluster[] @relation("ClusterToProject")
id String @id @unique @default(uuid()) @db.Uuid
name String
organizationId String @db.Uuid
description String @default("")
status ProjectStatus @default(initializing)
locked Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
everyonePerms BigInt @default(896)
ownerId String @db.Uuid
environments Environment[]
logs Log[]
organization Organization @relation(fields: [organizationId], references: [id])
owner User @relation(fields: [ownerId], references: [id])
members ProjectMembers[]
plugins ProjectPlugin[]
roles ProjectRole[]
repositories Repository[]
clusters Cluster[] @relation("ClusterToProject")
lastSuccessProvisionningVersion String?
}

enum ProjectStatus {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/resources/log/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function addLogs({ action, data, requestId, userId = null, projectId }: A
data: {
action,
userId,
data: exclude(data, ['cluster', 'user', 'newCreds']),
data: exclude(data, ['cluster', 'user', 'newCreds', 'apis']),
requestId,
projectId,
},
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/utils/hook-wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ describe('transformToHookProject', () => {
stage: stage.name,
permissions: [{ permissions: { rw: true, ro: true }, userId: project.ownerId }],
...environment,
apis: {},
})))

// Assert sur la transformation des repositories
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/utils/hook-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export function transformToHookProject(project: ProjectInfos, store: Store, repo
})),
],
...environment,
apis: {},
})),
repositories: project.repositories.map(repo => ({ ...repo, newCreds: reposCreds[repo.internalRepoName] })),
store,
Expand Down
5 changes: 5 additions & 0 deletions packages/hooks/src/hooks/hook-project.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PluginApi } from '@/utils/utils.js'
import type { Hook } from './hook.js'
import { createHook } from './hook.js'
import type { ClusterObject, ExternalRepoUrl, InternalRepoName, IsInfra, IsPrivate, UserObject } from './index.js'
Expand All @@ -17,6 +18,9 @@ export interface Role {
role: 'owner' | 'user'
}

export interface EnvironmentApis {
[x: string]: PluginApi
}
export interface Environment {
id: string
name: string
Expand All @@ -30,6 +34,7 @@ export interface Environment {
rw: boolean
}
}[]
apis: EnvironmentApis
}

export interface Repository {
Expand Down
6 changes: 3 additions & 3 deletions plugins/gitlab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@cpn-console/hooks": "workspace:^",
"@cpn-console/shared": "workspace:^",
"@cpn-console/vault-plugin": "workspace:^",
"@gitbeaker/core": "^41.3.0",
"@gitbeaker/requester-utils": "^41.3.0",
"@gitbeaker/rest": "^41.3.0",
"@gitbeaker/core": "~40.6.0",
"@gitbeaker/requester-utils": "~40.6.0",
"@gitbeaker/rest": "~40.6.0",
"axios": "^1.7.9",
"js-yaml": "4.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cpn-console/kubernetes-plugin",
"type": "module",
"version": "2.0.7",
"version": "2.1.0",
"private": false,
"description": "",
"main": "dist/index.js",
Expand Down
8 changes: 4 additions & 4 deletions plugins/kubernetes/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class KubernetesNamespace {
anyObjectApi: AnyObjectsApi | undefined
apisApi: ApisApi | undefined

constructor(organizationName: string, projectName: string, environmentName: string, owner: UserObject, cluster: ClusterObject, projectId: string) {
constructor(organizationName: string, projectName: string, environment: Environment, owner: UserObject, cluster: ClusterObject, projectId: string) {
this.coreV1Api = createCoreV1Api(cluster)
this.apisApi = createApisApi(cluster)
this.anyObjectApi = createCustomObjectApi(cluster)
this.nsObjectExpected = getNsObject(organizationName, projectName, environmentName, owner, cluster.zone.slug, projectId)
this.nsObject = getNsObject(organizationName, projectName, environmentName, owner, cluster.zone.slug, projectId)
this.nsObjectExpected = getNsObject(organizationName, projectName, environment, owner, cluster.zone.slug, projectId)
this.nsObject = getNsObject(organizationName, projectName, environment, owner, cluster.zone.slug, projectId)
}

public async create() {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class KubernetesProjectApi<GProject extends Project> extends PluginApi {
const owner = project.owner
this.namespaces = project.environments.reduce((acc, env) => {
const cluster = project.clusters.find(cluster => cluster.id === env.clusterId) as ClusterObject
acc[env.name] = new KubernetesNamespace(project.organization.name, project.name, env.name, owner, cluster, project.id)
acc[env.name] = new KubernetesNamespace(project.organization.name, project.name, env, owner, cluster, project.id)
return acc
}, {} as Record<Environment['name'], KubernetesNamespace>)
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/kubernetes/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHmac } from 'node:crypto'
import { Namespace } from 'kubernetes-models/v1'
import type { Project, ProjectLite, StepCall, UserObject } from '@cpn-console/hooks'
import type { Environment, Project, ProjectLite, StepCall, UserObject } from '@cpn-console/hooks'
import { parseError } from '@cpn-console/hooks'
import type { CoreV1Api, V1NamespaceList } from '@kubernetes/client-node'
import { createCoreV1Api } from './api.js'
Expand Down Expand Up @@ -83,19 +83,19 @@ export const deleteNamespaces: StepCall<Project> = async (payload) => {
}

// Utils
export function getNsObject(organization: string, project: string, environment: string, owner: UserObject, zone: string, projectId: string): V1NamespacePopulated {
export function getNsObject(organization: string, project: string, environment: Environment, owner: UserObject, zone: string, projectId: string): V1NamespacePopulated {
const nsObject = new Namespace({
metadata: {
name: generateNamespaceName(organization, project, environment),
name: generateNamespaceName(organization, project, environment.name),
labels: {
'dso/organization': organization,
'dso/projet': project,
'dso/project': project,
'dso/environment': environment,
'dso/environment': environment.name,
'dso/owner.id': owner.id,
'app.kubernetes.io/managed-by': 'dso-console',
'dso/zone': zone,
'dso/project.id': projectId,
'dso/environment.id': environment.id,
},
},
})
Expand Down
4 changes: 4 additions & 0 deletions plugins/nexus/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const deleteNexusProject: StepCall<Project> = async ({ args: project }) =
result: 'OK',
message: 'Project deleted from Nexus',
},
store: {
activateNpmRepo: 'disabled',
activateMavenRepo: 'disabled',
},
}
} catch (error) {
return {
Expand Down
44 changes: 22 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e15a02a

Please sign in to comment.