mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
Feat: UA CLI Support
This commit is contained in:
@@ -59,6 +59,11 @@ type DynamicSecretLease struct {
|
|||||||
Data map[string]interface{} `json:"data"`
|
Data map[string]interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TokenDetails struct {
|
||||||
|
Type string
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
type SingleFolder struct {
|
type SingleFolder struct {
|
||||||
ID string `json:"_id"`
|
ID string `json:"_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -67,18 +67,39 @@ func IsSecretTypeValid(s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInfisicalServiceToken(cmd *cobra.Command) (serviceToken string, err error) {
|
func GetInfisicalToken(cmd *cobra.Command) (token *models.TokenDetails, err error) {
|
||||||
infisicalToken, err := cmd.Flags().GetString("token")
|
infisicalToken, err := cmd.Flags().GetString("token")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if infisicalToken == "" {
|
||||||
|
// If no flag is passed, we first check for the universal auth access token env variable.
|
||||||
|
infisicalToken = os.Getenv(INFISICAL_UNIVERSAL_AUTH_ACCESS_TOKEN_NAME)
|
||||||
|
// If it's still empty after the first env check, we check for the service token env variable.
|
||||||
if infisicalToken == "" {
|
if infisicalToken == "" {
|
||||||
infisicalToken = os.Getenv(INFISICAL_TOKEN_NAME)
|
infisicalToken = os.Getenv(INFISICAL_TOKEN_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return infisicalToken, nil
|
// If it's empty, we return nothing at all.
|
||||||
|
if infisicalToken == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(infisicalToken, "st.") {
|
||||||
|
return &models.TokenDetails{
|
||||||
|
Type: "service-token",
|
||||||
|
Token: infisicalToken,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &models.TokenDetails{
|
||||||
|
Type: "universal-auth-token",
|
||||||
|
Token: infisicalToken,
|
||||||
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInfisicalUniversalAuthAccessToken(cmd *cobra.Command) (accessToken string, err error) {
|
func GetInfisicalUniversalAuthAccessToken(cmd *cobra.Command) (accessToken string, err error) {
|
||||||
@@ -128,6 +149,25 @@ func UniversalAuthLogin(clientId string, clientSecret string) (api.UniversalAuth
|
|||||||
return tokenResponse, nil
|
return tokenResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RenewUniversalAuthAccessToken(accessToken string) (string, error) {
|
||||||
|
|
||||||
|
httpClient := resty.New()
|
||||||
|
httpClient.SetRetryCount(10000).
|
||||||
|
SetRetryMaxWaitTime(20 * time.Second).
|
||||||
|
SetRetryWaitTime(5 * time.Second)
|
||||||
|
|
||||||
|
request := api.UniversalAuthRefreshRequest{
|
||||||
|
AccessToken: accessToken,
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenResponse, err := api.CallUniversalAuthRefreshAccessToken(httpClient, request)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokenResponse.AccessToken, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if the passed in email already exists in the users slice
|
// Checks if the passed in email already exists in the users slice
|
||||||
func ConfigContainsEmail(users []models.LoggedInUser, email string) bool {
|
func ConfigContainsEmail(users []models.LoggedInUser, email string) bool {
|
||||||
for _, value := range users {
|
for _, value := range users {
|
||||||
|
|||||||
Reference in New Issue
Block a user