Skip to content

Commit

Permalink
[GH-2] Use logger and upgrade go version
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanni1993 committed May 26, 2021
1 parent 920585a commit fb715b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion venafi-snowflake-connector/lambda/request_cert/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 4 additions & 0 deletions venafi-snowflake-connector/lambda/request_cert/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
15 changes: 7 additions & 8 deletions venafi-snowflake-connector/lambda/request_cert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -99,21 +100,19 @@ 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,
}, nil
}

func main() {
// lambda.Start(GetCertificate)
lambda.Start(RequestCert)
}

0 comments on commit fb715b5

Please sign in to comment.