Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api,cli,api-client,schema): Make get secret and get variable response to be consistent with their getAll #625

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/validate-platform.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing as of now, so comment out this step

Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ jobs:
- name: Lint
run: |
pnpm run lint:platform

- name: Build
run: |
pnpm run build:platform
26 changes: 26 additions & 0 deletions apps/api/src/common/secret-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Secret } from '@prisma/client'

export interface SecretWithValues {
secret: Secret & { lastUpdatedBy: { id: string; name: string } }
values: Array<{
environment: {
id: string
name: string
slug: string
}
value: string
version: number
}>
}

export function getSecretWithValues(
secretWithVersion: SecretWithValues['secret'] & {
versions: SecretWithValues['values']
}
): SecretWithValues {
const { versions, ...secret } = secretWithVersion
return {
secret,
values: versions
}
}
26 changes: 26 additions & 0 deletions apps/api/src/common/variable-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Variable } from '@prisma/client'

export interface VariableWithValues {
variable: Variable & { lastUpdatedBy: { id: string; name: string } }
values: Array<{
environment: {
id: string
name: string
slug: string
}
value: string
version: number
}>
}

export function getVariableWithValues(
variableWithVersion: VariableWithValues['variable'] & {
versions: VariableWithValues['values']
}
): VariableWithValues {
const { versions, ...variable } = variableWithVersion
return {
variable,
values: versions
}
}
62 changes: 33 additions & 29 deletions apps/api/src/event/event.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,23 @@ describe('Event Controller Tests', () => {
project.slug
)

const secret = await secretService.createSecret(
user,
{
name: 'My secret',
entries: [
{
value: 'My value',
environmentSlug: environment.slug
}
],
note: 'Some note',
rotateAfter: '720'
},
project.slug
)
const secret = (
await secretService.createSecret(
user,
{
name: 'My secret',
entries: [
{
value: 'My value',
environmentSlug: environment.slug
}
],
note: 'Some note',
rotateAfter: '720'
},
project.slug
)
).secret

expect(secret).toBeDefined()

Expand Down Expand Up @@ -360,20 +362,22 @@ describe('Event Controller Tests', () => {
project.slug
)

const variable = (await variableService.createVariable(
user,
{
name: 'My variable',
entries: [
{
value: 'My value',
environmentSlug: environment.slug
}
],
note: 'Some note'
},
project.slug
)) as Variable
const variable = (
await variableService.createVariable(
user,
{
name: 'My variable',
entries: [
{
value: 'My value',
environmentSlug: environment.slug
}
],
note: 'Some note'
},
project.slug
)
).variable as Variable

expect(variable).toBeDefined()

Expand Down
224 changes: 120 additions & 104 deletions apps/api/src/project/project.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,60 +557,68 @@ describe('Project Controller Tests', () => {
)) as Environment

// Add two secrets
;(await secretService.createSecret(
user2,
{
name: 'API_KEY',
entries: [
{
value: 'some_key',
environmentSlug: environment.slug
}
]
},
project4.slug
)) as Secret
;(await secretService.createSecret(
user2,
{
name: 'DB_PASSWORD',
entries: [
{
value: 'password',
environmentSlug: environment.slug
}
]
},
project4.slug
)) as Secret
;(
await secretService.createSecret(
user2,
{
name: 'API_KEY',
entries: [
{
value: 'some_key',
environmentSlug: environment.slug
}
]
},
project4.slug
)
).secret as Secret
;(
await secretService.createSecret(
user2,
{
name: 'DB_PASSWORD',
entries: [
{
value: 'password',
environmentSlug: environment.slug
}
]
},
project4.slug
)
).secret as Secret

// Add two variables
;(await variableService.createVariable(
user2,
{
name: 'PORT',
entries: [
{
value: '8080',
environmentSlug: environment.slug
}
]
},
project4.slug
)) as Variable
;(await variableService.createVariable(
user2,
{
name: 'EXPIRY',
entries: [
{
value: '3600',
environmentSlug: environment.slug
}
]
},
project4.slug
)) as Variable
;(
await variableService.createVariable(
user2,
{
name: 'PORT',
entries: [
{
value: '8080',
environmentSlug: environment.slug
}
]
},
project4.slug
)
).variable as Variable
;(
await variableService.createVariable(
user2,
{
name: 'EXPIRY',
entries: [
{
value: '3600',
environmentSlug: environment.slug
}
]
},
project4.slug
)
).variable as Variable

const response = await app.inject({
method: 'GET',
Expand Down Expand Up @@ -1287,62 +1295,70 @@ describe('Project Controller Tests', () => {
)) as Environment

// Add two secrets
const secret1 = (await secretService.createSecret(
user1,
{
name: 'API_KEY',
entries: [
{
value: 'some_key',
environmentSlug: environment.slug
}
]
},
project3.slug
)) as Secret
const secret1 = (
await secretService.createSecret(
user1,
{
name: 'API_KEY',
entries: [
{
value: 'some_key',
environmentSlug: environment.slug
}
]
},
project3.slug
)
).secret as Secret

const secret2 = (await secretService.createSecret(
user1,
{
name: 'DB_PASSWORD',
entries: [
{
value: 'password',
environmentSlug: environment.slug
}
]
},
project3.slug
)) as Secret
const secret2 = (
await secretService.createSecret(
user1,
{
name: 'DB_PASSWORD',
entries: [
{
value: 'password',
environmentSlug: environment.slug
}
]
},
project3.slug
)
).secret as Secret

// Add two variables
const variable1 = (await variableService.createVariable(
user1,
{
name: 'PORT',
entries: [
{
value: '8080',
environmentSlug: environment.slug
}
]
},
project3.slug
)) as Variable
const variable1 = (
await variableService.createVariable(
user1,
{
name: 'PORT',
entries: [
{
value: '8080',
environmentSlug: environment.slug
}
]
},
project3.slug
)
).variable as Variable

const variable2 = (await variableService.createVariable(
user1,
{
name: 'EXPIRY',
entries: [
{
value: '3600',
environmentSlug: environment.slug
}
]
},
project3.slug
)) as Variable
const variable2 = (
await variableService.createVariable(
user1,
{
name: 'EXPIRY',
entries: [
{
value: '3600',
environmentSlug: environment.slug
}
]
},
project3.slug
)
).variable as Variable

// Try forking the project
const forkedProject = await projectService.forkProject(
Expand Down
Loading
Loading