Skip to content

Commit

Permalink
Merge branch 'develop' into cli/secret-hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Feb 4, 2025
2 parents e8a6720 + d1b9767 commit bde376f
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 99 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [2.11.0-stage.11](https://github.com/keyshade-xyz/keyshade/compare/v2.11.0-stage.10...v2.11.0-stage.11) (2025-02-04)

### 🐛 Bug Fixes

* **api:** Project hard sync existing entities deleted ([#660](https://github.com/keyshade-xyz/keyshade/issues/660)) ([3632217](https://github.com/keyshade-xyz/keyshade/commit/36322175290723089b8bd9a1a479925efd00f6f1))

## [2.11.0-stage.10](https://github.com/keyshade-xyz/keyshade/compare/v2.11.0-stage.9...v2.11.0-stage.10) (2025-02-04)

### 🚀 Features

* **api:** Workspace-membership invitationAccepted included ([#665](https://github.com/keyshade-xyz/keyshade/issues/665)) ([3877249](https://github.com/keyshade-xyz/keyshade/commit/38772498be229c8d83c8a99c395dded9e0a6ef7f))

## [2.11.0-stage.9](https://github.com/keyshade-xyz/keyshade/compare/v2.11.0-stage.8...v2.11.0-stage.9) (2025-01-31)

### 🚀 Features
Expand Down
186 changes: 93 additions & 93 deletions apps/api/src/environment/environment.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,99 +475,99 @@ describe('Environment Controller Tests', () => {
)
})

it('should be able to get the count of secrets and variables in an environment', async () => {
// Add secrets to the environment
const secret1 = await secretService.createSecret(
user1,
{
name: 'Secret 1',
entries: [
{
value: 'Secret 1 value',
environmentSlug: environment1.slug
}
]
},
project1.slug
)
await secretService.createSecret(
user1,
{
name: 'Secret 2',
entries: [
{
value: 'Secret 2 value',
environmentSlug: environment1.slug
}
]
},
project1.slug
)

// Add variables to the environment
const variable1 = await variableService.createVariable(
user1,
{
name: 'Variable 1',
entries: [
{
value: 'Variable 1 value',
environmentSlug: environment1.slug
}
]
},
project1.slug
)
await variableService.createVariable(
user1,
{
name: 'Variable 2',
entries: [
{
value: 'Variable 2 value',
environmentSlug: environment1.slug
}
]
},
project1.slug
)

// Update the value of a secret to add a SecretVersion
await secretService.updateSecret(user1, secret1.secret.slug, {
entries: [
{
value: 'Updated Secret 1 value',
environmentSlug: environment1.slug
}
]
})

// Update the value of a variable to add a VariableVersion
await variableService.updateVariable(user1, variable1.variable.slug, {
entries: [
{
value: 'Updated Variable 1 value',
environmentSlug: environment1.slug
}
]
})

const response = await app.inject({
method: 'GET',
url: `/environment/all/${project1.slug}?page=0&limit=10`,
headers: {
'x-e2e-user-email': user1.email
}
})

expect(response.statusCode).toBe(200)
const devEnvironment = response
.json()
.items.find((env: Environment) => env.slug === environment1.slug)

expect(devEnvironment.secrets).toBe(2)
expect(devEnvironment.variables).toBe(2)
})
// it('should be able to get the count of secrets and variables in an environment', async () => {
// // Add secrets to the environment
// const secret1 = await secretService.createSecret(
// user1,
// {
// name: 'Secret 1',
// entries: [
// {
// value: 'Secret 1 value',
// environmentSlug: environment1.slug
// }
// ]
// },
// project1.slug
// )
// await secretService.createSecret(
// user1,
// {
// name: 'Secret 2',
// entries: [
// {
// value: 'Secret 2 value',
// environmentSlug: environment1.slug
// }
// ]
// },
// project1.slug
// )

// // Add variables to the environment
// const variable1 = await variableService.createVariable(
// user1,
// {
// name: 'Variable 1',
// entries: [
// {
// value: 'Variable 1 value',
// environmentSlug: environment1.slug
// }
// ]
// },
// project1.slug
// )
// await variableService.createVariable(
// user1,
// {
// name: 'Variable 2',
// entries: [
// {
// value: 'Variable 2 value',
// environmentSlug: environment1.slug
// }
// ]
// },
// project1.slug
// )

// // Update the value of a secret to add a SecretVersion
// await secretService.updateSecret(user1, secret1.secret.slug, {
// entries: [
// {
// value: 'Updated Secret 1 value',
// environmentSlug: environment1.slug
// }
// ]
// })

// // Update the value of a variable to add a VariableVersion
// await variableService.updateVariable(user1, variable1.variable.slug, {
// entries: [
// {
// value: 'Updated Variable 1 value',
// environmentSlug: environment1.slug
// }
// ]
// })

// const response = await app.inject({
// method: 'GET',
// url: `/environment/all/${project1.slug}?page=0&limit=10`,
// headers: {
// 'x-e2e-user-email': user1.email
// }
// })

// expect(response.statusCode).toBe(200)
// const devEnvironment = response
// .json()
// .items.find((env: Environment) => env.slug === environment1.slug)

// expect(devEnvironment.secrets).toBe(2)
// expect(devEnvironment.variables).toBe(2)
// })

it('should not be able to fetch all environments of a project that does not exist', async () => {
const response = await app.inject({
Expand Down
36 changes: 35 additions & 1 deletion apps/api/src/project/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,11 @@ export class ProjectService {
// hardCopy = false: Only add those items in the toProject that are not already present in it
hardCopy: boolean = false
) {
// This field will be populated if hardCopy is true
// When we are doing a hard copy, we need to delete all the
// items in the toProject that are already present in it
const deleteOps = []

// Get all the environments that belongs to the parent project
// and replicate them for the new project
const createEnvironmentOps = []
Expand Down Expand Up @@ -964,6 +969,30 @@ export class ProjectService {
variables.forEach((variable) => {
toProjectVariables.add(variable.name)
})
} else {
deleteOps.push(
this.prisma.environment.deleteMany({
where: {
projectId: toProject.id
}
})
)

deleteOps.push(
this.prisma.secret.deleteMany({
where: {
projectId: toProject.id
}
})
)

deleteOps.push(
this.prisma.variable.deleteMany({
where: {
projectId: toProject.id
}
})
)
}

// We want to find all such environments in the fromProject that
Expand Down Expand Up @@ -1117,7 +1146,12 @@ export class ProjectService {
)
}

return [...createEnvironmentOps, ...createSecretOps, ...createVariableOps]
return [
...deleteOps,
...createEnvironmentOps,
...createSecretOps,
...createVariableOps
]
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ export class WorkspaceMembershipService {
}
}
}
}
},
invitationAccepted: true
}
})

Expand Down
14 changes: 12 additions & 2 deletions apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,18 @@ describe('Workspace Membership Controller Tests', () => {
})

expect(response.statusCode).toBe(200)
expect(response.json().items).toBeInstanceOf(Array)
expect(response.json().items).toHaveLength(1)

const workspaceMembers = response.json().items

expect(workspaceMembers).toBeInstanceOf(Array)
expect(workspaceMembers).toHaveLength(1)

const workspaceMember = workspaceMembers[0]

expect(workspaceMember.id).toBeDefined()
expect(workspaceMember.user).toBeDefined()
expect(workspaceMember.roles).toBeDefined()
expect(workspaceMember.invitationAccepted).toBeDefined()

//check metadata
const metadata = response.json().metadata
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ These are the options supported by the `sync` command:

#### `-h, --hard-sync`

Upserts a new copy of the parent onto the child. Defaults to soft sync.
Force the child to match the parent by discarding all changes in the child. Defaults to soft sync.

## `unlink`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keyshade-xyz",
"version": "2.11.0-stage.9",
"version": "2.11.0-stage.11",
"license": "MPL-2.0",
"private": true,
"engineStrict": false,
Expand Down

0 comments on commit bde376f

Please sign in to comment.