mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 07:26:45 +00:00
Helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -246,3 +247,30 @@ func AppendAPIEndpoint(address string) string {
|
|||||||
}
|
}
|
||||||
return address + "/api"
|
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