mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 07:26:45 +00:00
Merge remote-tracking branch 'origin' into mfa
This commit is contained in:
@@ -56,7 +56,7 @@ var initCmd = &cobra.Command{
|
|||||||
workspaces := workspaceResponse.Workspaces
|
workspaces := workspaceResponse.Workspaces
|
||||||
if len(workspaces) == 0 {
|
if len(workspaces) == 0 {
|
||||||
message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", util.INFISICAL_TOKEN_NAME)
|
message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", util.INFISICAL_TOKEN_NAME)
|
||||||
util.PrintMessageAndExit(message)
|
util.PrintErrorMessageAndExit(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
var workspaceNames []string
|
var workspaceNames []string
|
||||||
|
|||||||
+44
-19
@@ -92,15 +92,13 @@ var secretsSetCmd = &cobra.Command{
|
|||||||
PreRun: toggleDebug,
|
PreRun: toggleDebug,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
util.RequireLocalWorkspaceFile()
|
||||||
|
|
||||||
environmentName, err := cmd.Flags().GetString("env")
|
environmentName, err := cmd.Flags().GetString("env")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !util.IsSecretEnvironmentValid(environmentName) {
|
|
||||||
util.PrintMessageAndExit("You have entered a invalid environment name", "Environment names can only be prod, dev, test or staging")
|
|
||||||
}
|
|
||||||
|
|
||||||
workspaceFile, err := util.GetWorkSpaceFromFile()
|
workspaceFile, err := util.GetWorkSpaceFromFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to get your local config details")
|
util.HandleError(err, "Unable to get your local config details")
|
||||||
@@ -153,11 +151,11 @@ var secretsSetCmd = &cobra.Command{
|
|||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
splitKeyValueFromArg := strings.SplitN(arg, "=", 2)
|
splitKeyValueFromArg := strings.SplitN(arg, "=", 2)
|
||||||
if splitKeyValueFromArg[0] == "" || splitKeyValueFromArg[1] == "" {
|
if splitKeyValueFromArg[0] == "" || splitKeyValueFromArg[1] == "" {
|
||||||
util.PrintMessageAndExit("ensure that each secret has a none empty key and value. Modify the input and try again")
|
util.PrintErrorMessageAndExit("ensure that each secret has a none empty key and value. Modify the input and try again")
|
||||||
}
|
}
|
||||||
|
|
||||||
if unicode.IsNumber(rune(splitKeyValueFromArg[0][0])) {
|
if unicode.IsNumber(rune(splitKeyValueFromArg[0][0])) {
|
||||||
util.PrintMessageAndExit("keys of secrets cannot start with a number. Modify the key name(s) and try again")
|
util.PrintErrorMessageAndExit("keys of secrets cannot start with a number. Modify the key name(s) and try again")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key and value from argument
|
// Key and value from argument
|
||||||
@@ -308,7 +306,7 @@ var secretsDeleteCmd = &cobra.Command{
|
|||||||
|
|
||||||
if len(invalidSecretNamesThatDoNotExist) != 0 {
|
if len(invalidSecretNamesThatDoNotExist) != 0 {
|
||||||
message := fmt.Sprintf("secret name(s) [%v] does not exist in your project. To see which secrets exist run [infisical secrets]", strings.Join(invalidSecretNamesThatDoNotExist, ", "))
|
message := fmt.Sprintf("secret name(s) [%v] does not exist in your project. To see which secrets exist run [infisical secrets]", strings.Join(invalidSecretNamesThatDoNotExist, ", "))
|
||||||
util.PrintMessageAndExit(message)
|
util.PrintErrorMessageAndExit(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
request := api.BatchDeleteSecretsBySecretIdsRequest{
|
request := api.BatchDeleteSecretsBySecretIdsRequest{
|
||||||
@@ -337,11 +335,6 @@ func getSecretsByNames(cmd *cobra.Command, args []string) {
|
|||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceFileExists := util.WorkspaceConfigFileExistsInCurrentPath()
|
|
||||||
if !workspaceFileExists {
|
|
||||||
util.HandleError(err, "Unable to parse flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
infisicalToken, err := cmd.Flags().GetString("token")
|
infisicalToken, err := cmd.Flags().GetString("token")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
@@ -385,11 +378,6 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
|
|||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceFileExists := util.WorkspaceConfigFileExistsInCurrentPath()
|
|
||||||
if !workspaceFileExists {
|
|
||||||
util.HandleError(err, "Unable to parse flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
infisicalToken, err := cmd.Flags().GetString("token")
|
infisicalToken, err := cmd.Flags().GetString("token")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
@@ -406,6 +394,11 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tagsHashToSecretKey := make(map[string]int)
|
tagsHashToSecretKey := make(map[string]int)
|
||||||
|
slugsToFilerBy := make(map[string]int)
|
||||||
|
|
||||||
|
for _, slug := range strings.Split(tagSlugs, ",") {
|
||||||
|
slugsToFilerBy[slug] = 1
|
||||||
|
}
|
||||||
|
|
||||||
type TagsAndSecrets struct {
|
type TagsAndSecrets struct {
|
||||||
Secrets []models.SingleEnvironmentVariable
|
Secrets []models.SingleEnvironmentVariable
|
||||||
@@ -422,6 +415,25 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
|
|||||||
return len(secrets[i].Tags) > len(secrets[j].Tags)
|
return len(secrets[i].Tags) > len(secrets[j].Tags)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for i, secret := range secrets {
|
||||||
|
filteredTag := []struct {
|
||||||
|
ID string "json:\"_id\""
|
||||||
|
Name string "json:\"name\""
|
||||||
|
Slug string "json:\"slug\""
|
||||||
|
Workspace string "json:\"workspace\""
|
||||||
|
}{}
|
||||||
|
|
||||||
|
for _, secretTag := range secret.Tags {
|
||||||
|
_, exists := slugsToFilerBy[secretTag.Slug]
|
||||||
|
if !exists {
|
||||||
|
filteredTag = append(filteredTag, secretTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
secret.Tags = filteredTag
|
||||||
|
secrets[i] = secret
|
||||||
|
}
|
||||||
|
|
||||||
for _, secret := range secrets {
|
for _, secret := range secrets {
|
||||||
listOfTagSlugs := []string{}
|
listOfTagSlugs := []string{}
|
||||||
|
|
||||||
@@ -485,6 +497,8 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
|
|||||||
return len(listOfsecretDetails[i].Tags) < len(listOfsecretDetails[j].Tags)
|
return len(listOfsecretDetails[i].Tags) < len(listOfsecretDetails[j].Tags)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tableOfContents := []string{}
|
||||||
|
fullyGeneratedDocuments := []string{}
|
||||||
for _, secretDetails := range listOfsecretDetails {
|
for _, secretDetails := range listOfsecretDetails {
|
||||||
listOfKeyValue := []string{}
|
listOfKeyValue := []string{}
|
||||||
|
|
||||||
@@ -525,11 +539,22 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
|
|||||||
heading := CenterString(strings.Join(listOfTagNames, " & "), 80)
|
heading := CenterString(strings.Join(listOfTagNames, " & "), 80)
|
||||||
|
|
||||||
if len(listOfTagNames) == 0 {
|
if len(listOfTagNames) == 0 {
|
||||||
fmt.Printf("\n%s \n", strings.Join(listOfKeyValue, "\n \n"))
|
fullyGeneratedDocuments = append(fullyGeneratedDocuments, fmt.Sprintf("\n%s \n", strings.Join(listOfKeyValue, "\n")))
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("\n\n\n%s \n%s \n", heading, strings.Join(listOfKeyValue, "\n \n"))
|
fullyGeneratedDocuments = append(fullyGeneratedDocuments, fmt.Sprintf("\n\n\n%s \n%s \n", heading, strings.Join(listOfKeyValue, "\n")))
|
||||||
|
tableOfContents = append(tableOfContents, strings.ToUpper(strings.Join(listOfTagNames, " & ")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dashedList := []string{}
|
||||||
|
for _, item := range tableOfContents {
|
||||||
|
dashedList = append(dashedList, fmt.Sprintf("# - %s \n", item))
|
||||||
|
}
|
||||||
|
if len(dashedList) > 0 {
|
||||||
|
fmt.Println(CenterString("TABLE OF CONTENTS", 80))
|
||||||
|
fmt.Println(strings.Join(dashedList, ""))
|
||||||
|
}
|
||||||
|
fmt.Println(strings.Join(fullyGeneratedDocuments, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CenterString(s string, numStars int) string {
|
func CenterString(s string, numStars int) string {
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ type Workspace struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WorkspaceConfigFile struct {
|
type WorkspaceConfigFile struct {
|
||||||
WorkspaceId string `json:"workspaceId"`
|
WorkspaceId string `json:"workspaceId"`
|
||||||
|
DefaultEnvironment string `json:"defaultEnvironment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SymmetricEncryptionResult struct {
|
type SymmetricEncryptionResult struct {
|
||||||
|
|||||||
@@ -65,29 +65,29 @@ func RequireLogin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !currentUserDetails.IsUserLoggedIn {
|
if !currentUserDetails.IsUserLoggedIn {
|
||||||
PrintMessageAndExit("You must be logged in to run this command. To login, run [infisical login]")
|
PrintErrorMessageAndExit("You must be logged in to run this command. To login, run [infisical login]")
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentUserDetails.LoginExpired {
|
if currentUserDetails.LoginExpired {
|
||||||
PrintMessageAndExit("Your login expired, please login in again. To login, run [infisical login]")
|
PrintErrorMessageAndExit("Your login expired, please login in again. To login, run [infisical login]")
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentUserDetails.UserCredentials.Email == "" && currentUserDetails.UserCredentials.JTWToken == "" && currentUserDetails.UserCredentials.PrivateKey == "" {
|
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]")
|
PrintErrorMessageAndExit("One or more of your login details is empty. Please try logging in again via by running [infisical login]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireServiceToken() {
|
func RequireServiceToken() {
|
||||||
serviceToken := os.Getenv(INFISICAL_TOKEN_NAME)
|
serviceToken := os.Getenv(INFISICAL_TOKEN_NAME)
|
||||||
if serviceToken == "" {
|
if serviceToken == "" {
|
||||||
PrintMessageAndExit("No service token is found in your terminal")
|
PrintErrorMessageAndExit("No service token is found in your terminal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireLocalWorkspaceFile() {
|
func RequireLocalWorkspaceFile() {
|
||||||
workspaceFileExists := WorkspaceConfigFileExistsInCurrentPath()
|
workspaceFileExists := WorkspaceConfigFileExistsInCurrentPath()
|
||||||
if !workspaceFileExists {
|
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")
|
PrintErrorMessageAndExit("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()
|
workspaceFile, err := GetWorkSpaceFromFile()
|
||||||
@@ -96,7 +96,7 @@ func RequireLocalWorkspaceFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if workspaceFile.WorkspaceId == "" {
|
if workspaceFile.WorkspaceId == "" {
|
||||||
PrintMessageAndExit("Your project id is missing in your local config file. Please add it or run again [infisical init]")
|
PrintErrorMessageAndExit("Your project id is missing in your local config file. Please add it or run again [infisical init]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ func PrintSuccessMessage(message string) {
|
|||||||
color.New(color.FgGreen).Println(message)
|
color.New(color.FgGreen).Println(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintMessageAndExit(messages ...string) {
|
func PrintErrorMessageAndExit(messages ...string) {
|
||||||
if len(messages) > 0 {
|
if len(messages) > 0 {
|
||||||
for _, message := range messages {
|
for _, message := range messages {
|
||||||
fmt.Println(message)
|
fmt.Fprintln(os.Stderr, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,5 +42,5 @@ func PrintMessageAndExit(messages ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printError(e error) {
|
func printError(e error) {
|
||||||
color.Red("Hmm, we ran into an error: %v", e)
|
color.New(color.FgRed).Fprintf(os.Stderr, "Hmm, we ran into an error: %v", e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ func GetAllEnvironmentVariables(params models.GetAllSecretsParameters) ([]models
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if workspaceFile.DefaultEnvironment != "" {
|
||||||
|
params.Environment = workspaceFile.DefaultEnvironment
|
||||||
|
}
|
||||||
|
|
||||||
// Verify environment
|
// Verify environment
|
||||||
err = ValidateEnvironmentName(params.Environment, workspaceFile.WorkspaceId, loggedInUserDetails.UserCredentials)
|
err = ValidateEnvironmentName(params.Environment, workspaceFile.WorkspaceId, loggedInUserDetails.UserCredentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user