diff --git a/venafi-snowflake-connector/lambda/request_cert/go.mod b/venafi-snowflake-connector/lambda/request_cert/go.mod index 217fc86..fe26086 100644 --- a/venafi-snowflake-connector/lambda/request_cert/go.mod +++ b/venafi-snowflake-connector/lambda/request_cert/go.mod @@ -1,10 +1,12 @@ module github.com/starschema/snowflake-venafi-connector -go 1.14 +go 1.16 replace github.com/snowflake-venafi-connector/go-lambda/src/request_cert => ./request_cert require ( github.com/Venafi/vcert/v4 v4.14.1 github.com/aws/aws-lambda-go v1.23.0 + github.com/palette-software/go-log-targets v0.0.0-20200609204140-16fbfda0867a + github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134 // indirect ) diff --git a/venafi-snowflake-connector/lambda/request_cert/go.sum b/venafi-snowflake-connector/lambda/request_cert/go.sum index fd16008..6708352 100644 --- a/venafi-snowflake-connector/lambda/request_cert/go.sum +++ b/venafi-snowflake-connector/lambda/request_cert/go.sum @@ -127,6 +127,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/palette-software/go-log-targets v0.0.0-20200609204140-16fbfda0867a h1:AEqLzA2c6+Em5cXn2VDyrK1x2yjHv7GshRM0i1Qz0g8= +github.com/palette-software/go-log-targets v0.0.0-20200609204140-16fbfda0867a/go.mod h1:LUvrlvuVikcIWSBBA+nKP6pc1uUzY/7T97eIpfOfYWA= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pavel-v-chernykh/keystore-go/v4 v4.1.0/go.mod h1:2ejgys4qY+iNVW1IittZhyRYA6MNv8TgM6VHqojbB9g= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= @@ -173,6 +175,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134 h1:itYC8Ycx8aVBN7a8q1Yr187W5WmQthvYU13+f4rOWkU= +github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134/go.mod h1:0MsIttMJIF/8Y7x0XjonJP7K99t3sR6bjj4m5S4JmqU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= diff --git a/venafi-snowflake-connector/lambda/request_cert/main.go b/venafi-snowflake-connector/lambda/request_cert/main.go index b781cb7..6b63ad3 100644 --- a/venafi-snowflake-connector/lambda/request_cert/main.go +++ b/venafi-snowflake-connector/lambda/request_cert/main.go @@ -11,6 +11,7 @@ import ( "github.com/Venafi/vcert/v4/pkg/endpoint" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" + log "github.com/palette-software/go-log-targets" ) type VenafiConnectorConfig struct { @@ -32,7 +33,7 @@ func RequestCert(ctx context.Context, request events.APIGatewayProxyRequest) (ev var snowflakeData SnowFlakeType err := json.Unmarshal([]byte(request.Body), &snowflakeData) if err != nil { - fmt.Printf("Failed to unmarshal snowflake value: %v ", err) + log.Errorf("Failed to unmarshal snowflake parameters: %s", err) return events.APIGatewayProxyResponse{ // Error HTTP response Body: err.Error(), StatusCode: 500, @@ -56,8 +57,8 @@ func RequestCert(ctx context.Context, request events.APIGatewayProxyRequest) (ev c, err := vcert.NewClient(config) if err != nil { - fmt.Printf("Failed to connect to endpoint: %v ", err) // TODO: use logger - return events.APIGatewayProxyResponse{ // Error HTTP response + log.Errorf("Failed to connect to endpoint: %s", err) + return events.APIGatewayProxyResponse{ Body: err.Error(), StatusCode: 500, }, nil @@ -87,7 +88,7 @@ func RequestCert(ctx context.Context, request events.APIGatewayProxyRequest) (ev // err = c.GenerateRequest(nil, enrollReq) if err != nil { - fmt.Printf("Failed to generate request: %v ", err) + log.Errorf("Failed to generate request: %v ", err) return events.APIGatewayProxyResponse{ // Error HTTP response Body: err.Error(), StatusCode: 500, @@ -99,14 +100,13 @@ func RequestCert(ctx context.Context, request events.APIGatewayProxyRequest) (ev // requestID, err := c.RequestCertificate(enrollReq) if err != nil { - fmt.Printf("Failed to request certificate: %v ", err) + log.Errorf("Failed to request certificate:: %v ", err) return events.APIGatewayProxyResponse{ // Error HTTP response Body: err.Error(), StatusCode: 500, }, nil } - // fmt.Printf("Successfully submitted certificate request. Will pickup certificate by ID: %s", requestID) - // body, err := json.Marshal(requestID) + log.Infof("Certificate request was successful. RequestID is: %s", requestID) return events.APIGatewayProxyResponse{ // Success HTTP response Body: fmt.Sprintf("{'data': [[0, '%v']]}", requestID), StatusCode: 200, @@ -114,6 +114,5 @@ func RequestCert(ctx context.Context, request events.APIGatewayProxyRequest) (ev } func main() { - // lambda.Start(GetCertificate) lambda.Start(RequestCert) }