| 1 | import { ApiProperty } from '@nestjs/swagger'; |
| 2 | import { IsOptional, IsString |
| 3 | |
| 4 | /** An 8192-bit RSA key with a long comment still fits inside this several times over. */ |
| 5 | export const MAX_PUBLIC_KEY_LENGTH = |
| 6 | |
| 7 | export const MAX_TITLE_LENGTH = |
| 8 | |
| 9 | export class AddSshKeyDTO |
| 10 | @ApiProperty({ |
| 11 | description: |
| 12 | 'One authorized_keys line, as `~/.ssh/id_ed25519.pub` holds it.', |
| 13 | example: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... laptop', |
| 14 | maxLength: MAX_PUBLIC_KEY_LENGTH, |
| 15 | }) |
| 16 | @IsString() |
| 17 | @MaxLength(MAX_PUBLIC_KEY_LENGTH) |
| 18 | publicKey: string; |
| 19 | |
| 20 | @ApiProperty({ |
| 21 | description: |
| 22 | "What to call the key. Defaults to the key's own comment, then to its type.", |
| 23 | required: false, |
| 24 | maxLength: MAX_TITLE_LENGTH, |
| 25 | }) |
| 26 | @IsOptional() |
| 27 | @IsString() |
| 28 | @MaxLength(MAX_TITLE_LENGTH) |
| 29 | title?: string |
| 30 | } |
| 31 | |
| 32 | export class SshKeyDTO |
| 33 | @ApiProperty() |
| 34 | id: string; |
| 35 | |
| 36 | @ApiProperty({ description |
| 37 | title: string; |
| 38 | |
| 39 | @ApiProperty({ description |
| 40 | type: string; |
| 41 | |
| 42 | @ApiProperty({ |
| 43 | description: 'SHA256 fingerprint, base64, as `ssh-keygen -lf` prints it.', |
| 44 | }) |
| 45 | fingerprint: string; |
| 46 | |
| 47 | @ApiProperty({ |
| 48 | description: 'When the key last authenticated a git session, ISO 8601.', |
| 49 | nullable: true, |
| 50 | }) |
| 51 | lastUsedAt: string |
| 52 | |
| 53 | @ApiProperty({ description |
| 54 | createdAt: string; |
| 55 | } |
| 56 | |
| 57 | export class ListSshKeysResponseDTO |
| 58 | @ApiProperty({ type |
| 59 | keys: SshKeyDTO |
| 60 | } |