feat: EC2 UI polished + storage persisting
This commit is contained in:
@@ -4,6 +4,7 @@ import type {
|
||||
CreateAmiInput,
|
||||
CreateNatGatewayInput,
|
||||
CreateRouteInput,
|
||||
Ec2KeyPairType,
|
||||
Ec2Tag,
|
||||
IpPermissionInput,
|
||||
RunInstanceInput,
|
||||
@@ -12,6 +13,11 @@ import type {
|
||||
import {ec2Service} from '../services/ec2'
|
||||
|
||||
type Ec2Service = typeof ec2Service
|
||||
type CreateKeyPairInput = {name: string; keyType?: Ec2KeyPairType}
|
||||
|
||||
function isEc2KeyPairType(value: unknown): value is Ec2KeyPairType {
|
||||
return value === 'rsa' || value === 'ed25519'
|
||||
}
|
||||
|
||||
function handleError(c: Context, error: unknown) {
|
||||
const msg = error instanceof Error ? error.message : 'Unknown error'
|
||||
@@ -124,8 +130,11 @@ export function createEc2Router(svc: Ec2Service = ec2Service) {
|
||||
|
||||
app.post('/key-pairs', async (c) => {
|
||||
try {
|
||||
const {name} = await c.req.json<{name: string}>()
|
||||
return c.json(await svc.createKeyPair(name))
|
||||
const {name, keyType = 'rsa'} = await c.req.json<CreateKeyPairInput>()
|
||||
if (!isEc2KeyPairType(keyType)) {
|
||||
return c.json({error: 'keyType must be rsa or ed25519'}, 400)
|
||||
}
|
||||
return c.json(await svc.createKeyPair(name, keyType))
|
||||
} catch (error) {
|
||||
return handleError(c, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user