Skip to content

Commit 904d5e1

Browse files
committed
fix support for caching the encryption passphrase
1 parent 7e2c95f commit 904d5e1

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pkg/c8ysession/c8ysession.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func WriteOutput(w io.Writer, client *c8y.Client, cfg *config.Config, session *C
158158

159159
shell, isShell := utilities.ShellType.Parse(utilities.ShellBash, format)
160160
if isShell {
161-
output := GetVariablesFromSession(session, client, cfg.AlwaysIncludePassword())
161+
output := GetVariablesFromSession(session, cfg, client, cfg.AlwaysIncludePassword())
162162
utilities.WriteShellVariables(w, output, shell)
163163
return nil
164164
}
@@ -175,7 +175,7 @@ func WriteOutput(w io.Writer, client *c8y.Client, cfg *config.Config, session *C
175175
}
176176
fmt.Fprintf(w, "%s\n", out)
177177
case "env", "dotenv":
178-
output := GetVariablesFromSession(session, client, cfg.AlwaysIncludePassword())
178+
output := GetVariablesFromSession(session, cfg, client, cfg.AlwaysIncludePassword())
179179
for k, v := range output {
180180
if v != "" {
181181
fmt.Fprintf(w, "%s=%s\n", k, v)
@@ -188,7 +188,7 @@ func WriteOutput(w io.Writer, client *c8y.Client, cfg *config.Config, session *C
188188
}
189189

190190
// GetVariablesFromSession gets all the environment variables associated with the current session
191-
func GetVariablesFromSession(session *CumulocitySession, client *c8y.Client, setPassword bool) map[string]interface{} {
191+
func GetVariablesFromSession(session *CumulocitySession, cfg *config.Config, client *c8y.Client, setPassword bool) map[string]interface{} {
192192
host := session.Host
193193
domain := session.GetDomain()
194194
tenant := session.Tenant
@@ -227,6 +227,17 @@ func GetVariablesFromSession(session *CumulocitySession, client *c8y.Client, set
227227
"C8Y_SETTINGS_LOGIN_TYPE": loginType,
228228
}
229229

230+
cache := cfg.CachePassphraseVariables()
231+
cfg.Logger.Debugf("Cache passphrase: %v", cache)
232+
if cache {
233+
if cfg.Passphrase != "" {
234+
output[config.EnvPassphrase] = cfg.Passphrase
235+
}
236+
if cfg.SecretText != "" {
237+
output[config.EnvPassphraseText] = cfg.SecretText
238+
}
239+
}
240+
230241
if loginType != c8y.AuthMethodOAuth2Internal {
231242
output["C8Y_TOKEN"] = ""
232243
}
@@ -241,7 +252,7 @@ func GetVariablesFromSession(session *CumulocitySession, client *c8y.Client, set
241252
}
242253

243254
func ShowSessionEnvironmentVariables(session *CumulocitySession, cfg *config.Config, c8yclient *c8y.Client, shell utilities.ShellType) {
244-
output := GetVariablesFromSession(session, c8yclient, cfg.AlwaysIncludePassword())
255+
output := GetVariablesFromSession(session, cfg, c8yclient, cfg.AlwaysIncludePassword())
245256
utilities.WriteShellVariables(os.Stdout, output, shell)
246257
}
247258

0 commit comments

Comments
 (0)