Skip to content

Commit

Permalink
onboard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Oct 4, 2023
1 parent c30a6ff commit e20ec4d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/cert-generator/cmd/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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

}
Expand Down
19 changes: 19 additions & 0 deletions src/cert-generator/cmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
}
}

0 comments on commit e20ec4d

Please sign in to comment.