Files
spinifex/hive/gateway/ec2/key/CreateKeyPair.go
T
2026-02-11 10:11:37 +10:00

47 lines
1.0 KiB
Go

package gateway_ec2_key
import (
"errors"
"log/slog"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mulgadc/hive/hive/awserrors"
handlers_ec2_key "github.com/mulgadc/hive/hive/handlers/ec2/key"
"github.com/nats-io/nats.go"
)
func ValidateCreateKeyPairInput(input *ec2.CreateKeyPairInput) (err error) {
if input == nil {
return errors.New(awserrors.ErrorMissingParameter)
}
if input.KeyName == nil || *input.KeyName == "" {
return errors.New(awserrors.ErrorMissingParameter)
}
return
}
func CreateKeyPair(input *ec2.CreateKeyPairInput, natsConn *nats.Conn) (output ec2.CreateKeyPairOutput, err error) {
// Validate input
err = ValidateCreateKeyPairInput(input)
if err != nil {
return output, err
}
// Create NATS key service and call CreateKeyPair
keyService := handlers_ec2_key.NewNATSKeyService(natsConn)
result, err := keyService.CreateKeyPair(input)
if err != nil {
slog.Error("CreateKeyPair failed", "err", err)
return output, err
}
// Return the result
output = *result
return output, nil
}