0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-25 09:40:39 +00:00

Use logrus for logging messages

This commit is contained in:
Jacob McCann 2016-10-09 10:38:37 +05:30
parent 5f6ed41c05
commit ef64a0f2a3
3 changed files with 15 additions and 16 deletions

View File

@ -9,7 +9,7 @@ pipeline:
- CGO_ENABLED=0 - CGO_ENABLED=0
commands: commands:
- go test -cover -coverprofile=coverage.out - go test -cover -coverprofile=coverage.out
- go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a - go build -ldflags "-s -w -X main.revision=$(git rev-parse HEAD)" -a
coverage: coverage:
image: coverage image: coverage

View File

@ -9,14 +9,14 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
var version string // build number set at compile-time var revision string // build number set at compile-time
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "terraform plugin" app.Name = "terraform plugin"
app.Usage = "terraform plugin" app.Usage = "terraform plugin"
app.Action = run app.Action = run
app.Version = version app.Version = revision
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
// //
@ -81,6 +81,10 @@ func main() {
} }
func run(c *cli.Context) error { func run(c *cli.Context) error {
logrus.WithFields(logrus.Fields{
"Revision": revision,
}).Info("Drone Terraform Plugin Version")
if c.String("env-file") != "" { if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file")) _ = godotenv.Load(c.String("env-file"))
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" "github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts" "github.com/aws/aws-sdk-go/service/sts"
"github.com/Sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
@ -13,10 +14,6 @@ import (
"time" "time"
) )
var (
buildCommit string
)
type ( type (
Config struct { Config struct {
Remote Remote Remote Remote
@ -41,8 +38,6 @@ type (
) )
func (p Plugin) Exec() error { func (p Plugin) Exec() error {
fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit)
if p.Config.RoleARN != "" { if p.Config.RoleARN != "" {
assumeRole(p.Config.RoleARN) assumeRole(p.Config.RoleARN)
} }
@ -81,11 +76,11 @@ func (p Plugin) Exec() error {
err := c.Run() err := c.Run()
if err != nil { if err != nil {
fmt.Println("Error!") logrus.WithFields(logrus.Fields{
fmt.Println(err) "error": err,
os.Exit(1) }).Fatal("Failed to execute a command")
} }
fmt.Println("Command completed successfully") logrus.Debug("Command completed successfully")
} }
return nil return nil
@ -176,9 +171,9 @@ func assumeRole(roleArn string) {
value, err := credentials.NewCredentials(stsProvider).Get() value, err := credentials.NewCredentials(stsProvider).Get()
if err != nil { if err != nil {
fmt.Println("Error assuming role!") logrus.WithFields(logrus.Fields{
fmt.Println(err) "error": err,
os.Exit(1) }).Fatal("Error assuming role!")
} }
os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID) os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID)
os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey) os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey)