From 2ab643161c3a95965ca4a7f0b057ae6ae057cfcb Mon Sep 17 00:00:00 2001 From: Eugene Dementiev Date: Fri, 15 Feb 2019 09:48:01 +1300 Subject: [PATCH] Create the dotenv file with 0600 perms --- cmd/dotenv.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/dotenv.go b/cmd/dotenv.go index 9b5736a..c91e3db 100644 --- a/cmd/dotenv.go +++ b/cmd/dotenv.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "github.com/apex/log" "github.com/imdario/mergo" "github.com/joho/godotenv" @@ -32,12 +34,22 @@ var dotenvCmd = &cobra.Command{ } } - err = godotenv.Write(megamap, args[0]) + // we don't want to use godotenv as it creates files with too open permissions + content, err := godotenv.Marshal(megamap) + if err != nil { + log.WithError(err).Fatal("Can't marshal the env to a string") + } + + file, err := os.OpenFile(args[0], os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + log.WithError(err).Fatal("Can't create the file") + } + + _, err = file.WriteString(content) if err != nil { log.WithError(err).Fatal("Can't write the dotenv file") } else { log.WithFields(log.Fields{"filename": args[0]}).Info("Wrote the .env file") - } }, }