Skip to content

Commit

Permalink
lambda onboard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Oct 2, 2023
1 parent de906dd commit fd277c9
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/cert-generator/cmd/lambda.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"context"
"fmt"

"github.com/aws/aws-lambda-go/lambda"
"github.com/zLukas/CloudTools/src/cert-generator/pkg/tls"
)

type RequestEvent struct {
CACert tls.CACert `json:"caCert"`
Cert tls.Cert `json:"cert"`
}

func handleRequest(ctx context.Context, event RequestEvent) (string, error) {

caKey, ca, err := tls.CreateCACertBytes(&event.CACert)
if err != nil {
return "fail", fmt.Errorf("Failed to create CaCert: %s", err.Error())
}
ceKey, ce, err := tls.CreateCertBytes(&event.Cert, caKey, ca)
if err != nil {
return "fail", fmt.Errorf("Failed to create Cert: %s", err.Error())
}
fmt.Printf("%v,%v", ceKey, ce)
return "sucess", nil

}

func RunLambda() {
lambda.Start(handleRequest)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"fmt"
Expand All @@ -8,8 +8,7 @@ import (
"github.com/zLukas/CloudTools/src/cert-generator/pkg/tls"
)

func main() {

func RunLocal() {
var file string = ""
if len(os.Args) > 1 {
file = os.Args[1]
Expand All @@ -18,7 +17,7 @@ func main() {
config := input.Config{CfgFilePath: file}

if err := config.ParseInput(); err != nil {
fmt.Printf("cannot parse input file: %s", err)
fmt.Printf("cannot parse input file: %s", err.Error())
return
}

Expand Down
12 changes: 11 additions & 1 deletion src/cert-generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ module github.com/zLukas/CloudTools/src/cert-generator

go 1.21.1

require gopkg.in/yaml.v2 v2.4.0 // indirect
require (
github.com/aws/aws-lambda-go v1.41.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
github.com/aws/aws-sdk-go-v2/service/lambda v1.39.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
22 changes: 22 additions & 0 deletions src/cert-generator/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc=
github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 h1:OPLEkmhXf6xFPiz0bLeDArZIDx1NNS4oJyG4nv3Gct0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13/go.mod h1:gpAbvyDGQFozTEmlTFO8XcQKHzubdq0LzRyJpG6MiXM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 h1:22dGT7PneFMx4+b3pz7lMTRyN8ZKH7M2cW4GP9yUS2g=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41/go.mod h1:CrObHAuPneJBlfEJ5T3szXOUkLEThaGfvnhTf33buas=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 h1:SijA0mgjV8E+8G45ltVHs0fvKpTj8xmZJ3VwhGKtUSI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1g3pHAIdCp7QsRIkMmLAgoDquQ9Rr8kYw=
github.com/aws/aws-sdk-go-v2/service/lambda v1.39.5 h1:uMvxJFS92hNW6BRX0Ou+5zb9DskgrJQHZ+5yT8FXK5Y=
github.com/aws/aws-sdk-go-v2/service/lambda v1.39.5/go.mod h1:ByLHcf0zbHpyLTOy1iPVRPJWmAUPCiJv5k81dt52ID8=
github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ=
github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
19 changes: 19 additions & 0 deletions src/cert-generator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"fmt"
"os"

"github.com/zLukas/CloudTools/src/cert-generator/cmd"
)

func main() {
enviroment := os.Getenv("ENVIROMENT")
if enviroment == "LAMBDA" {

cmd.RunLambda()
} else {
fmt.Print("running locally")
cmd.RunLocal()
}
}
1 change: 1 addition & 0 deletions src/cert-generator/pkg/aws/dynamodb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package aws
1 change: 1 addition & 0 deletions src/cert-generator/pkg/aws/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package aws

0 comments on commit fd277c9

Please sign in to comment.