mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
delete, get and create via cli
This commit is contained in:
@@ -12,6 +12,12 @@ import (
|
||||
|
||||
const SERVICE_NAME = "infisical"
|
||||
|
||||
type LoggedInUserDetails struct {
|
||||
IsUserLoggedIn bool
|
||||
LoginExpired bool
|
||||
UserCredentials models.UserCredentials
|
||||
}
|
||||
|
||||
// To do: what happens if the user doesn't have a keyring in their system?
|
||||
func StoreUserCredsInKeyRing(userCred *models.UserCredentials) error {
|
||||
userCredMarshalled, err := json.Marshal(userCred)
|
||||
@@ -102,3 +108,50 @@ func IsUserLoggedIn() (hasUserLoggedIn bool, theUsersEmail string, err error) {
|
||||
return false, "", nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetCurrentLoggedInUserDetails() (LoggedInUserDetails, error) {
|
||||
if ConfigFileExists() {
|
||||
configFile, err := GetConfigFile()
|
||||
if err != nil {
|
||||
return LoggedInUserDetails{}, fmt.Errorf("getCurrentLoggedInUserDetails: unable to get logged in user from config file [err=%s]", err)
|
||||
}
|
||||
|
||||
if configFile.LoggedInUserEmail == "" {
|
||||
return LoggedInUserDetails{}, nil
|
||||
}
|
||||
|
||||
userCreds, err := GetUserCredsFromKeyRing(configFile.LoggedInUserEmail)
|
||||
if err != nil {
|
||||
return LoggedInUserDetails{}, fmt.Errorf("getCurrentLoggedInUserDetails: unable to your credentials from Keyring [err=%s]", err)
|
||||
}
|
||||
|
||||
// check to to see if the JWT is still valid
|
||||
httpClient := resty.New().
|
||||
SetAuthToken(userCreds.JTWToken).
|
||||
SetHeader("Accept", "application/json")
|
||||
|
||||
response, err := httpClient.
|
||||
R().
|
||||
Post(fmt.Sprintf("%v/v1/auth/checkAuth", INFISICAL_URL))
|
||||
|
||||
if err != nil {
|
||||
return LoggedInUserDetails{}, err
|
||||
}
|
||||
|
||||
if response.StatusCode() > 299 {
|
||||
return LoggedInUserDetails{
|
||||
IsUserLoggedIn: true,
|
||||
LoginExpired: true,
|
||||
UserCredentials: userCreds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return LoggedInUserDetails{
|
||||
IsUserLoggedIn: true,
|
||||
LoginExpired: false,
|
||||
UserCredentials: userCreds,
|
||||
}, nil
|
||||
} else {
|
||||
return LoggedInUserDetails{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
|
||||
"github.com/Infisical/infisical-merge/packages/models"
|
||||
"golang.org/x/crypto/nacl/box"
|
||||
)
|
||||
|
||||
@@ -39,15 +40,15 @@ func GenerateNewKey() (newKey []byte, keyErr error) {
|
||||
}
|
||||
|
||||
// Will encrypt a plain text with the provided key
|
||||
func EncryptSymmetric(plaintext []byte, key []byte) (cipherText []byte, iv []byte, tag []byte, err error) {
|
||||
func EncryptSymmetric(plaintext []byte, key []byte) (result models.SymmetricEncryptionResult, err error) {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return models.SymmetricEncryptionResult{}, err
|
||||
}
|
||||
|
||||
aesgcm, err := cipher.NewGCMWithNonceSize(block, 16) // default is 12, 16 because https://github.com/Infisical/infisical/blob/bea0ff6e05a4de73a5db625d4ae181a015b50855/backend/src/utils/aes-gcm.ts#L4
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return models.SymmetricEncryptionResult{}, err
|
||||
}
|
||||
|
||||
// create a nonce
|
||||
@@ -62,7 +63,11 @@ func EncryptSymmetric(plaintext []byte, key []byte) (cipherText []byte, iv []byt
|
||||
|
||||
authTag := ciphertext[len(ciphertext)-16:]
|
||||
|
||||
return ciphertextOnly, nonce, authTag, nil
|
||||
return models.SymmetricEncryptionResult{
|
||||
CipherText: ciphertextOnly,
|
||||
AuthTag: authTag,
|
||||
Nonce: nonce,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DecryptAsymmetric(ciphertext []byte, nonce []byte, publicKey []byte, privateKey []byte) (plainText []byte) {
|
||||
|
||||
@@ -81,6 +81,7 @@ func getSecretsByWorkspaceIdAndEnvName(httpClient resty.Client, envName string,
|
||||
Key: string(plainTextKey),
|
||||
Value: string(plainTextValue),
|
||||
Type: string(secret.Type),
|
||||
ID: secret.ID,
|
||||
}
|
||||
|
||||
listOfEnv = append(listOfEnv, env)
|
||||
@@ -192,6 +193,7 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string,
|
||||
Key: string(plainTextKey),
|
||||
Value: string(plainTextValue),
|
||||
Type: string(secret.Type),
|
||||
ID: secret.ID,
|
||||
}
|
||||
|
||||
listOfEnv = append(listOfEnv, env)
|
||||
|
||||
Reference in New Issue
Block a user