mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-07 22:53:55 -05:00
Revert "feat: confirm environment exists when running run command"
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,5 +1,3 @@
|
|||||||
.direnv/
|
|
||||||
|
|
||||||
# backend
|
# backend
|
||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
@@ -28,6 +26,8 @@ node_modules
|
|||||||
/.pnp
|
/.pnp
|
||||||
.pnp.js
|
.pnp.js
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
||||||
# testing
|
# testing
|
||||||
coverage
|
coverage
|
||||||
reports
|
reports
|
||||||
@@ -63,12 +63,10 @@ yarn-error.log*
|
|||||||
|
|
||||||
# Editor specific
|
# Editor specific
|
||||||
.vscode/*
|
.vscode/*
|
||||||
**/.idea/*
|
.idea/*
|
||||||
|
|
||||||
frontend-build
|
frontend-build
|
||||||
|
|
||||||
# cli
|
|
||||||
.go/
|
|
||||||
*.tgz
|
*.tgz
|
||||||
cli/infisical-merge
|
cli/infisical-merge
|
||||||
cli/test/infisical-merge
|
cli/test/infisical-merge
|
||||||
|
|||||||
@@ -2,12 +2,6 @@ package api
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Environment struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Slug string `json:"slug"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stores info for login one
|
// Stores info for login one
|
||||||
type LoginOneRequest struct {
|
type LoginOneRequest struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
@@ -20,6 +14,7 @@ type LoginOneResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stores info for login two
|
// Stores info for login two
|
||||||
|
|
||||||
type LoginTwoRequest struct {
|
type LoginTwoRequest struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
ClientProof string `json:"clientProof"`
|
ClientProof string `json:"clientProof"`
|
||||||
@@ -176,7 +171,6 @@ type Project struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Environments []Environment `json:"environments"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RawSecret struct {
|
type RawSecret struct {
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/api"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
|
|
||||||
"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/fatih/color"
|
"github.com/fatih/color"
|
||||||
@@ -62,11 +59,11 @@ var runCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
environmentSlug, _ := cmd.Flags().GetString("env")
|
environmentName, _ := cmd.Flags().GetString("env")
|
||||||
if !cmd.Flags().Changed("env") {
|
if !cmd.Flags().Changed("env") {
|
||||||
environmentFromWorkspace := util.GetEnvFromWorkspaceFile()
|
environmentFromWorkspace := util.GetEnvFromWorkspaceFile()
|
||||||
if environmentFromWorkspace != "" {
|
if environmentFromWorkspace != "" {
|
||||||
environmentSlug = environmentFromWorkspace
|
environmentName = environmentFromWorkspace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,20 +136,8 @@ var runCmd = &cobra.Command{
|
|||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msgf("Confirming selected environment is valid: %s", environmentSlug)
|
|
||||||
|
|
||||||
hasEnvironment, err := confirmProjectHasEnvironment(environmentSlug, projectId, token)
|
|
||||||
if err != nil {
|
|
||||||
util.HandleError(err, "Could not confirm project has environment")
|
|
||||||
}
|
|
||||||
if !hasEnvironment {
|
|
||||||
util.HandleError(fmt.Errorf("project does not have environment '%s'", environmentSlug))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debug().Msgf("Project '%s' has environment '%s'", projectId, environmentSlug)
|
|
||||||
|
|
||||||
request := models.GetAllSecretsParameters{
|
request := models.GetAllSecretsParameters{
|
||||||
Environment: environmentSlug,
|
Environment: environmentName,
|
||||||
WorkspaceId: projectId,
|
WorkspaceId: projectId,
|
||||||
TagSlugs: tagSlugs,
|
TagSlugs: tagSlugs,
|
||||||
SecretsPath: secretsPath,
|
SecretsPath: secretsPath,
|
||||||
@@ -323,6 +308,7 @@ func waitForExitCommand(cmd *exec.Cmd) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executeCommandWithWatchMode(commandFlag string, args []string, watchModeInterval int, request models.GetAllSecretsParameters, projectConfigDir string, secretOverriding bool, token *models.TokenDetails) {
|
func executeCommandWithWatchMode(commandFlag string, args []string, watchModeInterval int, request models.GetAllSecretsParameters, projectConfigDir string, secretOverriding bool, token *models.TokenDetails) {
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
var err error
|
var err error
|
||||||
var lastSecretsFetch time.Time
|
var lastSecretsFetch time.Time
|
||||||
@@ -453,53 +439,8 @@ func executeCommandWithWatchMode(commandFlag string, args []string, watchModeInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmProjectHasEnvironment(environmentSlug, projectId string, token *models.TokenDetails) (bool, error) {
|
|
||||||
var accessToken string
|
|
||||||
|
|
||||||
if token != nil && (token.Type == util.SERVICE_TOKEN_IDENTIFIER || token.Type == util.UNIVERSAL_AUTH_TOKEN_IDENTIFIER) {
|
|
||||||
accessToken = token.Token
|
|
||||||
} else {
|
|
||||||
util.RequireLogin()
|
|
||||||
util.RequireLocalWorkspaceFile()
|
|
||||||
|
|
||||||
loggedInUserDetails, err := util.GetCurrentLoggedInUserDetails(true)
|
|
||||||
if err != nil {
|
|
||||||
util.HandleError(err, "Unable to authenticate")
|
|
||||||
}
|
|
||||||
|
|
||||||
if loggedInUserDetails.LoginExpired {
|
|
||||||
util.PrintErrorMessageAndExit("Your login session has expired, please run [infisical login] and try again")
|
|
||||||
}
|
|
||||||
accessToken = loggedInUserDetails.UserCredentials.JTWToken
|
|
||||||
}
|
|
||||||
|
|
||||||
if projectId == "" {
|
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
|
||||||
if err != nil {
|
|
||||||
util.HandleError(err, "Unable to get local project details")
|
|
||||||
}
|
|
||||||
|
|
||||||
projectId = workspaceFile.WorkspaceId
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient := resty.New()
|
|
||||||
httpClient.SetAuthToken(accessToken).
|
|
||||||
SetHeader("Accept", "application/json")
|
|
||||||
|
|
||||||
project, err := api.CallGetProjectById(httpClient, projectId)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, env := range project.Environments {
|
|
||||||
if env.Slug == environmentSlug {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchAndFormatSecretsForShell(request models.GetAllSecretsParameters, projectConfigDir string, secretOverriding bool, token *models.TokenDetails) (models.InjectableEnvironmentResult, error) {
|
func fetchAndFormatSecretsForShell(request models.GetAllSecretsParameters, projectConfigDir string, secretOverriding bool, token *models.TokenDetails) (models.InjectableEnvironmentResult, error) {
|
||||||
|
|
||||||
if token != nil && token.Type == util.SERVICE_TOKEN_IDENTIFIER {
|
if token != nil && token.Type == util.SERVICE_TOKEN_IDENTIFIER {
|
||||||
request.InfisicalToken = token.Token
|
request.InfisicalToken = token.Token
|
||||||
} else if token != nil && token.Type == util.UNIVERSAL_AUTH_TOKEN_IDENTIFIER {
|
} else if token != nil && token.Type == util.UNIVERSAL_AUTH_TOKEN_IDENTIFIER {
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ func FilterSecretsByTag(plainTextSecrets []models.SingleEnvironmentVariable, tag
|
|||||||
|
|
||||||
func GetAllEnvironmentVariables(params models.GetAllSecretsParameters, projectConfigFilePath string) ([]models.SingleEnvironmentVariable, error) {
|
func GetAllEnvironmentVariables(params models.GetAllSecretsParameters, projectConfigFilePath string) ([]models.SingleEnvironmentVariable, error) {
|
||||||
var secretsToReturn []models.SingleEnvironmentVariable
|
var secretsToReturn []models.SingleEnvironmentVariable
|
||||||
|
// var serviceTokenDetails api.GetServiceTokenDetailsResponse
|
||||||
var errorToReturn error
|
var errorToReturn error
|
||||||
|
|
||||||
if params.InfisicalToken == "" && params.UniversalAuthAccessToken == "" {
|
if params.InfisicalToken == "" && params.UniversalAuthAccessToken == "" {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ func TestUniversalAuth_SecretsGetWrongEnvironment(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("snapshot failed: %v", err)
|
t.Fatalf("snapshot failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserAuth_SecretsGetAll(t *testing.T) {
|
func TestUserAuth_SecretsGetAll(t *testing.T) {
|
||||||
|
|||||||
10
flake.nix
10
flake.nix
@@ -14,21 +14,11 @@
|
|||||||
git
|
git
|
||||||
lazygit
|
lazygit
|
||||||
|
|
||||||
go
|
|
||||||
python312Full
|
python312Full
|
||||||
nodejs_20
|
nodejs_20
|
||||||
nodePackages.prettier
|
nodePackages.prettier
|
||||||
infisical
|
infisical
|
||||||
];
|
];
|
||||||
|
|
||||||
env = {
|
|
||||||
GOROOT = "${pkgs.go}/share/go";
|
|
||||||
};
|
|
||||||
|
|
||||||
shellHook = ''
|
|
||||||
export GOPATH="$(pwd)/.go"
|
|
||||||
mkdir -p "$GOPATH"
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user