mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 19:28:09 +00:00
Add watch interval
This commit is contained in:
+32
-10
@@ -36,6 +36,8 @@ var runCmd = &cobra.Command{
|
|||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
// Check if the --command flag has been set
|
// Check if the --command flag has been set
|
||||||
commandFlagSet := cmd.Flags().Changed("command")
|
commandFlagSet := cmd.Flags().Changed("command")
|
||||||
|
watchIntervalFlagSet := cmd.Flags().Changed("watch-interval")
|
||||||
|
watchFlagSet := cmd.Flags().Changed("watch")
|
||||||
|
|
||||||
// If the --command flag has been set, check if a value was provided
|
// If the --command flag has been set, check if a value was provided
|
||||||
if commandFlagSet {
|
if commandFlagSet {
|
||||||
@@ -55,6 +57,20 @@ var runCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the --watch flag has been set, the --watch-interval flag should also be set
|
||||||
|
if watchFlagSet && watchIntervalFlagSet {
|
||||||
|
// Ensure that the --watch-interval flag is set to a positive integer, and is at least 10 seconds
|
||||||
|
|
||||||
|
watchInterval, err := cmd.Flags().GetInt("watch-interval")
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to parse flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
if watchInterval < 5 {
|
||||||
|
return fmt.Errorf("watch interval must be at least 5 seconds, you passed %d seconds", watchInterval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
@@ -100,6 +116,11 @@ var runCmd = &cobra.Command{
|
|||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watchModeInterval, err := cmd.Flags().GetInt("watch-interval")
|
||||||
|
if err != nil {
|
||||||
|
util.HandleError(err, "Unable to parse flag")
|
||||||
|
}
|
||||||
|
|
||||||
shouldExpandSecrets, err := cmd.Flags().GetBool("expand")
|
shouldExpandSecrets, err := cmd.Flags().GetBool("expand")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.HandleError(err, "Unable to parse flag")
|
util.HandleError(err, "Unable to parse flag")
|
||||||
@@ -151,12 +172,12 @@ var runCmd = &cobra.Command{
|
|||||||
Set("multi-command", cmd.Flag("command").Value.String()).
|
Set("multi-command", cmd.Flag("command").Value.String()).
|
||||||
Set("version", util.CLI_VERSION))
|
Set("version", util.CLI_VERSION))
|
||||||
|
|
||||||
executeSpecifiedCommand(command, args, watchMode, request, projectConfigDir, shouldExpandSecrets, secretOverriding, token)
|
executeSpecifiedCommand(command, args, watchMode, watchModeInterval, request, projectConfigDir, shouldExpandSecrets, secretOverriding, token)
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeSpecifiedCommand(commandFlag string, args []string, watchMode bool, request models.GetAllSecretsParameters, projectConfigDir string, expandSecrets bool, secretOverriding bool, token *models.TokenDetails) {
|
func executeSpecifiedCommand(commandFlag string, args []string, watchMode bool, watchModeInterval int, request models.GetAllSecretsParameters, projectConfigDir string, expandSecrets bool, secretOverriding bool, token *models.TokenDetails) {
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
var err error
|
var err error
|
||||||
@@ -264,7 +285,7 @@ func executeSpecifiedCommand(commandFlag string, args []string, watchMode bool,
|
|||||||
// a simple goroutine that triggers the recheckSecretsChan every 5 seconds
|
// a simple goroutine that triggers the recheckSecretsChan every 5 seconds
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(time.Duration(watchModeInterval) * time.Second)
|
||||||
recheckSecretsChannel <- true
|
recheckSecretsChannel <- true
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -324,14 +345,15 @@ func filterReservedEnvVars(env map[string]models.SingleEnvironmentVariable) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(runCmd)
|
rootCmd.AddCommand(runCmd)
|
||||||
runCmd.Flags().String("token", "", "Fetch secrets using service token or machine identity access token")
|
runCmd.Flags().String("token", "", "fetch secrets using service token or machine identity access token")
|
||||||
runCmd.Flags().String("projectId", "", "manually set the project ID to fetch secrets from when using machine identity based auth")
|
runCmd.Flags().String("projectId", "", "manually set the project ID to fetch secrets from when using machine identity based auth")
|
||||||
runCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from")
|
runCmd.Flags().StringP("env", "e", "dev", "set the environment (dev, prod, etc.) from which your secrets should be pulled from")
|
||||||
runCmd.Flags().Bool("expand", true, "Parse shell parameter expansions in your secrets")
|
runCmd.Flags().Bool("expand", true, "parse shell parameter expansions in your secrets")
|
||||||
runCmd.Flags().Bool("include-imports", true, "Import linked secrets ")
|
runCmd.Flags().Bool("include-imports", true, "import linked secrets ")
|
||||||
runCmd.Flags().Bool("recursive", false, "Fetch secrets from all sub-folders")
|
runCmd.Flags().Bool("recursive", false, "fetch secrets from all sub-folders")
|
||||||
runCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets")
|
runCmd.Flags().Bool("secret-overriding", true, "prioritizes personal secrets, if any, with the same name over shared secrets")
|
||||||
runCmd.Flags().Bool("watch", false, "Enable reload of application when secrets change")
|
runCmd.Flags().Bool("watch", false, "enable reload of application when secrets change")
|
||||||
|
runCmd.Flags().Int("watch-interval", 10, "interval in seconds to check for secret changes")
|
||||||
runCmd.Flags().StringP("command", "c", "", "chained commands to execute (e.g. \"npm install && npm run dev; echo ...\")")
|
runCmd.Flags().StringP("command", "c", "", "chained commands to execute (e.g. \"npm install && npm run dev; echo ...\")")
|
||||||
runCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs ")
|
runCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs ")
|
||||||
runCmd.Flags().String("path", "/", "get secrets within a folder path")
|
runCmd.Flags().String("path", "/", "get secrets within a folder path")
|
||||||
|
|||||||
Reference in New Issue
Block a user