mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 02:27:37 +00:00
Allow custom headers on CLI
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/config"
|
"github.com/Infisical/infisical-merge/packages/config"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -529,6 +528,7 @@ func NewAgentManager(options NewAgentMangerOptions) *AgentManager {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT, // ? Should we perhaps use a different user agent for the Agent for better analytics?
|
UserAgent: api.USER_AGENT, // ? Should we perhaps use a different user agent for the Agent for better analytics?
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,7 +716,11 @@ func (tm *AgentManager) FetchNewAccessToken() error {
|
|||||||
|
|
||||||
// Refreshes the existing access token
|
// Refreshes the existing access token
|
||||||
func (tm *AgentManager) RefreshAccessToken() error {
|
func (tm *AgentManager) RefreshAccessToken() error {
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetRetryCount(10000).
|
httpClient.SetRetryCount(10000).
|
||||||
SetRetryMaxWaitTime(20 * time.Second).
|
SetRetryMaxWaitTime(20 * time.Second).
|
||||||
SetRetryWaitTime(5 * time.Second)
|
SetRetryWaitTime(5 * time.Second)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -70,8 +69,12 @@ var bootstrapCmd = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient := resty.New().
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
SetHeader("Accept", "application/json")
|
if err != nil {
|
||||||
|
log.Error().Msgf("Failed to get resty client with custom headers: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
httpClient.SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
bootstrapResponse, err := api.CallBootstrapInstance(httpClient, api.BootstrapInstanceRequest{
|
bootstrapResponse, err := api.CallBootstrapInstance(httpClient, api.BootstrapInstanceRequest{
|
||||||
Domain: util.AppendAPIEndpoint(domain),
|
Domain: util.AppendAPIEndpoint(domain),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/config"
|
"github.com/Infisical/infisical-merge/packages/config"
|
||||||
@@ -14,7 +15,6 @@ import (
|
|||||||
// "github.com/Infisical/infisical-merge/packages/models"
|
// "github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
// "github.com/Infisical/infisical-merge/packages/visualize"
|
// "github.com/Infisical/infisical-merge/packages/visualize"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/posthog/posthog-go"
|
"github.com/posthog/posthog-go"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -56,7 +56,10 @@ func getDynamicSecretList(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var infisicalToken string
|
var infisicalToken string
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
@@ -89,6 +92,7 @@ func getDynamicSecretList(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
@@ -164,7 +168,10 @@ func createDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var infisicalToken string
|
var infisicalToken string
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
@@ -197,6 +204,7 @@ func createDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
@@ -286,7 +294,10 @@ func renewDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var infisicalToken string
|
var infisicalToken string
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
@@ -319,6 +330,7 @@ func renewDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
@@ -384,7 +396,10 @@ func revokeDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var infisicalToken string
|
var infisicalToken string
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
@@ -417,6 +432,7 @@ func revokeDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
@@ -481,7 +497,10 @@ func listDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var infisicalToken string
|
var infisicalToken string
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
@@ -514,6 +533,7 @@ func listDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/posthog/posthog-go"
|
"github.com/posthog/posthog-go"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -50,7 +49,10 @@ var initCmd = &cobra.Command{
|
|||||||
util.PrintErrorMessageAndExit("Your login session has expired, please run [infisical login] and try again")
|
util.PrintErrorMessageAndExit("Your login session has expired, please run [infisical login] and try again")
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
httpClient.SetAuthToken(userCreds.UserCredentials.JTWToken)
|
httpClient.SetAuthToken(userCreds.UserCredentials.JTWToken)
|
||||||
|
|
||||||
organizationResponse, err := api.CallGetAllOrganizations(httpClient)
|
organizationResponse, err := api.CallGetAllOrganizations(httpClient)
|
||||||
@@ -81,7 +83,10 @@ var initCmd = &cobra.Command{
|
|||||||
for i < 6 {
|
for i < 6 {
|
||||||
mfaVerifyCode := askForMFACode(tokenResponse.MfaMethod)
|
mfaVerifyCode := askForMFACode(tokenResponse.MfaMethod)
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
httpClient.SetAuthToken(tokenResponse.Token)
|
httpClient.SetAuthToken(tokenResponse.Token)
|
||||||
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
||||||
Email: userCreds.UserCredentials.Email,
|
Email: userCreds.UserCredentials.Email,
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/srp"
|
"github.com/Infisical/infisical-merge/packages/srp"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/posthog/posthog-go"
|
"github.com/posthog/posthog-go"
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
@@ -182,6 +181,7 @@ var loginCmd = &cobra.Command{
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
|
|
||||||
loginMethod, err := cmd.Flags().GetString("method")
|
loginMethod, err := cmd.Flags().GetString("method")
|
||||||
@@ -359,7 +359,10 @@ func cliDefaultLogin(userCredentialsToBeStored *models.UserCredentials) {
|
|||||||
for i < 6 {
|
for i < 6 {
|
||||||
mfaVerifyCode := askForMFACode("email")
|
mfaVerifyCode := askForMFACode("email")
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
httpClient.SetAuthToken(loginTwoResponse.Token)
|
httpClient.SetAuthToken(loginTwoResponse.Token)
|
||||||
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
||||||
Email: email,
|
Email: email,
|
||||||
@@ -726,7 +729,10 @@ func askForLoginCredentials() (email string, password string, err error) {
|
|||||||
|
|
||||||
func getFreshUserCredentials(email string, password string) (*api.GetLoginOneV2Response, *api.GetLoginTwoV2Response, error) {
|
func getFreshUserCredentials(email string, password string) (*api.GetLoginOneV2Response, *api.GetLoginTwoV2Response, error) {
|
||||||
log.Debug().Msg(fmt.Sprint("getFreshUserCredentials: ", "email", email, "password: ", password))
|
log.Debug().Msg(fmt.Sprint("getFreshUserCredentials: ", "email", email, "password: ", password))
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
httpClient.SetRetryCount(5)
|
httpClient.SetRetryCount(5)
|
||||||
|
|
||||||
params := srp.GetParams(4096)
|
params := srp.GetParams(4096)
|
||||||
@@ -776,7 +782,10 @@ func getFreshUserCredentials(email string, password string) (*api.GetLoginOneV2R
|
|||||||
func GetJwtTokenWithOrganizationId(oldJwtToken string, email string) string {
|
func GetJwtTokenWithOrganizationId(oldJwtToken string, email string) string {
|
||||||
log.Debug().Msg(fmt.Sprint("GetJwtTokenWithOrganizationId: ", "oldJwtToken", oldJwtToken))
|
log.Debug().Msg(fmt.Sprint("GetJwtTokenWithOrganizationId: ", "oldJwtToken", oldJwtToken))
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
httpClient.SetAuthToken(oldJwtToken)
|
httpClient.SetAuthToken(oldJwtToken)
|
||||||
|
|
||||||
organizationResponse, err := api.CallGetAllOrganizations(httpClient)
|
organizationResponse, err := api.CallGetAllOrganizations(httpClient)
|
||||||
@@ -811,7 +820,10 @@ func GetJwtTokenWithOrganizationId(oldJwtToken string, email string) string {
|
|||||||
for i < 6 {
|
for i < 6 {
|
||||||
mfaVerifyCode := askForMFACode(selectedOrgRes.MfaMethod)
|
mfaVerifyCode := askForMFACode(selectedOrgRes.MfaMethod)
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
httpClient.SetAuthToken(selectedOrgRes.Token)
|
httpClient.SetAuthToken(selectedOrgRes.Token)
|
||||||
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
verifyMFAresponse, mfaErrorResponse, requestError := api.CallVerifyMfaToken(httpClient, api.VerifyMfaTokenRequest{
|
||||||
Email: email,
|
Email: email,
|
||||||
@@ -913,7 +925,14 @@ func askToPasteJwtToken(success chan models.UserCredentials, failure chan error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// verify JTW
|
// verify JTW
|
||||||
httpClient := resty.New().
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
failure <- err
|
||||||
|
fmt.Println("Error getting resty client with custom headers", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.
|
||||||
SetAuthToken(userCredentials.JTWToken).
|
SetAuthToken(userCredentials.JTWToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/Infisical/infisical-merge/packages/visualize"
|
"github.com/Infisical/infisical-merge/packages/visualize"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/posthog/posthog-go"
|
"github.com/posthog/posthog-go"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -274,8 +273,12 @@ var secretsDeleteCmd = &cobra.Command{
|
|||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient := resty.New().
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
SetHeader("Accept", "application/json")
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
if projectId == "" {
|
if projectId == "" {
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ func issueCredentials(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
@@ -559,6 +560,7 @@ func signKey(cmd *cobra.Command, args []string) {
|
|||||||
SiteUrl: config.INFISICAL_URL,
|
SiteUrl: config.INFISICAL_URL,
|
||||||
UserAgent: api.USER_AGENT,
|
UserAgent: api.USER_AGENT,
|
||||||
AutoTokenRefresh: false,
|
AutoTokenRefresh: false,
|
||||||
|
CustomHeaders: os.Getenv("INFISICAL_CUSTOM_HEADERS"),
|
||||||
})
|
})
|
||||||
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
infisicalClient.Auth().SetAccessToken(infisicalToken)
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/crypto"
|
"github.com/Infisical/infisical-merge/packages/crypto"
|
||||||
"github.com/Infisical/infisical-merge/packages/util"
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -136,7 +135,11 @@ var tokensCreateCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make a call to the api to save the encrypted symmetric key details
|
// make a call to the api to save the encrypted symmetric key details
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to get resty client with custom headers")
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(loggedInUserDetails.UserCredentials.JTWToken).
|
httpClient.SetAuthToken(loggedInUserDetails.UserCredentials.JTWToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/systemd"
|
"github.com/Infisical/infisical-merge/packages/systemd"
|
||||||
|
"github.com/Infisical/infisical-merge/packages/util"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/pion/dtls/v3"
|
"github.com/pion/dtls/v3"
|
||||||
"github.com/pion/logging"
|
"github.com/pion/logging"
|
||||||
@@ -40,7 +41,11 @@ type Gateway struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGateway(identityToken string) (Gateway, error) {
|
func NewGateway(identityToken string) (Gateway, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := util.GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return Gateway{}, fmt.Errorf("unable to get client with custom headers [err=%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(identityToken)
|
httpClient.SetAuthToken(identityToken)
|
||||||
|
|
||||||
return Gateway{
|
return Gateway{
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/config"
|
"github.com/Infisical/infisical-merge/packages/config"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetHomeDir() (string, error) {
|
func GetHomeDir() (string, error) {
|
||||||
@@ -27,3 +29,25 @@ func ValidateInfisicalAPIConnection() (ok bool) {
|
|||||||
_, err := http.Get(fmt.Sprintf("%v/status", config.INFISICAL_URL))
|
_, err := http.Get(fmt.Sprintf("%v/status", config.INFISICAL_URL))
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRestyClientWithCustomHeaders() (*resty.Client, error) {
|
||||||
|
httpClient := resty.New()
|
||||||
|
customHeaders := os.Getenv("INFISICAL_CUSTOM_HEADERS")
|
||||||
|
if customHeaders != "" {
|
||||||
|
headers := map[string]string{}
|
||||||
|
pairs := strings.Split(customHeaders, " ")
|
||||||
|
for _, pair := range pairs {
|
||||||
|
kv := strings.SplitN(pair, "=", 2)
|
||||||
|
if len(kv) != 2 {
|
||||||
|
return nil, fmt.Errorf("invalid custom header format. Expected \"headerKey1=value1 headerKey2=value2 ....\" but got %v", customHeaders)
|
||||||
|
}
|
||||||
|
key := strings.TrimSpace(kv[0])
|
||||||
|
value := strings.TrimSpace(kv[1])
|
||||||
|
if !strings.EqualFold(key, "User-Agent") && !strings.EqualFold(key, "Accept") {
|
||||||
|
headers[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
httpClient.SetHeaders(headers)
|
||||||
|
}
|
||||||
|
return httpClient, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/config"
|
"github.com/Infisical/infisical-merge/packages/config"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/zalando/go-keyring"
|
"github.com/zalando/go-keyring"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,7 +84,12 @@ func GetCurrentLoggedInUserDetails(setConfigVariables bool) (LoggedInUserDetails
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check to to see if the JWT is still valid
|
// check to to see if the JWT is still valid
|
||||||
httpClient := resty.New().
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return LoggedInUserDetails{}, fmt.Errorf("getCurrentLoggedInUserDetails: unable to get client with custom headers [err=%s]", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.
|
||||||
SetAuthToken(userCreds.JTWToken).
|
SetAuthToken(userCreds.JTWToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -65,7 +64,11 @@ func GetAllFolders(params models.GetAllFoldersParameters) ([]models.SingleFolder
|
|||||||
|
|
||||||
func GetFoldersViaJTW(JTWToken string, workspaceId string, environmentName string, foldersPath string) ([]models.SingleFolder, error) {
|
func GetFoldersViaJTW(JTWToken string, workspaceId string, environmentName string, foldersPath string) ([]models.SingleFolder, error) {
|
||||||
// set up resty client
|
// set up resty client
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(JTWToken).
|
httpClient.SetAuthToken(JTWToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -100,7 +103,10 @@ func GetFoldersViaServiceToken(fullServiceToken string, workspaceId string, envi
|
|||||||
|
|
||||||
serviceToken := fmt.Sprintf("%v.%v.%v", serviceTokenParts[0], serviceTokenParts[1], serviceTokenParts[2])
|
serviceToken := fmt.Sprintf("%v.%v.%v", serviceTokenParts[0], serviceTokenParts[1], serviceTokenParts[2])
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get client with custom headers [err=%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(serviceToken).
|
httpClient.SetAuthToken(serviceToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
@@ -143,7 +149,11 @@ func GetFoldersViaServiceToken(fullServiceToken string, workspaceId string, envi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetFoldersViaMachineIdentity(accessToken string, workspaceId string, envSlug string, foldersPath string) ([]models.SingleFolder, error) {
|
func GetFoldersViaMachineIdentity(accessToken string, workspaceId string, envSlug string, foldersPath string) ([]models.SingleFolder, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(accessToken).
|
httpClient.SetAuthToken(accessToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -191,9 +201,12 @@ func CreateFolder(params models.CreateFolderParameters) (models.SingleFolder, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up resty client
|
// set up resty client
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
httpClient.
|
if err != nil {
|
||||||
SetAuthToken(params.InfisicalToken).
|
return models.SingleFolder{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.SetAuthToken(params.InfisicalToken).
|
||||||
SetHeader("Accept", "application/json").
|
SetHeader("Accept", "application/json").
|
||||||
SetHeader("Content-Type", "application/json")
|
SetHeader("Content-Type", "application/json")
|
||||||
|
|
||||||
@@ -238,9 +251,12 @@ func DeleteFolder(params models.DeleteFolderParameters) ([]models.SingleFolder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up resty client
|
// set up resty client
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
httpClient.
|
if err != nil {
|
||||||
SetAuthToken(params.InfisicalToken).
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.SetAuthToken(params.InfisicalToken).
|
||||||
SetHeader("Accept", "application/json").
|
SetHeader("Accept", "application/json").
|
||||||
SetHeader("Content-Type", "application/json")
|
SetHeader("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -120,7 +119,11 @@ func GetInfisicalToken(cmd *cobra.Command) (token *models.TokenDetails, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UniversalAuthLogin(clientId string, clientSecret string) (api.UniversalAuthLoginResponse, error) {
|
func UniversalAuthLogin(clientId string, clientSecret string) (api.UniversalAuthLoginResponse, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return api.UniversalAuthLoginResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetRetryCount(10000).
|
httpClient.SetRetryCount(10000).
|
||||||
SetRetryMaxWaitTime(20 * time.Second).
|
SetRetryMaxWaitTime(20 * time.Second).
|
||||||
SetRetryWaitTime(5 * time.Second)
|
SetRetryWaitTime(5 * time.Second)
|
||||||
@@ -135,7 +138,11 @@ func UniversalAuthLogin(clientId string, clientSecret string) (api.UniversalAuth
|
|||||||
|
|
||||||
func RenewMachineIdentityAccessToken(accessToken string) (string, error) {
|
func RenewMachineIdentityAccessToken(accessToken string) (string, error) {
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetRetryCount(10000).
|
httpClient.SetRetryCount(10000).
|
||||||
SetRetryMaxWaitTime(20 * time.Second).
|
SetRetryMaxWaitTime(20 * time.Second).
|
||||||
SetRetryWaitTime(5 * time.Second)
|
SetRetryWaitTime(5 * time.Second)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/Infisical/infisical-merge/packages/api"
|
"github.com/Infisical/infisical-merge/packages/api"
|
||||||
"github.com/Infisical/infisical-merge/packages/crypto"
|
"github.com/Infisical/infisical-merge/packages/crypto"
|
||||||
"github.com/Infisical/infisical-merge/packages/models"
|
"github.com/Infisical/infisical-merge/packages/models"
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/zalando/go-keyring"
|
"github.com/zalando/go-keyring"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -28,7 +27,10 @@ func GetPlainTextSecretsViaServiceToken(fullServiceToken string, environment str
|
|||||||
|
|
||||||
serviceToken := fmt.Sprintf("%v.%v.%v", serviceTokenParts[0], serviceTokenParts[1], serviceTokenParts[2])
|
serviceToken := fmt.Sprintf("%v.%v.%v", serviceTokenParts[0], serviceTokenParts[1], serviceTokenParts[2])
|
||||||
|
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get client with custom headers [err=%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(serviceToken).
|
httpClient.SetAuthToken(serviceToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
@@ -79,7 +81,11 @@ func GetPlainTextSecretsViaServiceToken(fullServiceToken string, environment str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPlainTextSecretsV3(accessToken string, workspaceId string, environmentName string, secretsPath string, includeImports bool, recursive bool, tagSlugs string, expandSecretReferences bool) (models.PlaintextSecretResult, error) {
|
func GetPlainTextSecretsV3(accessToken string, workspaceId string, environmentName string, secretsPath string, includeImports bool, recursive bool, tagSlugs string, expandSecretReferences bool) (models.PlaintextSecretResult, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return models.PlaintextSecretResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(accessToken).
|
httpClient.SetAuthToken(accessToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -122,7 +128,11 @@ func GetPlainTextSecretsV3(accessToken string, workspaceId string, environmentNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetSinglePlainTextSecretByNameV3(accessToken string, workspaceId string, environmentName string, secretsPath string, secretName string) (models.SingleEnvironmentVariable, string, error) {
|
func GetSinglePlainTextSecretByNameV3(accessToken string, workspaceId string, environmentName string, secretsPath string, secretName string) (models.SingleEnvironmentVariable, string, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return models.SingleEnvironmentVariable{}, "", err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(accessToken).
|
httpClient.SetAuthToken(accessToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -153,7 +163,11 @@ func GetSinglePlainTextSecretByNameV3(accessToken string, workspaceId string, en
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateDynamicSecretLease(accessToken string, projectSlug string, environmentName string, secretsPath string, slug string, ttl string) (models.DynamicSecretLease, error) {
|
func CreateDynamicSecretLease(accessToken string, projectSlug string, environmentName string, secretsPath string, slug string, ttl string) (models.DynamicSecretLease, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return models.DynamicSecretLease{}, err
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(accessToken).
|
httpClient.SetAuthToken(accessToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -525,7 +539,11 @@ func GetEnvelopmentBasedOnGitBranch(workspaceFile models.WorkspaceConfigFile) st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPlainTextWorkspaceKey(authenticationToken string, receiverPrivateKey string, workspaceId string) ([]byte, error) {
|
func GetPlainTextWorkspaceKey(authenticationToken string, receiverPrivateKey string, workspaceId string) ([]byte, error) {
|
||||||
httpClient := resty.New()
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("GetPlainTextWorkspaceKey: unable to get client with custom headers [err=%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
httpClient.SetAuthToken(authenticationToken).
|
httpClient.SetAuthToken(authenticationToken).
|
||||||
SetHeader("Accept", "application/json")
|
SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
@@ -672,9 +690,12 @@ func SetRawSecrets(secretArgs []string, secretType string, environmentName strin
|
|||||||
getAllEnvironmentVariablesRequest.InfisicalToken = tokenDetails.Token
|
getAllEnvironmentVariablesRequest.InfisicalToken = tokenDetails.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient := resty.New().
|
httpClient, err := GetRestyClientWithCustomHeaders()
|
||||||
SetAuthToken(tokenDetails.Token).
|
if err != nil {
|
||||||
SetHeader("Accept", "application/json")
|
return nil, fmt.Errorf("unable to get client with custom headers [err=%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.SetHeader("Accept", "application/json")
|
||||||
|
|
||||||
// pull current secrets
|
// pull current secrets
|
||||||
secrets, err := GetAllEnvironmentVariables(getAllEnvironmentVariablesRequest, "")
|
secrets, err := GetAllEnvironmentVariables(getAllEnvironmentVariablesRequest, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user