feat: added cacerts and some tidying
This commit is contained in:
parent
2112e7eefd
commit
bdd85b01ff
8 changed files with 279 additions and 59 deletions
49
cmd/list.go
49
cmd/list.go
|
|
@ -24,14 +24,16 @@ var listCmd = &cobra.Command{
|
|||
`,
|
||||
Args: cobra.NoArgs,
|
||||
Short: "List all files in a remote data directory",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
setenv(cmd, "host", "MAKESHIFT_HOST")
|
||||
setenv(cmd, "path", "MAKESHIFT_PATH")
|
||||
setenv(cmd, "cacert", "MAKESHIFT_CACERT")
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
path, _ = cmd.Flags().GetString("path")
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
path, _ = cmd.Flags().GetString("path")
|
||||
cacertPath, _ = cmd.Flags().GetString("cacert")
|
||||
|
||||
c = client.New(host)
|
||||
body []byte
|
||||
|
|
@ -42,8 +44,13 @@ var listCmd = &cobra.Command{
|
|||
log.Debug().
|
||||
Str("host", host).
|
||||
Str("path", path).
|
||||
Str("cacert", cacertPath).
|
||||
Send()
|
||||
|
||||
if cacertPath != "" {
|
||||
c.LoadCertificateFromPath(cacertPath)
|
||||
}
|
||||
|
||||
// make request to /list endpoint
|
||||
_, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||
Path: fmt.Sprintf("/list/%s", path),
|
||||
|
|
@ -80,7 +87,8 @@ var listPluginsCmd = &cobra.Command{
|
|||
Short: "Show plugins information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
cacertPath, _ = cmd.Flags().GetString("cacert")
|
||||
|
||||
c = client.New(host)
|
||||
res *http.Response
|
||||
|
|
@ -90,6 +98,15 @@ var listPluginsCmd = &cobra.Command{
|
|||
err error
|
||||
)
|
||||
|
||||
log.Debug().
|
||||
Str("host", host).
|
||||
Str("cacert", cacertPath).
|
||||
Send()
|
||||
|
||||
if cacertPath != "" {
|
||||
c.LoadCertificateFromPath(cacertPath)
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
// make request to /list endpoint
|
||||
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||
|
|
@ -121,11 +138,19 @@ var listPluginsCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
var listProfilesCmd = &cobra.Command{
|
||||
Use: "profiles",
|
||||
Use: "profiles",
|
||||
Example: `
|
||||
# list all profiles
|
||||
makeshift list profiles
|
||||
|
||||
# live individual profiles
|
||||
makeshift list profiles default custom
|
||||
`,
|
||||
Short: "Show all available profiles",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
host, _ = cmd.Flags().GetString("host")
|
||||
cacertPath, _ = cmd.Flags().GetString("cacert")
|
||||
|
||||
c = client.New(host)
|
||||
res *http.Response
|
||||
|
|
@ -135,6 +160,15 @@ var listProfilesCmd = &cobra.Command{
|
|||
err error
|
||||
)
|
||||
|
||||
log.Debug().
|
||||
Str("host", host).
|
||||
Str("cacert", cacertPath).
|
||||
Send()
|
||||
|
||||
if cacertPath != "" {
|
||||
c.LoadCertificateFromPath(cacertPath)
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
// make request to /list endpoint
|
||||
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||
|
|
@ -154,7 +188,7 @@ var listProfilesCmd = &cobra.Command{
|
|||
// make request to /list endpoint
|
||||
query = fmt.Sprintf("/profiles/%s", profileID)
|
||||
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||
Path: fmt.Sprintf(query),
|
||||
Path: query,
|
||||
Method: http.MethodGet,
|
||||
})
|
||||
handleResponseError(res, host, query, err)
|
||||
|
|
@ -174,6 +208,7 @@ var listProfilesCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
listCmd.PersistentFlags().String("host", "http://localhost:5050", "Set the configurator remote host (can be set with MAKESHIFT_HOST)")
|
||||
listCmd.PersistentFlags().String("cacert", "", "Set the CA certificate path to load")
|
||||
listCmd.Flags().StringP("path", "p", ".", "Set the path to list files (can be set with MAKESHIFT_PATH)")
|
||||
|
||||
listCmd.AddCommand(listPluginsCmd, listProfilesCmd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue