Skip to content

Commit 96abc49

Browse files
author
André Medek
committed
feat: read user and password from environment variables
- read environment variables BLAZECTL_USER and BLAZECTL_USER to avoid visible credentials in process list - added new section on environment variables to README.md
1 parent 47fe5d3 commit 96abc49

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ Flags:
5353
-h, --help help for blazectl
5454
-k, --insecure allow insecure server connections when using SSL
5555
--no-progress don't show progress bar
56-
--password string password information for basic authentication
56+
--password string password information for basic authentication (env: BLAZECTL_PASSWORD)
5757
--token string bearer token for authentication
58-
--user string user information for basic authentication
58+
--user string user information for basic authentication (env: BLAZECTL_USER)
5959
-v, --version version for blazectl
6060
6161
Use "blazectl [command] --help" for more information about a command.
6262
```
6363

64+
### Environment Variables
65+
66+
To avoid visible credentials in the process list (e.g. by `ps`) by passing username and password on the command line, you can also provide them via environment variables:
67+
```sh
68+
export BLAZECTL_USER="myuser"
69+
export BLAZECTL_PASSWORD="myS3cr3T"
70+
blazectl upload --server http://localhost:8080/fhir my/bundles
71+
```
72+
6473
### Upload
6574

6675
You can use the upload command to upload transaction bundles to your server. Currently, JSON (*.json), [gzip compressed][7] JSON (*.json.gz), [bzip2 compressed][8] JSON (*.json.bz2) and NDJSON (*.ndjson) files are supported. If you don't have any transaction bundles, you can generate some with [SyntheaTM][5].

cmd/root.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ func createClient() error {
5353
}
5454

5555
func clientAuth() fhir.Auth {
56+
// check for environment variables
57+
var envUser = os.Getenv("BLAZECTL_USER")
58+
if basicAuthUser == "" && envUser != "" {
59+
basicAuthUser = envUser
60+
}
61+
var envPassword = os.Getenv("BLAZECTL_PASSWORD")
62+
if basicAuthPassword == "" && envPassword != "" {
63+
basicAuthPassword = envPassword
64+
}
5665
if basicAuthUser != "" && basicAuthPassword != "" {
5766
return fhir.BasicAuth{User: basicAuthUser, Password: basicAuthPassword}
5867
} else if bearerToken != "" {
@@ -85,8 +94,8 @@ func Execute() {
8594
func init() {
8695
rootCmd.PersistentFlags().BoolVarP(&disableTlsSecurity, "insecure", "k", false, "allow insecure server connections when using SSL")
8796
rootCmd.PersistentFlags().StringVar(&caCert, "certificate-authority", "", "path to a cert file for the certificate authority")
88-
rootCmd.PersistentFlags().StringVar(&basicAuthUser, "user", "", "user information for basic authentication")
89-
rootCmd.PersistentFlags().StringVar(&basicAuthPassword, "password", "", "password information for basic authentication")
97+
rootCmd.PersistentFlags().StringVar(&basicAuthUser, "user", "", "user information for basic authentication (env: BLAZECTL_USER)")
98+
rootCmd.PersistentFlags().StringVar(&basicAuthPassword, "password", "", "password information for basic authentication (env: BLAZECTL_PASSWORD)")
9099
rootCmd.PersistentFlags().StringVar(&bearerToken, "token", "", "bearer token for authentication")
91100
rootCmd.PersistentFlags().BoolVarP(&noProgress, "no-progress", "", false, "don't show progress bar")
92101
}

0 commit comments

Comments
 (0)