mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@@ -246,3 +247,30 @@ func AppendAPIEndpoint(address string) string {
|
||||
}
|
||||
return address + "/api"
|
||||
}
|
||||
|
||||
func ReadFileAsString(filePath string) (string, error) {
|
||||
fileBytes, err := ioutil.ReadFile(filePath)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(fileBytes), nil
|
||||
|
||||
}
|
||||
|
||||
func GetEnvVarOrFileContent(envName string, filePath string) (string, error) {
|
||||
// First check if the environment variable is set
|
||||
if envVarValue := os.Getenv(envName); envVarValue != "" {
|
||||
return envVarValue, nil
|
||||
}
|
||||
|
||||
// If it's not set, try to read the file
|
||||
fileContent, err := ReadFileAsString(filePath)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to read file content from file path '%s' [err=%v]", filePath, err)
|
||||
}
|
||||
|
||||
return fileContent, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user