feat: EC2 UI polished + storage persisting
This commit is contained in:
@@ -214,7 +214,7 @@ describe('ec2Service key pairs', () => {
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test('createKeyPair sends CreateKeyPairCommand and returns material', async () => {
|
||||
test('createKeyPair sends CreateKeyPairCommand with the requested key type and returns material', async () => {
|
||||
const sent: unknown[] = []
|
||||
const client: EC2Client = {
|
||||
send: async (cmd: unknown) => {
|
||||
@@ -222,12 +222,25 @@ describe('ec2Service key pairs', () => {
|
||||
return {KeyPairId: 'kp-1', KeyName: 'my-key', KeyMaterial: '-----BEGIN RSA-----'}
|
||||
},
|
||||
} as unknown as EC2Client
|
||||
const result = await createEc2Service(client).createKeyPair('my-key')
|
||||
const result = await createEc2Service(client).createKeyPair('my-key', 'ed25519')
|
||||
expect(sent[0]).toBeInstanceOf(CreateKeyPairCommand)
|
||||
expect((sent[0] as CreateKeyPairCommand).input).toMatchObject({KeyName: 'my-key', KeyType: 'ed25519'})
|
||||
expect(result.keyName).toBe('my-key')
|
||||
expect(result.keyMaterial).toBe('-----BEGIN RSA-----')
|
||||
})
|
||||
|
||||
test('createKeyPair defaults to rsa', async () => {
|
||||
const sent: CreateKeyPairCommand[] = []
|
||||
const client: EC2Client = {
|
||||
send: async (cmd: CreateKeyPairCommand) => {
|
||||
sent.push(cmd)
|
||||
return {}
|
||||
},
|
||||
} as unknown as EC2Client
|
||||
await createEc2Service(client).createKeyPair('my-key')
|
||||
expect(sent[0].input.KeyType).toBe('rsa')
|
||||
})
|
||||
|
||||
test('deleteKeyPair sends DeleteKeyPairCommand', async () => {
|
||||
const sent: unknown[] = []
|
||||
const client: EC2Client = {send: async (cmd: unknown) => { sent.push(cmd); return {} }} as unknown as EC2Client
|
||||
|
||||
@@ -142,6 +142,8 @@ export type Ec2KeyPairMaterial = {
|
||||
keyMaterial: string
|
||||
}
|
||||
|
||||
export type Ec2KeyPairType = 'rsa' | 'ed25519'
|
||||
|
||||
export type Ec2Vpc = {
|
||||
vpcId: string
|
||||
cidrBlock: string
|
||||
@@ -588,8 +590,8 @@ export function createEc2Service(client: EC2Client = awsClients.ec2) {
|
||||
}
|
||||
},
|
||||
|
||||
async createKeyPair(name: string): Promise<Ec2KeyPairMaterial> {
|
||||
const res = await client.send(new CreateKeyPairCommand({KeyName: name}))
|
||||
async createKeyPair(name: string, keyType: Ec2KeyPairType = 'rsa'): Promise<Ec2KeyPairMaterial> {
|
||||
const res = await client.send(new CreateKeyPairCommand({KeyName: name, KeyType: keyType}))
|
||||
return {
|
||||
keyPairId: res.KeyPairId ?? '',
|
||||
keyName: res.KeyName ?? name,
|
||||
|
||||
Reference in New Issue
Block a user