Skip to content

Commit

Permalink
fix(api): Secrets with empty names (#738)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajdip Bhattacharya <agentR47@gmail.com>
  • Loading branch information
csehatt741 and rajdip-b authored Feb 11, 2025
1 parent dd89d57 commit 5e9c57f
Show file tree
Hide file tree
Showing 3 changed files with 1,229 additions and 1,165 deletions.
7 changes: 7 additions & 0 deletions apps/api/src/decorators/trim-string.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Transform } from 'class-transformer'

export function TrimString() {
return Transform(({ value }) =>
typeof value === 'string' ? value?.trim() : value
)
}
84 changes: 45 additions & 39 deletions apps/api/src/secret/dto/create.secret/create.secret.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import 'reflect-metadata'
import { Transform, Type } from 'class-transformer'
import {
IsArray,
IsOptional,
IsString,
Length,
ValidateNested
} from 'class-validator'

export class CreateSecret {
@IsString()
name: string

@IsString()
@IsOptional()
@Length(0, 100)
note?: string

@IsString()
@IsOptional()
rotateAfter?: '24' | '168' | '720' | '8760' | 'never' = 'never'

@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => Entry)
entries?: Entry[]
}

class Entry {
@IsString()
@Transform(({ value }) => value.trim())
environmentSlug: string

@IsString()
@Transform(({ value }) => value.trim())
value: string
}
import 'reflect-metadata'
import { Transform, Type } from 'class-transformer'
import {
IsArray,
IsNotEmpty,
IsOptional,
IsString,
Length,
ValidateNested
} from 'class-validator'
import { TrimString } from '@/decorators/trim-string.decorator'

export class CreateSecret {
@IsString()
@IsNotEmpty()
@TrimString()
name: string

@IsString()
@IsOptional()
@Length(0, 100)
note?: string

@IsString()
@IsOptional()
rotateAfter?: '24' | '168' | '720' | '8760' | 'never' = 'never'

@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => Entry)
entries?: Entry[]
}

class Entry {
@IsString()
@IsNotEmpty()
@TrimString()
environmentSlug: string

@IsString()
@IsNotEmpty()
@TrimString()
value: string
}
Loading

0 comments on commit 5e9c57f

Please sign in to comment.