From e20ec4d4eed21b23826646f4e0483f0841206c5e Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 4 Oct 2023 12:10:04 +0200 Subject: [PATCH] onboard tests --- src/cert-generator/cmd/lambda.go | 19 ++++++++++++++++++- src/cert-generator/cmd/local.go | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/cert-generator/cmd/lambda.go b/src/cert-generator/cmd/lambda.go index 0e220d1..9e07ed5 100644 --- a/src/cert-generator/cmd/lambda.go +++ b/src/cert-generator/cmd/lambda.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/aws/aws-lambda-go/lambda" + "github.com/zLukas/CloudTools/src/cert-generator/pkg/aws" "github.com/zLukas/CloudTools/src/cert-generator/pkg/tls" ) @@ -23,7 +24,23 @@ func handleRequest(ctx context.Context, event RequestEvent) (string, error) { if err != nil { return "fail", fmt.Errorf("Failed to create Cert: %s", err.Error()) } - fmt.Printf("%v,%v", ceKey, ce) + //dbTable := os.Getenv("TABLE_NAME") + dbTable := "CertTable" + db := aws.Database{} + err = db.PutItem(aws.TableRecord{ + CaCert: aws.CertItem{PrivateKey: string(caKey), + Cert: string(ca), + }, + CeCert: aws.CertItem{PrivateKey: string(ceKey), + Cert: string(ce), + }, + Name: "sample-record", + CreationDate: "today", + }, + aws.WithDynamoDBLogin(), + aws.WithTableName(dbTable), + ) + return "sucess", nil } diff --git a/src/cert-generator/cmd/local.go b/src/cert-generator/cmd/local.go index 32153aa..d78ad28 100644 --- a/src/cert-generator/cmd/local.go +++ b/src/cert-generator/cmd/local.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/zLukas/CloudTools/src/cert-generator/pkg/aws" "github.com/zLukas/CloudTools/src/cert-generator/pkg/input" "github.com/zLukas/CloudTools/src/cert-generator/pkg/tls" ) @@ -36,4 +37,22 @@ func RunLocal() { } tls.WriteKeyCertFile(caKey, ca, "CA-Certificate.pem") + + fmt.Print("uploading to database...") + dbTable := "Certificates" + db := aws.Database{} + err = db.PutItem(aws.TableRecord{ + CaCert: aws.CertItem{PrivateKey: string(caKey), + Cert: string(ca), + }, + CeCert: aws.CertItem{}, + Name: "sample-record", + CreationDate: "today", + }, + aws.WithDynamoDBLogin(), + aws.WithTableName(dbTable), + ) + if err != nil { + fmt.Printf("database upload error: %s", err.Error()) + } }