Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Helpers

Daniel Hougaarde019f3811bc1
diff --git a/cli/packages/util/helper.go b/cli/packages/util/helper.go
index 81fbcaeff0..36d8abda17 100644
--- a/cli/packages/util/helper.go
+++ b/cli/packages/util/helper.go
@@ -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
+}