This is an automated email from the ASF dual-hosted git repository.

guangning pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 28a6b491 Support load config from env (#1089)
28a6b491 is described below

commit 28a6b49159a7474facdb6dc5d675fae427d8a1f8
Author: Guangning E <[email protected]>
AuthorDate: Thu Sep 7 20:38:55 2023 +0800

    Support load config from env (#1089)
    
    * Support load config from env
    * Run goimport
---
 pulsaradmin/pkg/admin/auth/oauth2.go |  8 ++++++--
 pulsaradmin/pkg/utils/utils.go       | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/pulsaradmin/pkg/admin/auth/oauth2.go 
b/pulsaradmin/pkg/admin/auth/oauth2.go
index eab64cac..2864eae2 100644
--- a/pulsaradmin/pkg/admin/auth/oauth2.go
+++ b/pulsaradmin/pkg/admin/auth/oauth2.go
@@ -19,9 +19,12 @@ package auth
 
 import (
        "encoding/json"
+       "fmt"
        "net/http"
        "path/filepath"
 
+       "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
+
        "github.com/99designs/keyring"
        "github.com/apache/pulsar-client-go/oauth2"
        "github.com/apache/pulsar-client-go/oauth2/cache"
@@ -243,8 +246,9 @@ func makeKeyring() (keyring.Keyring, error) {
                ServiceName:              serviceName,
                KeychainName:             keyChainName,
                KeychainTrustApplication: true,
-               FileDir:                  filepath.Join("~/.config/pulsar", 
"credentials"),
-               FilePasswordFunc:         keyringPrompt,
+               FileDir: filepath.Join(fmt.Sprintf(
+                       "%s/.config/pulsar", utils.GetConfigPath()), 
"credentials"),
+               FilePasswordFunc: keyringPrompt,
        })
 }
 
diff --git a/pulsaradmin/pkg/utils/utils.go b/pulsaradmin/pkg/utils/utils.go
index 7b23b156..fc0897ca 100644
--- a/pulsaradmin/pkg/utils/utils.go
+++ b/pulsaradmin/pkg/utils/utils.go
@@ -19,6 +19,7 @@ package utils
 
 import (
        "fmt"
+       "os"
        "reflect"
 )
 
@@ -36,3 +37,12 @@ func IsNilFixed(i interface{}) bool {
        }
        return false
 }
+
+func GetConfigPath() string {
+       // pulsar client config dir path, for example: PULSAR_CLIENT_CONF_PATH: 
/home/pulsar
+       // configuration file path is: /home/pulsar/.config/pulsar
+       if envConf, ok := os.LookupEnv("PULSAR_CLIENT_CONF_PATH"); ok {
+               return envConf
+       }
+       return HomeDir()
+}

Reply via email to