2022-07-12 16:49:39 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/api/contexts"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VarCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *VarCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad var <subcommand> [options] [args]
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
This command groups subcommands for interacting with variables. Variables
|
|
|
|
allow operators to provide credentials and otherwise sensitive material to
|
|
|
|
Nomad jobs at runtime via the template stanza or directly through
|
2022-07-12 16:49:39 +00:00
|
|
|
the Nomad API and CLI.
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
Users can create new variables; list, inspect, and delete existing
|
|
|
|
variables, and more. For a full guide on variables see:
|
2022-07-12 16:49:39 +00:00
|
|
|
https://www.nomadproject.io/guides/vars.html
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
Create a variable specification file:
|
2022-07-12 16:49:39 +00:00
|
|
|
|
|
|
|
$ nomad var init
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
Upsert a variable:
|
2022-07-12 16:49:39 +00:00
|
|
|
|
|
|
|
$ nomad var put <path>
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
Examine a variable:
|
2022-07-12 16:49:39 +00:00
|
|
|
|
|
|
|
$ nomad var get <path>
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
List existing variables:
|
2022-07-12 16:49:39 +00:00
|
|
|
|
|
|
|
$ nomad var list <prefix>
|
|
|
|
|
|
|
|
Please see the individual subcommand help for detailed usage information.
|
|
|
|
`
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *VarCommand) Synopsis() string {
|
2022-08-26 18:03:56 +00:00
|
|
|
return "Interact with variables"
|
2022-07-12 16:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *VarCommand) Name() string { return "var" }
|
|
|
|
|
|
|
|
func (f *VarCommand) Run(args []string) int {
|
|
|
|
return cli.RunResultHelp
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
// VariablePathPredictor returns a var predictor
|
|
|
|
func VariablePathPredictor(factory ApiClientFactory) complete.Predictor {
|
2022-07-12 16:49:39 +00:00
|
|
|
return complete.PredictFunc(func(a complete.Args) []string {
|
|
|
|
client, err := factory()
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Variables, nil)
|
2022-07-12 16:49:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return []string{}
|
|
|
|
}
|
2022-08-26 18:03:56 +00:00
|
|
|
return resp.Matches[contexts.Variables]
|
2022-07-12 16:49:39 +00:00
|
|
|
})
|
|
|
|
}
|