From 9adb72b1b115554105eac52c12886187fcfccc70 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Tue, 14 Dec 2021 18:28:05 +0200 Subject: [PATCH] Jira password from STDIN Ths is the safest way of passing the username and password, compare dto a text file or ENV --- cmd/jiraworklog/main.go | 19 +++++++++++++++++++ docs/readme.md | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/cmd/jiraworklog/main.go b/cmd/jiraworklog/main.go index 96a42dc..acf268f 100644 --- a/cmd/jiraworklog/main.go +++ b/cmd/jiraworklog/main.go @@ -2,9 +2,12 @@ package main import ( "errors" + "fmt" "strconv" + "syscall" "github.com/mkobaly/jiraworklog/job" + "golang.org/x/crypto/ssh/terminal" //"github.com/mkobaly/jiraworklog/test" "net/http" @@ -81,6 +84,22 @@ func main() { } } + if cmdline.IsOptionSet("ask") { + fmt.Println("Please enter Jira username:") + userBytes, err := terminal.ReadPassword(int(syscall.Stdin)) + if err != nil { + logger.WithError(err).Fatal("Reading Jira Username from the STDIN failed") + } + cfg.Jira.Username = string(userBytes) + fmt.Println("Please enter Jira password:") + passBytes, err := terminal.ReadPassword(int(syscall.Stdin)) + if err != nil { + logger.WithError(err).Fatal("Reading Jira Password from the STDIN failed") + } + cfg.Jira.Password = string(passBytes) + fmt.Println("Thanks!") + } + //Repo Settings repoType := "BOLTDB" if cmdline.IsOptionSet("r") { diff --git a/docs/readme.md b/docs/readme.md index 4002f73..aa3b2cd 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -66,9 +66,25 @@ OPTIONS -h, --help print help and exit -p, --port <8180> default port to serve rest API from (default: 8180) -r, --repo specific repo to use (MSSQL, BOLTDB) (default: BOLTDB) +-a, --ask Ask for Jira username and password from the STDIN -v, --verbose verbose logging ``` +## Environment values + +You can override values from the configuration file using the ENV. + +### Example + +JWL_JIRA_URL=> Config.Jira.URL +Only JWL_JIRA_* are currently supported + +### Usage + +``` +JWL_JIRA_USERNAME="urho" JWL_JIRA_PASSWORD="kekkonen" ./jiraworklog +``` + ## Running for the first time ### Linux or Windows