diff --git a/src/cert-generator/cmd/lambda.go b/src/cert-generator/cmd/lambda.go new file mode 100644 index 0000000..0e220d1 --- /dev/null +++ b/src/cert-generator/cmd/lambda.go @@ -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) +} diff --git a/src/cert-generator/cmd/tls-gen.go b/src/cert-generator/cmd/local.go similarity index 88% rename from src/cert-generator/cmd/tls-gen.go rename to src/cert-generator/cmd/local.go index c478d05..32153aa 100644 --- a/src/cert-generator/cmd/tls-gen.go +++ b/src/cert-generator/cmd/local.go @@ -1,4 +1,4 @@ -package main +package cmd import ( "fmt" @@ -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] @@ -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 } diff --git a/src/cert-generator/go.mod b/src/cert-generator/go.mod index 262788f..44b9e11 100644 --- a/src/cert-generator/go.mod +++ b/src/cert-generator/go.mod @@ -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 +) diff --git a/src/cert-generator/go.sum b/src/cert-generator/go.sum index 7534661..5433102 100644 --- a/src/cert-generator/go.sum +++ b/src/cert-generator/go.sum @@ -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= diff --git a/src/cert-generator/main.go b/src/cert-generator/main.go new file mode 100644 index 0000000..81979f9 --- /dev/null +++ b/src/cert-generator/main.go @@ -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() + } +} diff --git a/src/cert-generator/pkg/aws/dynamodb.go b/src/cert-generator/pkg/aws/dynamodb.go new file mode 100644 index 0000000..a1f9c0e --- /dev/null +++ b/src/cert-generator/pkg/aws/dynamodb.go @@ -0,0 +1 @@ +package aws diff --git a/src/cert-generator/pkg/aws/types.go b/src/cert-generator/pkg/aws/types.go new file mode 100644 index 0000000..a1f9c0e --- /dev/null +++ b/src/cert-generator/pkg/aws/types.go @@ -0,0 +1 @@ +package aws