mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 20:28:16 +00:00
add helper functions to check workspace and login status
This commit is contained in:
@@ -3,6 +3,7 @@ package util
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DecodedSymmetricEncryptionDetails = struct {
|
type DecodedSymmetricEncryptionDetails = struct {
|
||||||
@@ -54,3 +55,46 @@ func IsSecretTypeValid(s string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RequireLogin() {
|
||||||
|
currentUserDetails, err := GetCurrentLoggedInUserDetails()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
HandleError(err, "unable to retrieve your login details")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !currentUserDetails.IsUserLoggedIn {
|
||||||
|
PrintMessageAndExit("You must be logged in to run this command. To login, run [infisical login]")
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentUserDetails.LoginExpired {
|
||||||
|
PrintMessageAndExit("Your login expired, please login in again. To login, run [infisical login]")
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentUserDetails.UserCredentials.Email == "" && currentUserDetails.UserCredentials.JTWToken == "" && currentUserDetails.UserCredentials.PrivateKey == "" {
|
||||||
|
PrintMessageAndExit("One or more of your login details is empty. Please try logging in again via by running [infisical login]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequireServiceToken() {
|
||||||
|
serviceToken := os.Getenv(INFISICAL_TOKEN_NAME)
|
||||||
|
if serviceToken == "" {
|
||||||
|
PrintMessageAndExit("No service token is found in your terminal")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RequireLocalWorkspaceFile() {
|
||||||
|
workspaceFileExists := WorkspaceConfigFileExistsInCurrentPath()
|
||||||
|
if !workspaceFileExists {
|
||||||
|
PrintMessageAndExit("It looks you have not yet connected this project to Infisical", "To do so, run [infisical init] then run your command again")
|
||||||
|
}
|
||||||
|
|
||||||
|
workspaceFile, err := GetWorkSpaceFromFile()
|
||||||
|
if err != nil {
|
||||||
|
HandleError(err, "Unable to read your project configuration, please try initializing this project again.", "Run [infisical init]")
|
||||||
|
}
|
||||||
|
|
||||||
|
if workspaceFile.WorkspaceId == "" {
|
||||||
|
PrintMessageAndExit("Your project id is missing in your local config file. Please add it or run again [infisical init]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user