Skip to content

Commit

Permalink
secrets: Add function to retrieve password externally.
Browse files Browse the repository at this point in the history
  • Loading branch information
VoigtS committed Oct 11, 2023
1 parent 2702728 commit 4f42d65
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions secrets/externalSecret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package secrets

import (
"fmt"
"os"
"os/exec"
"strings"
)

func CheckPWCMD(pwCmd string) (string, error) {
if pwCmd == "" && os.Getenv("OS_PASSWORD") != "" {
return "", fmt.Errorf("no command specified")
}
// Retrieve user's password from external command.
out, err := exec.Command("sh", "-c", pwCmd).Output()
if err != nil {
return "", fmt.Errorf("could not retrieve user password using: %s", pwCmd)
}
return strings.TrimSuffix(string(out), "\n"), nil
}

0 comments on commit 4f42d65

Please sign in to comment.