From 5fa675b203d77cd4245b3f1e9b33b174c37da5b2 Mon Sep 17 00:00:00 2001 From: Mist Gitlab Runner Date: Tue, 16 Nov 2021 10:37:23 +0000 Subject: [PATCH 1/5] Regenerate mist-cli after: Improve clone operation --- mist-api-v2.go | 807 ++++++++++++++++++++++++++----------------------- 1 file changed, 425 insertions(+), 382 deletions(-) diff --git a/mist-api-v2.go b/mist-api-v2.go index 2a699c4..d25c5e4 100644 --- a/mist-api-v2.go +++ b/mist-api-v2.go @@ -206,9 +206,9 @@ func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, m return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditCloud Edit cloud -func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-cloud" +// MistApiV2RemoveCloud Remove cloud +func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "remove-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -226,11 +226,7 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Put().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -257,9 +253,9 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RemoveCloud Remove cloud -func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "remove-cloud" +// MistApiV2GetCloud Get cloud +func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -277,7 +273,20 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -286,7 +295,7 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -298,15 +307,15 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetCloud Get cloud -func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-cloud" +// MistApiV2EditCloud Edit cloud +func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -324,19 +333,10 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -346,7 +346,7 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -358,10 +358,10 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2ListClusters List clusters @@ -1550,7 +1550,7 @@ func MistApiV2AssociateKey(paramMachine string, params *viper.Viper, body string } // MistApiV2CloneMachine Clone machine -func MistApiV2CloneMachine(paramMachine string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { +func MistApiV2CloneMachine(paramMachine string, paramName string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { handlerPath := "clone-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath @@ -1571,6 +1571,13 @@ func MistApiV2CloneMachine(paramMachine string, params *viper.Viper, body string req := cli.Client.Post().URL(url) + req = req.AddQuery("name", paramName) + + paramAsync := params.GetBool("async") + if paramAsync != false { + req = req.AddQuery("async", fmt.Sprintf("%v", paramAsync)) + } + if body != "" { req = req.AddHeader("Content-Type", "").BodyString(body) } @@ -2361,6 +2368,56 @@ func MistApiV2RevertToSnapshot(paramMachine string, paramSnapshot string, params return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } +// MistApiV2CreateNetwork Create network +func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-network" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/networks" + + req := cli.Client.Post().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) + } + + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + } + + var decoded map[string]interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) + } + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after.(map[string]interface{}) + } + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + // MistApiV2ListNetworks List networks func MistApiV2ListNetworks(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-networks" @@ -2436,9 +2493,9 @@ func MistApiV2ListNetworks(params *viper.Viper) (*gentleman.Response, map[string return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "external_id", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2CreateNetwork Create network -func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-network" +// MistApiV2EditNetwork Edit network +func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-network" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -2453,12 +2510,18 @@ func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Respon return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/networks" + url := server + "/api/v2/networks/{network}" + url = strings.Replace(url, "{network}", paramNetwork, 1) - req := cli.Client.Post().URL(url) + req := cli.Client.Put().URL(url) + + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + } if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -2468,7 +2531,7 @@ func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Respon return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -2480,7 +2543,7 @@ func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Respon after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil @@ -2591,62 +2654,6 @@ func MistApiV2GetNetwork(paramNetwork string, params *viper.Viper) (*gentleman.R return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2EditNetwork Edit network -func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-network" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/networks/{network}" - url = strings.Replace(url, "{network}", paramNetwork, 1) - - req := cli.Client.Put().URL(url) - - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) - } - - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) - } - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - // MistApiV2ListOrgs List orgs func MistApiV2ListOrgs(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-orgs" @@ -3088,9 +3095,9 @@ func MistApiV2AddRule(params *viper.Viper, body string) (*gentleman.Response, ma return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2ToggleRule Toggle rule -func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "toggle-rule" +// MistApiV2GetRule Get rule +func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3108,12 +3115,15 @@ func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Vip url := server + "/api/v2/rules/{rule}" url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Put().URL(url) - - req = req.AddQuery("action", paramAction) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) } cli.HandleBefore(handlerPath, params, req) @@ -3123,7 +3133,7 @@ func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Vip return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3135,15 +3145,15 @@ func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Vip after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "queries", "actions", "tags"}, []string{"id", "name", "resource_type", "selectors", "queries", "actions", "window", "frequency", "tags"}, []string{}, []string{}}, nil } -// MistApiV2DeleteRule Delete rule -func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-rule" +// MistApiV2RenameRule Rename rule +func MistApiV2RenameRule(paramRule string, paramName string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "rename-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3161,7 +3171,13 @@ func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Resp url := server + "/api/v2/rules/{rule}" url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Patch().URL(url) + + req = req.AddQuery("name", paramName) + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -3188,9 +3204,9 @@ func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Resp return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetRule Get rule -func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-rule" +// MistApiV2EditRule Update rule +func MistApiV2EditRule(paramRule string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3208,15 +3224,10 @@ func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Respons url := server + "/api/v2/rules/{rule}" url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3241,12 +3252,12 @@ func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Respons decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "queries", "actions", "tags"}, []string{"id", "name", "resource_type", "selectors", "queries", "actions", "window", "frequency", "tags"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RenameRule Rename rule -func MistApiV2RenameRule(paramRule string, paramName string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "rename-rule" +// MistApiV2ToggleRule Toggle rule +func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "toggle-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3264,9 +3275,9 @@ func MistApiV2RenameRule(paramRule string, paramName string, params *viper.Viper url := server + "/api/v2/rules/{rule}" url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Patch().URL(url) + req := cli.Client.Put().URL(url) - req = req.AddQuery("name", paramName) + req = req.AddQuery("action", paramAction) if body != "" { req = req.AddHeader("Content-Type", "").BodyString(body) @@ -3297,9 +3308,9 @@ func MistApiV2RenameRule(paramRule string, paramName string, params *viper.Viper return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditRule Update rule -func MistApiV2EditRule(paramRule string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-rule" +// MistApiV2DeleteRule Delete rule +func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3317,11 +3328,7 @@ func MistApiV2EditRule(paramRule string, params *viper.Viper, body string) (*gen url := server + "/api/v2/rules/{rule}" url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Post().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -3330,7 +3337,7 @@ func MistApiV2EditRule(paramRule string, params *viper.Viper, body string) (*gen return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3342,7 +3349,7 @@ func MistApiV2EditRule(paramRule string, params *viper.Viper, body string) (*gen after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil @@ -3469,9 +3476,9 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RunScript Run script -func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "run-script" +// MistApiV2GetScript Get script +func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3489,10 +3496,15 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -3517,12 +3529,12 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2EditScript Edit script -func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-script" +// MistApiV2RunScript Run script +func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "run-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3540,19 +3552,10 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Put().URL(url) - - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) - } - paramDescription := params.GetString("description") - if paramDescription != "" { - req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) - } + req := cli.Client.Post().URL(url) if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3562,7 +3565,7 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3574,15 +3577,15 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteScript Delete script -func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-script" +// MistApiV2EditScript Edit script +func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3600,7 +3603,20 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Put().URL(url) + + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + } + paramDescription := params.GetString("description") + if paramDescription != "" { + req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + } + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -3627,9 +3643,9 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetScript Get script -func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-script" +// MistApiV2DeleteScript Delete script +func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3647,16 +3663,7 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Get().URL(url) - - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -3665,7 +3672,7 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3677,10 +3684,10 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2DownloadScript Download script @@ -4388,9 +4395,9 @@ func MistApiV2CreateZone(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteZone Delete zone -func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-zone" +// MistApiV2GetZone Get zone +func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4408,7 +4415,16 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -4417,7 +4433,7 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4429,15 +4445,15 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetZone Get zone -func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-zone" +// MistApiV2EditZone Edit zone +func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4455,15 +4471,10 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -4473,7 +4484,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4485,15 +4496,15 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditZone Edit zone -func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-zone" +// MistApiV2DeleteZone Delete zone +func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4511,11 +4522,7 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Put().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -4735,7 +4742,7 @@ func mistApiV2Register(subcommand bool) { Group: "clouds", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -4752,6 +4759,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4767,19 +4775,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-cloud cloud", - Short: "Edit cloud", - Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), + Use: "remove-cloud cloud", + Short: "Remove cloud", + Long: cli.Markdown("Remove target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4806,15 +4810,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "remove-cloud cloud", - Short: "Remove cloud", - Long: cli.Markdown("Remove target cloud"), + Use: "get-cloud cloud", + Short: "Get cloud", + Long: cli.Markdown("Get details about target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4827,6 +4831,10 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -4841,15 +4849,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-cloud cloud", - Short: "Get cloud", - Long: cli.Markdown("Get details about target cloud"), + Use: "edit-cloud cloud", + Short: "Edit cloud", + Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4861,10 +4873,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4930,7 +4939,7 @@ func mistApiV2Register(subcommand bool) { Group: "clusters", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -4947,6 +4956,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5242,7 +5252,7 @@ func mistApiV2Register(subcommand bool) { Group: "keys", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5259,6 +5269,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5356,7 +5367,7 @@ func mistApiV2Register(subcommand bool) { Group: "keys", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5373,6 +5384,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cmd.Flags().String("name", "", "New key name") cmd.Flags().String("default", "", "Set as default") @@ -5522,7 +5534,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5557,6 +5569,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cmd.Flags().BoolP("wait", "w", false, "Wait job") @@ -5619,7 +5632,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:]) + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5636,6 +5649,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5658,7 +5672,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:]) + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5675,6 +5689,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5690,19 +5705,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "clone-machine machine", + Use: "clone-machine machine name", Short: "Clone machine", Long: cli.Markdown("Clone target machine"), Example: examples, Group: "machines", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2CloneMachine(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2CloneMachine(args[0], args[1], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5714,6 +5729,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("async", "", "") cli.SetCustomFlags(cmd) @@ -5736,7 +5754,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5753,6 +5771,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5775,7 +5794,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5792,6 +5811,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5849,7 +5869,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5866,6 +5886,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5888,7 +5909,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5905,6 +5926,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5927,7 +5949,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5944,6 +5966,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5966,7 +5989,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -5983,6 +6006,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6005,7 +6029,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6022,6 +6046,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6044,7 +6069,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6061,6 +6086,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6083,7 +6109,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6100,6 +6126,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6122,7 +6149,7 @@ func mistApiV2Register(subcommand bool) { Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6139,6 +6166,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6196,7 +6224,7 @@ func mistApiV2Register(subcommand bool) { Group: "snapshots", Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6213,6 +6241,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6270,7 +6299,7 @@ func mistApiV2Register(subcommand bool) { Group: "snapshots", Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6287,6 +6316,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6302,15 +6332,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-networks", - Short: "List networks", - Long: cli.Markdown("List networks owned by the active org. READ permission required on network & cloud."), + Use: "create-network", + Short: "Create network", + Long: cli.Markdown("Creates one or more networks on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. CREATE permission required on network.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n extra:\n description: Configure additional parameters, e.g. cidr (EC2 network)\n type: object\n name:\n description: Specify network name\n example: my-network\n type: string\n save:\n description: Save provisioning plan as template\n type: boolean\n tags:\n description: Assign tags to provisioned network\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\ntype: object\n"), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListNetworks(params) + _, decoded, outputOptions, err := MistApiV2CreateNetwork(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6322,14 +6356,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6345,19 +6372,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-network", - Short: "Create network", - Long: cli.Markdown("Creates one or more networks on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. CREATE permission required on network.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n extra:\n description: Configure additional parameters, e.g. cidr (EC2 network)\n type: object\n name:\n description: Specify network name\n example: my-network\n type: string\n save:\n description: Save provisioning plan as template\n type: boolean\n tags:\n description: Assign tags to provisioned network\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\ntype: object\n"), + Use: "list-networks", + Short: "List networks", + Long: cli.Markdown("List networks owned by the active org. READ permission required on network & cloud."), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateNetwork(params, body) + _, decoded, outputOptions, err := MistApiV2ListNetworks(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6370,6 +6393,14 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -6384,15 +6415,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-network network cloud", - Short: "Delete network", - Long: cli.Markdown("Delete target network"), + Use: "edit-network network", + Short: "Edit network", + Long: cli.Markdown("Edit target network"), Example: examples, Group: "networks", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteNetwork(args[0], args[1], params) + _, decoded, outputOptions, err := MistApiV2EditNetwork(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6404,6 +6439,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("name", "", "New network name") cli.SetCustomFlags(cmd) @@ -6419,15 +6457,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-network network", - Short: "Get network", - Long: cli.Markdown("Get details about target network"), + Use: "delete-network network cloud", + Short: "Delete network", + Long: cli.Markdown("Delete target network"), Example: examples, Group: "networks", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2GetNetwork(args[0], params) + _, decoded, outputOptions, err := MistApiV2DeleteNetwork(args[0], args[1], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6440,9 +6478,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -6457,19 +6492,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-network network", - Short: "Edit network", - Long: cli.Markdown("Edit target network"), + Use: "get-network network", + Short: "Get network", + Long: cli.Markdown("Get details about target network"), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditNetwork(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetNetwork(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6482,7 +6513,8 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("name", "", "New network name") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -6747,7 +6779,7 @@ func mistApiV2Register(subcommand bool) { Group: "rules", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -6764,6 +6796,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6779,19 +6812,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "toggle-rule rule action", - Short: "Toggle rule", - Long: cli.Markdown("Enable or disable a rule"), + Use: "get-rule rule", + Short: "Get rule", + Long: cli.Markdown("Get details about target rule"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2ToggleRule(args[0], args[1], params, body) + _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6804,6 +6833,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -6818,15 +6850,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-rule rule", - Short: "Delete rule", - Long: cli.Markdown("Delete a rule given its UUID."), + Use: "rename-rule rule name", + Short: "Rename rule", + Long: cli.Markdown("Rename a rule"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[2:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) + _, decoded, outputOptions, err := MistApiV2RenameRule(args[0], args[1], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6838,6 +6874,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6853,15 +6890,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-rule rule", - Short: "Get rule", - Long: cli.Markdown("Get details about target rule"), + Use: "edit-rule rule", + Short: "Update rule", + Long: cli.Markdown("Edit a rule given its UUID, EDIT permission required on rule\n## Request Schema (application/json)\n\nproperties:\n actions:\n $ref: '#/components/schemas/RuleActions'\n frequency:\n $ref: '#/components/schemas/Frequency'\n queries:\n $ref: '#/components/schemas/Queries'\n selectors:\n $ref: '#/components/schemas/Selector'\n trigger_after:\n $ref: '#/components/schemas/TriggerAfter'\n window:\n $ref: '#/components/schemas/Window'\ntype: object\n"), Example: examples, Group: "rules", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditRule(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6873,9 +6914,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6891,19 +6930,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "rename-rule rule name", - Short: "Rename rule", - Long: cli.Markdown("Rename a rule"), + Use: "toggle-rule rule action", + Short: "Toggle rule", + Long: cli.Markdown("Enable or disable a rule"), Example: examples, Group: "rules", Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:]) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2RenameRule(args[0], args[1], params, body) + _, decoded, outputOptions, err := MistApiV2ToggleRule(args[0], args[1], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6915,6 +6954,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6930,19 +6970,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-rule rule", - Short: "Update rule", - Long: cli.Markdown("Edit a rule given its UUID, EDIT permission required on rule\n## Request Schema (application/json)\n\nproperties:\n actions:\n $ref: '#/components/schemas/RuleActions'\n frequency:\n $ref: '#/components/schemas/Frequency'\n queries:\n $ref: '#/components/schemas/Queries'\n selectors:\n $ref: '#/components/schemas/Selector'\n trigger_after:\n $ref: '#/components/schemas/TriggerAfter'\n window:\n $ref: '#/components/schemas/Window'\ntype: object\n"), + Use: "delete-rule rule", + Short: "Delete rule", + Long: cli.Markdown("Delete a rule given its UUID."), Example: examples, Group: "rules", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditRule(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7018,7 +7054,7 @@ func mistApiV2Register(subcommand bool) { Group: "scripts", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -7035,6 +7071,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7050,19 +7087,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "run-script script", - Short: "Run script", - Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), + Use: "get-script script", + Short: "Get script", + Long: cli.Markdown("Get details about target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7075,6 +7108,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7089,19 +7125,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-script script", - Short: "Edit script", - Long: cli.Markdown("Edit target script"), + Use: "run-script script", + Short: "Run script", + Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7113,9 +7149,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("name", "", "New script name") - cmd.Flags().String("description", "", "New script description") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7131,15 +7165,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-script script", - Short: "Delete script", - Long: cli.Markdown("Delete target script"), + Use: "edit-script script", + Short: "Edit script", + Long: cli.Markdown("Edit target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7151,6 +7189,10 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("name", "", "New script name") + cmd.Flags().String("description", "", "New script description") cli.SetCustomFlags(cmd) @@ -7166,15 +7208,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-script script", - Short: "Get script", - Long: cli.Markdown("Get details about target script"), + Use: "delete-script script", + Short: "Delete script", + Long: cli.Markdown("Delete target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7187,9 +7229,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7447,7 +7486,7 @@ func mistApiV2Register(subcommand bool) { Group: "volumes", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -7464,6 +7503,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7559,7 +7599,7 @@ func mistApiV2Register(subcommand bool) { Group: "volumes", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -7576,6 +7616,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cmd.Flags().String("name", "", "New volume name") @@ -7643,7 +7684,7 @@ func mistApiV2Register(subcommand bool) { Group: "zones", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:]) + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } @@ -7660,6 +7701,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7675,15 +7717,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-zone zone", - Short: "Delete zone", - Long: cli.Markdown("Delete target zone"), + Use: "get-zone zone", + Short: "Get zone", + Long: cli.Markdown("Get details about target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7696,6 +7738,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7710,15 +7755,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-zone zone", - Short: "Get zone", - Long: cli.Markdown("Get details about target zone"), + Use: "edit-zone zone", + Short: "Edit zone", + Long: cli.Markdown("Edit target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7730,9 +7779,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7748,19 +7795,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-zone zone", - Short: "Edit zone", - Long: cli.Markdown("Edit target zone"), + Use: "delete-zone zone", + Short: "Delete zone", + Long: cli.Markdown("Delete target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:]) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } From febd005f0958aad83c475ca474d09a04cdb546e1 Mon Sep 17 00:00:00 2001 From: Mist Gitlab Runner Date: Tue, 16 Nov 2021 10:44:07 +0000 Subject: [PATCH 2/5] Regenerate mist-cli after: Improve clone operation --- mist-api-v2.go | 1156 ++++++++++++++++++++++++------------------------ 1 file changed, 578 insertions(+), 578 deletions(-) diff --git a/mist-api-v2.go b/mist-api-v2.go index d25c5e4..bfa6f00 100644 --- a/mist-api-v2.go +++ b/mist-api-v2.go @@ -85,9 +85,9 @@ func getToken() (string, error) { return cli.Creds.GetString("contexts." + mistContext + ".api_key"), nil } -// MistApiV2ListClouds List clouds -func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-clouds" +// MistApiV2AddCloud Add cloud +func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -104,31 +104,10 @@ func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]i url := server + "/api/v2/clouds" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -153,12 +132,12 @@ func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]i decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2AddCloud Add cloud -func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-cloud" +// MistApiV2ListClouds List clouds +func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-clouds" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -175,10 +154,31 @@ func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, m url := server + "/api/v2/clouds" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -203,12 +203,12 @@ func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, m decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2RemoveCloud Remove cloud -func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "remove-cloud" +// MistApiV2GetCloud Get cloud +func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -226,7 +226,20 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -235,7 +248,7 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -247,15 +260,15 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetCloud Get cloud -func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-cloud" +// MistApiV2EditCloud Edit cloud +func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -273,19 +286,10 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -295,7 +299,7 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -307,15 +311,15 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditCloud Edit cloud -func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-cloud" +// MistApiV2RemoveCloud Remove cloud +func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "remove-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -333,11 +337,7 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Put().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -843,9 +843,9 @@ func MistApiV2GetJob(paramJobId string, params *viper.Viper) (*gentleman.Respons return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2ListKeys List keys -func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-keys" +// MistApiV2AddKey Add key +func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-key" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -862,31 +862,10 @@ func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]int url := server + "/api/v2/keys" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -911,12 +890,12 @@ func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]int decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "default", "tags"}, []string{"id", "name", "default", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2AddKey Add key -func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-key" +// MistApiV2ListKeys List keys +func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-keys" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -933,10 +912,31 @@ func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map url := server + "/api/v2/keys" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -961,7 +961,7 @@ func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "default", "tags"}, []string{"id", "name", "default", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2DeleteKey Delete key @@ -1266,6 +1266,56 @@ func MistApiV2GetLocation(paramLocation string, params *viper.Viper) (*gentleman return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud"}, []string{"id", "name", "cloud", "locations", "external_id", "machines"}, []string{}, []string{}}, nil } +// MistApiV2CreateMachine Create machine +func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-machine" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/machines" + + req := cli.Client.Post().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) + } + + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + } + + var decoded map[string]interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) + } + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after.(map[string]interface{}) + } + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + // MistApiV2ListMachines List machines func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-machines" @@ -1341,56 +1391,6 @@ func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2CreateMachine Create machine -func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-machine" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/machines" - - req := cli.Client.Post().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded map[string]interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after.(map[string]interface{}) - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - // MistApiV2GetMachine Get machine func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "get-machine" @@ -2368,56 +2368,6 @@ func MistApiV2RevertToSnapshot(paramMachine string, paramSnapshot string, params return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2CreateNetwork Create network -func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-network" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/networks" - - req := cli.Client.Post().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded map[string]interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after.(map[string]interface{}) - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - // MistApiV2ListNetworks List networks func MistApiV2ListNetworks(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-networks" @@ -2493,9 +2443,9 @@ func MistApiV2ListNetworks(params *viper.Viper) (*gentleman.Response, map[string return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "external_id", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2EditNetwork Edit network -func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-network" +// MistApiV2CreateNetwork Create network +func MistApiV2CreateNetwork(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-network" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -2510,18 +2460,12 @@ func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/networks/{network}" - url = strings.Replace(url, "{network}", paramNetwork, 1) - - req := cli.Client.Put().URL(url) + url := server + "/api/v2/networks" - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) - } + req := cli.Client.Post().URL(url) if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -2531,7 +2475,7 @@ func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -2543,7 +2487,7 @@ func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil @@ -2654,6 +2598,62 @@ func MistApiV2GetNetwork(paramNetwork string, params *viper.Viper) (*gentleman.R return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } +// MistApiV2EditNetwork Edit network +func MistApiV2EditNetwork(paramNetwork string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-network" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/networks/{network}" + url = strings.Replace(url, "{network}", paramNetwork, 1) + + req := cli.Client.Put().URL(url) + + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + } + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) + } + + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + } + + var decoded interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) + } + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after + } + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + // MistApiV2ListOrgs List orgs func MistApiV2ListOrgs(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-orgs" @@ -3095,6 +3095,53 @@ func MistApiV2AddRule(params *viper.Viper, body string) (*gentleman.Response, ma return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } +// MistApiV2DeleteRule Delete rule +func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-rule" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/rules/{rule}" + url = strings.Replace(url, "{rule}", paramRule, 1) + + req := cli.Client.Delete().URL(url) + + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + } + + var decoded interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) + } + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after + } + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + // MistApiV2GetRule Get rule func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "get-rule" @@ -3308,9 +3355,9 @@ func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Vip return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteRule Delete rule -func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-rule" +// MistApiV2ListScripts List scripts +func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-scripts" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3325,64 +3372,17 @@ func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Resp return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/rules/{rule}" - url = strings.Replace(url, "{rule}", paramRule, 1) - - req := cli.Client.Delete().URL(url) + url := server + "/api/v2/scripts" - cli.HandleBefore(handlerPath, params, req) + req := cli.Client.Get().URL(url) - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) } - - var decoded interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - -// MistApiV2ListScripts List scripts -func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-scripts" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/scripts" - - req := cli.Client.Get().URL(url) - - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) } paramStart := params.GetString("start") if paramStart != "" { @@ -3476,9 +3476,9 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetScript Get script -func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-script" +// MistApiV2EditScript Edit script +func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3496,15 +3496,19 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + paramDescription := params.GetString("description") + if paramDescription != "" { + req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + } + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3514,7 +3518,7 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3526,15 +3530,15 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RunScript Run script -func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "run-script" +// MistApiV2DeleteScript Delete script +func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3552,11 +3556,7 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Post().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -3565,7 +3565,7 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3577,15 +3577,15 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditScript Edit script -func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-script" +// MistApiV2GetScript Get script +func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3603,19 +3603,15 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Get().URL(url) - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) - } - paramDescription := params.GetString("description") - if paramDescription != "" { - req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) } - - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -3625,7 +3621,7 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3637,15 +3633,15 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2DeleteScript Delete script -func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-script" +// MistApiV2RunScript Run script +func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "run-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3663,7 +3659,11 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Post().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -3672,7 +3672,7 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3684,7 +3684,7 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil @@ -4395,9 +4395,9 @@ func MistApiV2CreateZone(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetZone Get zone -func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-zone" +// MistApiV2DeleteZone Delete zone +func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4415,16 +4415,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Get().URL(url) - - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -4433,7 +4424,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4445,15 +4436,15 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditZone Edit zone -func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-zone" +// MistApiV2GetZone Get zone +func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4471,10 +4462,15 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -4484,7 +4480,7 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4496,15 +4492,15 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2DeleteZone Delete zone -func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-zone" +// MistApiV2EditZone Edit zone +func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4522,7 +4518,11 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Put().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -4693,15 +4693,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-clouds", - Short: "List clouds", - Long: cli.Markdown("List clouds owned by the active org. READ permission required on cloud."), + Use: "add-cloud", + Short: "Add cloud", + Long: cli.Markdown("Adds a new cloud and returns the cloud's id. ADD permission required on cloud.\n## Request Schema (application/json)\n\nallOf:\n- properties:\n name:\n description: The name of the cloud to add\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - name\n - provider\n type: object\n- discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n credentials:\n email: email\n privateKey: privateKey\n projectId: projectId\n name: my-cloud\n provider: google\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListClouds(params) + _, decoded, outputOptions, err := MistApiV2AddCloud(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4713,13 +4717,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4735,19 +4733,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "add-cloud", - Short: "Add cloud", - Long: cli.Markdown("Adds a new cloud and returns the cloud's id. ADD permission required on cloud.\n## Request Schema (application/json)\n\nallOf:\n- properties:\n name:\n description: The name of the cloud to add\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - name\n - provider\n type: object\n- discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n credentials:\n email: email\n privateKey: privateKey\n projectId: projectId\n name: my-cloud\n provider: google\n"), + Use: "list-clouds", + Short: "List clouds", + Long: cli.Markdown("List clouds owned by the active org. READ permission required on cloud."), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2AddCloud(params, body) + _, decoded, outputOptions, err := MistApiV2ListClouds(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4759,7 +4753,13 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -4775,15 +4775,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "remove-cloud cloud", - Short: "Remove cloud", - Long: cli.Markdown("Remove target cloud"), + Use: "get-cloud cloud", + Short: "Get cloud", + Long: cli.Markdown("Get details about target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4796,6 +4796,10 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -4810,15 +4814,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-cloud cloud", - Short: "Get cloud", - Long: cli.Markdown("Get details about target cloud"), + Use: "edit-cloud cloud", + Short: "Edit cloud", + Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4830,10 +4838,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4849,19 +4854,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-cloud cloud", - Short: "Edit cloud", - Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), + Use: "remove-cloud cloud", + Short: "Remove cloud", + Long: cli.Markdown("Remove target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4873,7 +4874,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5203,15 +5203,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-keys", - Short: "List keys", - Long: cli.Markdown("List keys owned by the active org. READ permission required on key."), + Use: "add-key", + Short: "Add key", + Long: cli.Markdown("Adds a new key and returns the key's id. ADD permission required on key.\n## Request Schema (application/json)\n\nanyOf:\n- properties:\n certificate:\n description: The signed public key, when using signed ssh keys\n type: string\n name:\n description: The key's name\n type: string\n private:\n description: The private key\n type: string\n required:\n - name\n - private\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n name:\n description: The key's name\n type: string\n required:\n - name\n - generate\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n required:\n - generate\n - dry\nexample:\n name: my-key\n private: |-\n -----BEGIN RSA PRIVATE KEY-----\n MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5 1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh 3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2 pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n -----END RSA PRIVATE KEY-----\ntype: object\n"), Example: examples, Group: "keys", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListKeys(params) + _, decoded, outputOptions, err := MistApiV2AddKey(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5223,13 +5227,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5245,19 +5243,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "add-key", - Short: "Add key", - Long: cli.Markdown("Adds a new key and returns the key's id. ADD permission required on key.\n## Request Schema (application/json)\n\nanyOf:\n- properties:\n certificate:\n description: The signed public key, when using signed ssh keys\n type: string\n name:\n description: The key's name\n type: string\n private:\n description: The private key\n type: string\n required:\n - name\n - private\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n name:\n description: The key's name\n type: string\n required:\n - name\n - generate\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n required:\n - generate\n - dry\nexample:\n name: my-key\n private: |-\n -----BEGIN RSA PRIVATE KEY-----\n MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5 1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh 3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2 pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n -----END RSA PRIVATE KEY-----\ntype: object\n"), + Use: "list-keys", + Short: "List keys", + Long: cli.Markdown("List keys owned by the active org. READ permission required on key."), Example: examples, Group: "keys", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2AddKey(params, body) + _, decoded, outputOptions, err := MistApiV2ListKeys(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5269,7 +5263,13 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -5484,15 +5484,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-machines", - Short: "List machines", - Long: cli.Markdown("List machines owned by the active org. READ permission required on machine & cloud."), + Use: "create-machine", + Short: "Create machine", + Long: cli.Markdown("Creates one or more machines on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on machine. RUN permission required on script. READ permission required on key.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n type: string\n cloudinit:\n description: Run this Cloud Init script on first boot\n type: string\n disks:\n description: Configure local disks\n properties:\n disk_path:\n description: KVM specific parameter. Where the VM disk file will be created\n type: string\n disk_size:\n description: KVM, CloudSigma specific parameter\n type: integer\n type: object\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n expiration:\n $ref: '#/components/schemas/Expiration'\n extra:\n anyOf:\n - $ref: '#/components/schemas/AzureExtra'\n - $ref: '#/components/schemas/DockerExtra'\n - $ref: '#/components/schemas/EquinixMetalExtra'\n - $ref: '#/components/schemas/LinodeExtra'\n - $ref: '#/components/schemas/LXDExtra'\n - $ref: '#/components/schemas/VSphereExtra'\n - $ref: '#/components/schemas/VultrExtra'\n description: Configure additional parameters\n fqdn:\n description: Add DNS A Record that points machine's public IP to this Fully Qualified Domain Name. Zone needs to be managed by a configured Cloud DNS provider\n type: string\n image:\n description: Operating System image to boot from\n example: Debian\n oneOf:\n - type: object\n - description: Name or ID of the image to boot from\n type: string\n key:\n description: Associate SSH key\n oneOf:\n - properties:\n key:\n description: Name or ID of the SSH key to deploy\n type: string\n user:\n description: SSH user, supported on Google\n type: string\n type: object\n - description: Name or ID of the SSH key to deploy\n type: string\n location:\n description: Where to provision e.g. region, datacenter, rack\n type: string\n monitoring:\n description: Enable monitoring of this machine\n type: boolean\n name:\n description: Specify machine name\n example: DB mirror\n type: string\n net:\n anyOf:\n - $ref: '#/components/schemas/AlibabaNet'\n - $ref: '#/components/schemas/AmazonNet'\n - $ref: '#/components/schemas/AzureNet'\n - $ref: '#/components/schemas/DockerNet'\n - $ref: '#/components/schemas/EquinixMetalNet'\n - $ref: '#/components/schemas/GoogleNet'\n - $ref: '#/components/schemas/KVMNet'\n - $ref: '#/components/schemas/LinodeNet'\n - $ref: '#/components/schemas/LXDNet'\n - $ref: '#/components/schemas/OpenstackNet'\n - $ref: '#/components/schemas/VSphereNet'\n - $ref: '#/components/schemas/VultrNet'\n description: Specify network configuration parameters\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple machines of this type\n type: number\n save:\n description: Save provisioning plan as template\n type: boolean\n schedules:\n description: Configure scheduled actions for the provisioned machine\n items:\n allOf:\n - properties:\n action:\n enum:\n - start\n - stop\n - reboot\n - destroy\n type: string\n description:\n type: string\n schedule_type:\n enum:\n - one_off\n - crontab\n - interval\n type: string\n script:\n $ref: '#/components/schemas/PostDeployScript'\n required:\n - schedule_type\n type: object\n - discriminator:\n mapping:\n crontab: '#/components/schemas/CronSchedule'\n interval: '#/components/schemas/IntervalSchedule'\n one_off: '#/components/schemas/OneOffSchedule'\n propertyName: schedule_type\n oneOf:\n - $ref: '#/components/schemas/OneOffSchedule'\n - $ref: '#/components/schemas/CronSchedule'\n - $ref: '#/components/schemas/IntervalSchedule'\n type: array\n scripts:\n description: Run post deploy scripts over SSH\n items:\n allOf:\n - type: object\n - oneOf:\n - $ref: '#/components/schemas/InlineScript'\n - $ref: '#/components/schemas/PostDeployScript'\n type: array\n size:\n description: Machine sizing spec e.g. cpu/ram/flavor, not used on Docker, LXD\n example: m1.small\n oneOf:\n - properties:\n accelerators:\n description: Google specific parameter\n properties:\n accelerator_count:\n description: The number of the accelerator cards exposed to this instance\n type: integer\n accelerator_type:\n description: Accelerator type to attach to this machine. e.g. 'nvidia-tesla-p100'\n type: string\n type: object\n cpus:\n description: Number of cpu cores. Mutually exclusive with 'size'\n minimum: 1\n type: integer\n ram:\n description: Ram size in MBs. Mutually exclusive with 'size'\n minimum: 256\n type: integer\n size:\n description: Name or ID of the size to select for this machine. Mutually exclusive with 'cpus' and 'ram'\n type: string\n type: object\n - description: Name or ID of the size to select for this machine\n type: string\n tags:\n description: Assign tags to provisioned machine\n type: object\n template:\n type: object\n volumes:\n anyOf:\n - $ref: '#/components/schemas/AlibabaVolumes'\n - $ref: '#/components/schemas/AmazonVolumes'\n - $ref: '#/components/schemas/AzureVolumes'\n - $ref: '#/components/schemas/CloudSigmaVolumes'\n - $ref: '#/components/schemas/DigitalOceanVolumes'\n - $ref: '#/components/schemas/GoogleVolumes'\n - $ref: '#/components/schemas/LinodeVolumes'\n - $ref: '#/components/schemas/LXDVolumes'\n - $ref: '#/components/schemas/OpenstackVolumes'\n - $ref: '#/components/schemas/VultrVolumes'\n description: Configure of attached storage volumes, e.g. cloud disks\nrequired:\n- name\n- image\ntype: object\n"), Example: examples, Group: "machines", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListMachines(params) + resp, decoded, outputOptions, err := MistApiV2CreateMachine(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5501,17 +5505,30 @@ func mistApiV2Register(subcommand bool) { logger.Fatalf("Formatting failed: %s", err.Error()) } + reqParams := params.AllSettings() + + var actual interface{} + if params.GetBool("wait") { + wparams := viper.New() + actual, err = cli.GetMatchValue(resp.Context, "response.body#jobId", reqParams, decoded) + if err != nil { + logger.Fatalf("Could not get matcher value: %s", err.Error()) + } + + arg0 := fmt.Sprintf("%v", actual) + + if err := MistApiV2JobFinishedWaiter(arg0, wparams); err != nil { + logger.Fatalf("Waiter error: %s", err.Error()) + } + + fmt.Println("Create machine completed successfully") + } }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().BoolP("wait", "w", false, "Wait job") cli.SetCustomFlags(cmd) @@ -5527,19 +5544,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-machine", - Short: "Create machine", - Long: cli.Markdown("Creates one or more machines on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on machine. RUN permission required on script. READ permission required on key.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n type: string\n cloudinit:\n description: Run this Cloud Init script on first boot\n type: string\n disks:\n description: Configure local disks\n properties:\n disk_path:\n description: KVM specific parameter. Where the VM disk file will be created\n type: string\n disk_size:\n description: KVM, CloudSigma specific parameter\n type: integer\n type: object\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n expiration:\n $ref: '#/components/schemas/Expiration'\n extra:\n anyOf:\n - $ref: '#/components/schemas/AzureExtra'\n - $ref: '#/components/schemas/DockerExtra'\n - $ref: '#/components/schemas/EquinixMetalExtra'\n - $ref: '#/components/schemas/LinodeExtra'\n - $ref: '#/components/schemas/LXDExtra'\n - $ref: '#/components/schemas/VSphereExtra'\n - $ref: '#/components/schemas/VultrExtra'\n description: Configure additional parameters\n fqdn:\n description: Add DNS A Record that points machine's public IP to this Fully Qualified Domain Name. Zone needs to be managed by a configured Cloud DNS provider\n type: string\n image:\n description: Operating System image to boot from\n example: Debian\n oneOf:\n - type: object\n - description: Name or ID of the image to boot from\n type: string\n key:\n description: Associate SSH key\n oneOf:\n - properties:\n key:\n description: Name or ID of the SSH key to deploy\n type: string\n user:\n description: SSH user, supported on Google\n type: string\n type: object\n - description: Name or ID of the SSH key to deploy\n type: string\n location:\n description: Where to provision e.g. region, datacenter, rack\n type: string\n monitoring:\n description: Enable monitoring of this machine\n type: boolean\n name:\n description: Specify machine name\n example: DB mirror\n type: string\n net:\n anyOf:\n - $ref: '#/components/schemas/AlibabaNet'\n - $ref: '#/components/schemas/AmazonNet'\n - $ref: '#/components/schemas/AzureNet'\n - $ref: '#/components/schemas/DockerNet'\n - $ref: '#/components/schemas/EquinixMetalNet'\n - $ref: '#/components/schemas/GoogleNet'\n - $ref: '#/components/schemas/KVMNet'\n - $ref: '#/components/schemas/LinodeNet'\n - $ref: '#/components/schemas/LXDNet'\n - $ref: '#/components/schemas/OpenstackNet'\n - $ref: '#/components/schemas/VSphereNet'\n - $ref: '#/components/schemas/VultrNet'\n description: Specify network configuration parameters\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple machines of this type\n type: number\n save:\n description: Save provisioning plan as template\n type: boolean\n schedules:\n description: Configure scheduled actions for the provisioned machine\n items:\n allOf:\n - properties:\n action:\n enum:\n - start\n - stop\n - reboot\n - destroy\n type: string\n description:\n type: string\n schedule_type:\n enum:\n - one_off\n - crontab\n - interval\n type: string\n script:\n $ref: '#/components/schemas/PostDeployScript'\n required:\n - schedule_type\n type: object\n - discriminator:\n mapping:\n crontab: '#/components/schemas/CronSchedule'\n interval: '#/components/schemas/IntervalSchedule'\n one_off: '#/components/schemas/OneOffSchedule'\n propertyName: schedule_type\n oneOf:\n - $ref: '#/components/schemas/OneOffSchedule'\n - $ref: '#/components/schemas/CronSchedule'\n - $ref: '#/components/schemas/IntervalSchedule'\n type: array\n scripts:\n description: Run post deploy scripts over SSH\n items:\n allOf:\n - type: object\n - oneOf:\n - $ref: '#/components/schemas/InlineScript'\n - $ref: '#/components/schemas/PostDeployScript'\n type: array\n size:\n description: Machine sizing spec e.g. cpu/ram/flavor, not used on Docker, LXD\n example: m1.small\n oneOf:\n - properties:\n accelerators:\n description: Google specific parameter\n properties:\n accelerator_count:\n description: The number of the accelerator cards exposed to this instance\n type: integer\n accelerator_type:\n description: Accelerator type to attach to this machine. e.g. 'nvidia-tesla-p100'\n type: string\n type: object\n cpus:\n description: Number of cpu cores. Mutually exclusive with 'size'\n minimum: 1\n type: integer\n ram:\n description: Ram size in MBs. Mutually exclusive with 'size'\n minimum: 256\n type: integer\n size:\n description: Name or ID of the size to select for this machine. Mutually exclusive with 'cpus' and 'ram'\n type: string\n type: object\n - description: Name or ID of the size to select for this machine\n type: string\n tags:\n description: Assign tags to provisioned machine\n type: object\n template:\n type: object\n volumes:\n anyOf:\n - $ref: '#/components/schemas/AlibabaVolumes'\n - $ref: '#/components/schemas/AmazonVolumes'\n - $ref: '#/components/schemas/AzureVolumes'\n - $ref: '#/components/schemas/CloudSigmaVolumes'\n - $ref: '#/components/schemas/DigitalOceanVolumes'\n - $ref: '#/components/schemas/GoogleVolumes'\n - $ref: '#/components/schemas/LinodeVolumes'\n - $ref: '#/components/schemas/LXDVolumes'\n - $ref: '#/components/schemas/OpenstackVolumes'\n - $ref: '#/components/schemas/VultrVolumes'\n description: Configure of attached storage volumes, e.g. cloud disks\nrequired:\n- name\n- image\ntype: object\n"), + Use: "list-machines", + Short: "List machines", + Long: cli.Markdown("List machines owned by the active org. READ permission required on machine & cloud."), Example: examples, Group: "machines", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - resp, decoded, outputOptions, err := MistApiV2CreateMachine(params, body) + _, decoded, outputOptions, err := MistApiV2ListMachines(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5548,30 +5561,17 @@ func mistApiV2Register(subcommand bool) { logger.Fatalf("Formatting failed: %s", err.Error()) } - reqParams := params.AllSettings() - - var actual interface{} - if params.GetBool("wait") { - wparams := viper.New() - actual, err = cli.GetMatchValue(resp.Context, "response.body#jobId", reqParams, decoded) - if err != nil { - logger.Fatalf("Could not get matcher value: %s", err.Error()) - } - - arg0 := fmt.Sprintf("%v", actual) - - if err := MistApiV2JobFinishedWaiter(arg0, wparams); err != nil { - logger.Fatalf("Waiter error: %s", err.Error()) - } - - fmt.Println("Create machine completed successfully") - } }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().BoolP("wait", "w", false, "Wait job") + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -6332,19 +6332,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-network", - Short: "Create network", - Long: cli.Markdown("Creates one or more networks on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. CREATE permission required on network.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n extra:\n description: Configure additional parameters, e.g. cidr (EC2 network)\n type: object\n name:\n description: Specify network name\n example: my-network\n type: string\n save:\n description: Save provisioning plan as template\n type: boolean\n tags:\n description: Assign tags to provisioned network\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\ntype: object\n"), + Use: "list-networks", + Short: "List networks", + Long: cli.Markdown("List networks owned by the active org. READ permission required on network & cloud."), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateNetwork(params, body) + _, decoded, outputOptions, err := MistApiV2ListNetworks(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6356,7 +6352,14 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -6372,15 +6375,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-networks", - Short: "List networks", - Long: cli.Markdown("List networks owned by the active org. READ permission required on network & cloud."), + Use: "create-network", + Short: "Create network", + Long: cli.Markdown("Creates one or more networks on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. CREATE permission required on network.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n extra:\n description: Configure additional parameters, e.g. cidr (EC2 network)\n type: object\n name:\n description: Specify network name\n example: my-network\n type: string\n save:\n description: Save provisioning plan as template\n type: boolean\n tags:\n description: Assign tags to provisioned network\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\ntype: object\n"), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListNetworks(params) + _, decoded, outputOptions, err := MistApiV2CreateNetwork(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6392,14 +6399,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6415,19 +6415,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-network network", - Short: "Edit network", - Long: cli.Markdown("Edit target network"), + Use: "delete-network network cloud", + Short: "Delete network", + Long: cli.Markdown("Delete target network"), Example: examples, Group: "networks", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditNetwork(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteNetwork(args[0], args[1], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6439,9 +6435,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - - cmd.Flags().String("name", "", "New network name") cli.SetCustomFlags(cmd) @@ -6457,15 +6450,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-network network cloud", - Short: "Delete network", - Long: cli.Markdown("Delete target network"), + Use: "get-network network", + Short: "Get network", + Long: cli.Markdown("Get details about target network"), Example: examples, Group: "networks", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2DeleteNetwork(args[0], args[1], params) + _, decoded, outputOptions, err := MistApiV2GetNetwork(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6478,6 +6471,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -6492,15 +6488,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-network network", - Short: "Get network", - Long: cli.Markdown("Get details about target network"), + Use: "edit-network network", + Short: "Edit network", + Long: cli.Markdown("Edit target network"), Example: examples, Group: "networks", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetNetwork(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditNetwork(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6512,9 +6512,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().String("name", "", "New network name") cli.SetCustomFlags(cmd) @@ -6812,15 +6812,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-rule rule", - Short: "Get rule", - Long: cli.Markdown("Get details about target rule"), + Use: "delete-rule rule", + Short: "Delete rule", + Long: cli.Markdown("Delete a rule given its UUID."), Example: examples, Group: "rules", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) + _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6833,9 +6833,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -6850,19 +6847,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "rename-rule rule name", - Short: "Rename rule", - Long: cli.Markdown("Rename a rule"), + Use: "get-rule rule", + Short: "Get rule", + Long: cli.Markdown("Get details about target rule"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2RenameRule(args[0], args[1], params, body) + _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6874,7 +6867,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") cli.SetCustomFlags(cmd) @@ -6890,19 +6885,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-rule rule", - Short: "Update rule", - Long: cli.Markdown("Edit a rule given its UUID, EDIT permission required on rule\n## Request Schema (application/json)\n\nproperties:\n actions:\n $ref: '#/components/schemas/RuleActions'\n frequency:\n $ref: '#/components/schemas/Frequency'\n queries:\n $ref: '#/components/schemas/Queries'\n selectors:\n $ref: '#/components/schemas/Selector'\n trigger_after:\n $ref: '#/components/schemas/TriggerAfter'\n window:\n $ref: '#/components/schemas/Window'\ntype: object\n"), + Use: "rename-rule rule name", + Short: "Rename rule", + Long: cli.Markdown("Rename a rule"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + body, err := cli.GetBody("", args[2:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2EditRule(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RenameRule(args[0], args[1], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6930,19 +6925,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "toggle-rule rule action", - Short: "Toggle rule", - Long: cli.Markdown("Enable or disable a rule"), + Use: "edit-rule rule", + Short: "Update rule", + Long: cli.Markdown("Edit a rule given its UUID, EDIT permission required on rule\n## Request Schema (application/json)\n\nproperties:\n actions:\n $ref: '#/components/schemas/RuleActions'\n frequency:\n $ref: '#/components/schemas/Frequency'\n queries:\n $ref: '#/components/schemas/Queries'\n selectors:\n $ref: '#/components/schemas/Selector'\n trigger_after:\n $ref: '#/components/schemas/TriggerAfter'\n window:\n $ref: '#/components/schemas/Window'\ntype: object\n"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(2), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[2:], params.GetString("filename")) + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2ToggleRule(args[0], args[1], params, body) + _, decoded, outputOptions, err := MistApiV2EditRule(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6970,15 +6965,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-rule rule", - Short: "Delete rule", - Long: cli.Markdown("Delete a rule given its UUID."), + Use: "toggle-rule rule action", + Short: "Toggle rule", + Long: cli.Markdown("Enable or disable a rule"), Example: examples, Group: "rules", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[2:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) + _, decoded, outputOptions, err := MistApiV2ToggleRule(args[0], args[1], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -6990,6 +6989,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7087,15 +7087,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-script script", - Short: "Get script", - Long: cli.Markdown("Get details about target script"), + Use: "edit-script script", + Short: "Edit script", + Long: cli.Markdown("Edit target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7107,9 +7111,10 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().String("name", "", "New script name") + cmd.Flags().String("description", "", "New script description") cli.SetCustomFlags(cmd) @@ -7125,19 +7130,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "run-script script", - Short: "Run script", - Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), + Use: "delete-script script", + Short: "Delete script", + Long: cli.Markdown("Delete target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7149,7 +7150,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7165,19 +7165,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-script script", - Short: "Edit script", - Long: cli.Markdown("Edit target script"), + Use: "get-script script", + Short: "Get script", + Long: cli.Markdown("Get details about target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7189,10 +7185,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("name", "", "New script name") - cmd.Flags().String("description", "", "New script description") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -7208,15 +7203,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-script script", - Short: "Delete script", - Long: cli.Markdown("Delete target script"), + Use: "run-script script", + Short: "Run script", + Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7228,6 +7227,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7717,15 +7717,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-zone zone", - Short: "Get zone", - Long: cli.Markdown("Get details about target zone"), + Use: "delete-zone zone", + Short: "Delete zone", + Long: cli.Markdown("Delete target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7738,9 +7738,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7755,19 +7752,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-zone zone", - Short: "Edit zone", - Long: cli.Markdown("Edit target zone"), + Use: "get-zone zone", + Short: "Get zone", + Long: cli.Markdown("Get details about target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7779,7 +7772,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -7795,15 +7790,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-zone zone", - Short: "Delete zone", - Long: cli.Markdown("Delete target zone"), + Use: "edit-zone zone", + Short: "Edit zone", + Long: cli.Markdown("Edit target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7815,6 +7814,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) From 386ff1c663b99622427bf68e2339ebf34d471ca8 Mon Sep 17 00:00:00 2001 From: Mist Gitlab Runner Date: Tue, 16 Nov 2021 11:06:06 +0000 Subject: [PATCH 3/5] Regenerate mist-cli after: Improve clone operation --- mist-api-v2.go | 926 ++++++++++++++++++++++++------------------------- 1 file changed, 463 insertions(+), 463 deletions(-) diff --git a/mist-api-v2.go b/mist-api-v2.go index bfa6f00..368e313 100644 --- a/mist-api-v2.go +++ b/mist-api-v2.go @@ -85,56 +85,6 @@ func getToken() (string, error) { return cli.Creds.GetString("contexts." + mistContext + ".api_key"), nil } -// MistApiV2AddCloud Add cloud -func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-cloud" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/clouds" - - req := cli.Client.Post().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded map[string]interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after.(map[string]interface{}) - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - // MistApiV2ListClouds List clouds func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-clouds" @@ -206,9 +156,9 @@ func MistApiV2ListClouds(params *viper.Viper) (*gentleman.Response, map[string]i return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetCloud Get cloud -func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-cloud" +// MistApiV2AddCloud Add cloud +func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -223,22 +173,12 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/clouds/{cloud}" - url = strings.Replace(url, "{cloud}", paramCloud, 1) + url := server + "/api/v2/clouds" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -263,7 +203,7 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2EditCloud Edit cloud @@ -364,6 +304,66 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } +// MistApiV2GetCloud Get cloud +func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-cloud" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/clouds/{cloud}" + url = strings.Replace(url, "{cloud}", paramCloud, 1) + + req := cli.Client.Get().URL(url) + + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } + + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") + } + + var decoded map[string]interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) + } + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after.(map[string]interface{}) + } + + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil +} + // MistApiV2ListClusters List clusters func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "list-clusters" @@ -843,9 +843,9 @@ func MistApiV2GetJob(paramJobId string, params *viper.Viper) (*gentleman.Respons return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2AddKey Add key -func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-key" +// MistApiV2ListKeys List keys +func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-keys" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -862,10 +862,31 @@ func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map url := server + "/api/v2/keys" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -890,12 +911,12 @@ func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "default", "tags"}, []string{"id", "name", "default", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2ListKeys List keys -func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-keys" +// MistApiV2AddKey Add key +func MistApiV2AddKey(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-key" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -912,31 +933,10 @@ func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]int url := server + "/api/v2/keys" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -961,7 +961,7 @@ func MistApiV2ListKeys(params *viper.Viper) (*gentleman.Response, map[string]int decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "default", "tags"}, []string{"id", "name", "default", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2DeleteKey Delete key @@ -1266,9 +1266,9 @@ func MistApiV2GetLocation(paramLocation string, params *viper.Viper) (*gentleman return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud"}, []string{"id", "name", "cloud", "locations", "external_id", "machines"}, []string{}, []string{}}, nil } -// MistApiV2CreateMachine Create machine -func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-machine" +// MistApiV2ListMachines List machines +func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-machines" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1285,10 +1285,35 @@ func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Respon url := server + "/api/v2/machines" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramCloud := params.GetString("cloud") + if paramCloud != "" { + req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) + } + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -1313,12 +1338,12 @@ func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Respon decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2ListMachines List machines -func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-machines" +// MistApiV2CreateMachine Create machine +func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1335,35 +1360,10 @@ func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string url := server + "/api/v2/machines" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramCloud := params.GetString("cloud") - if paramCloud != "" { - req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) - } - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -1388,12 +1388,12 @@ func MistApiV2ListMachines(params *viper.Viper) (*gentleman.Response, map[string decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetMachine Get machine -func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-machine" +// MistApiV2EditMachine Edit machine +func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1411,15 +1411,10 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R url := server + "/api/v2/machines/{machine}" url = strings.Replace(url, "{machine}", paramMachine, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -1429,7 +1424,7 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -1441,15 +1436,15 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditMachine Edit machine -func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-machine" +// MistApiV2GetMachine Get machine +func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1467,10 +1462,15 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) url := server + "/api/v2/machines/{machine}" url = strings.Replace(url, "{machine}", paramMachine, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -1480,7 +1480,7 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -1492,10 +1492,10 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2AssociateKey Associate a key with a machine @@ -1573,9 +1573,9 @@ func MistApiV2CloneMachine(paramMachine string, paramName string, params *viper. req = req.AddQuery("name", paramName) - paramAsync := params.GetBool("async") - if paramAsync != false { - req = req.AddQuery("async", fmt.Sprintf("%v", paramAsync)) + paramRunAsync := params.GetBool("run-async") + if paramRunAsync != false { + req = req.AddQuery("run_async", fmt.Sprintf("%v", paramRunAsync)) } if body != "" { @@ -3476,9 +3476,9 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditScript Edit script -func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-script" +// MistApiV2DeleteScript Delete script +func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3496,20 +3496,7 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Put().URL(url) - - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) - } - paramDescription := params.GetString("description") - if paramDescription != "" { - req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) - } - - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -3536,9 +3523,9 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteScript Delete script -func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-script" +// MistApiV2GetScript Get script +func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3556,7 +3543,16 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -3565,7 +3561,7 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3577,15 +3573,15 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetScript Get script -func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-script" +// MistApiV2RunScript Run script +func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "run-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3603,15 +3599,10 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3636,12 +3627,12 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RunScript Run script -func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "run-script" +// MistApiV2EditScript Edit script +func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3659,10 +3650,19 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Post().URL(url) + req := cli.Client.Put().URL(url) + + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + } + paramDescription := params.GetString("description") + if paramDescription != "" { + req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + } if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3672,7 +3672,7 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3684,7 +3684,7 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil @@ -3986,9 +3986,9 @@ func MistApiV2ListUsers(params *viper.Viper) (*gentleman.Response, map[string]in return resp, decoded, cli.CLIOutputOptions{[]string{"email"}, []string{"email", "id", "last_login", "registration_date"}, []string{}, []string{}}, nil } -// MistApiV2ListVolumes List volumes -func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-volumes" +// MistApiV2CreateVolume Create volume +func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-volume" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4005,35 +4005,10 @@ func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string] url := server + "/api/v2/volumes" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramCloud := params.GetString("cloud") - if paramCloud != "" { - req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) - } - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -4058,12 +4033,12 @@ func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string] decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "size", "cloud", "location", "attached_to", "tags"}, []string{"id", "name", "size", "cloud", "location", "external_id", "attached_to", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2CreateVolume Create volume -func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-volume" +// MistApiV2ListVolumes List volumes +func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-volumes" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4080,10 +4055,35 @@ func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Respons url := server + "/api/v2/volumes" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramCloud := params.GetString("cloud") + if paramCloud != "" { + req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) + } + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -4108,7 +4108,7 @@ func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Respons decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "size", "cloud", "location", "attached_to", "tags"}, []string{"id", "name", "size", "cloud", "location", "external_id", "attached_to", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2DeleteVolume Delete volume @@ -4395,9 +4395,9 @@ func MistApiV2CreateZone(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteZone Delete zone -func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-zone" +// MistApiV2EditZone Edit zone +func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4415,7 +4415,11 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Put().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -4442,9 +4446,9 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetZone Get zone -func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-zone" +// MistApiV2DeleteZone Delete zone +func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4462,16 +4466,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Get().URL(url) - - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -4480,7 +4475,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4492,15 +4487,15 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditZone Edit zone -func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-zone" +// MistApiV2GetZone Get zone +func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4518,10 +4513,15 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -4531,7 +4531,7 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4543,10 +4543,10 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } func MistApiV2JobFinishedWaiter(paramJobId string, params *viper.Viper) error { @@ -4693,19 +4693,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "add-cloud", - Short: "Add cloud", - Long: cli.Markdown("Adds a new cloud and returns the cloud's id. ADD permission required on cloud.\n## Request Schema (application/json)\n\nallOf:\n- properties:\n name:\n description: The name of the cloud to add\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - name\n - provider\n type: object\n- discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n credentials:\n email: email\n privateKey: privateKey\n projectId: projectId\n name: my-cloud\n provider: google\n"), + Use: "list-clouds", + Short: "List clouds", + Long: cli.Markdown("List clouds owned by the active org. READ permission required on cloud."), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2AddCloud(params, body) + _, decoded, outputOptions, err := MistApiV2ListClouds(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4717,7 +4713,13 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -4733,15 +4735,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-clouds", - Short: "List clouds", - Long: cli.Markdown("List clouds owned by the active org. READ permission required on cloud."), + Use: "add-cloud", + Short: "Add cloud", + Long: cli.Markdown("Adds a new cloud and returns the cloud's id. ADD permission required on cloud.\n## Request Schema (application/json)\n\nallOf:\n- properties:\n name:\n description: The name of the cloud to add\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - name\n - provider\n type: object\n- discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n credentials:\n email: email\n privateKey: privateKey\n projectId: projectId\n name: my-cloud\n provider: google\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListClouds(params) + _, decoded, outputOptions, err := MistApiV2AddCloud(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4753,13 +4759,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4775,15 +4775,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-cloud cloud", - Short: "Get cloud", - Long: cli.Markdown("Get details about target cloud"), + Use: "edit-cloud cloud", + Short: "Edit cloud", + Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4795,10 +4799,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4814,19 +4815,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-cloud cloud", - Short: "Edit cloud", - Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), + Use: "remove-cloud cloud", + Short: "Remove cloud", + Long: cli.Markdown("Remove target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4838,7 +4835,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4854,15 +4850,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "remove-cloud cloud", - Short: "Remove cloud", - Long: cli.Markdown("Remove target cloud"), + Use: "get-cloud cloud", + Short: "Get cloud", + Long: cli.Markdown("Get details about target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4875,6 +4871,10 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -5203,19 +5203,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "add-key", - Short: "Add key", - Long: cli.Markdown("Adds a new key and returns the key's id. ADD permission required on key.\n## Request Schema (application/json)\n\nanyOf:\n- properties:\n certificate:\n description: The signed public key, when using signed ssh keys\n type: string\n name:\n description: The key's name\n type: string\n private:\n description: The private key\n type: string\n required:\n - name\n - private\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n name:\n description: The key's name\n type: string\n required:\n - name\n - generate\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n required:\n - generate\n - dry\nexample:\n name: my-key\n private: |-\n -----BEGIN RSA PRIVATE KEY-----\n MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5 1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh 3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2 pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n -----END RSA PRIVATE KEY-----\ntype: object\n"), + Use: "list-keys", + Short: "List keys", + Long: cli.Markdown("List keys owned by the active org. READ permission required on key."), Example: examples, Group: "keys", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2AddKey(params, body) + _, decoded, outputOptions, err := MistApiV2ListKeys(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5227,7 +5223,13 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -5243,15 +5245,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-keys", - Short: "List keys", - Long: cli.Markdown("List keys owned by the active org. READ permission required on key."), + Use: "add-key", + Short: "Add key", + Long: cli.Markdown("Adds a new key and returns the key's id. ADD permission required on key.\n## Request Schema (application/json)\n\nanyOf:\n- properties:\n certificate:\n description: The signed public key, when using signed ssh keys\n type: string\n name:\n description: The key's name\n type: string\n private:\n description: The private key\n type: string\n required:\n - name\n - private\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n name:\n description: The key's name\n type: string\n required:\n - name\n - generate\n- properties:\n dry:\n description: Return generated key without actually adding it\n type: boolean\n generate:\n description: Generate a keypair instead of providing one\n type: boolean\n required:\n - generate\n - dry\nexample:\n name: my-key\n private: |-\n -----BEGIN RSA PRIVATE KEY-----\n MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5 1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh 3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2 pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n -----END RSA PRIVATE KEY-----\ntype: object\n"), Example: examples, Group: "keys", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListKeys(params) + _, decoded, outputOptions, err := MistApiV2AddKey(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5263,13 +5269,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5478,6 +5478,49 @@ func mistApiV2Register(subcommand bool) { }() + func() { + params := viper.New() + + var examples string + + cmd := &cobra.Command{ + Use: "list-machines", + Short: "List machines", + Long: cli.Markdown("List machines owned by the active org. READ permission required on machine & cloud."), + Example: examples, + Group: "machines", + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + + _, decoded, outputOptions, err := MistApiV2ListMachines(params) + if err != nil { + logger.Fatalf("Error calling operation: %s", err.Error()) + } + + if err := cli.Formatter.Format(decoded, outputOptions); err != nil { + logger.Fatalf("Formatting failed: %s", err.Error()) + } + + }, + } + root.AddCommand(cmd) + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + + cli.SetCustomFlags(cmd) + + if cmd.Flags().HasFlags() { + params.BindPFlags(cmd.Flags()) + } + + }() + func() { params := viper.New() @@ -5544,15 +5587,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-machines", - Short: "List machines", - Long: cli.Markdown("List machines owned by the active org. READ permission required on machine & cloud."), + Use: "edit-machine machine", + Short: "Edit machine", + Long: cli.Markdown("Edit target machine\n## Request Schema (application/json)\n\nproperties:\n expiration:\n properties:\n action:\n enum:\n - stop\n - destroy\n type: string\n date:\n description: format should be ΥΥΥΥ-ΜΜ-DD HH:MM:SS\n type: string\n notify:\n description: seconds before the expiration date to be notified\n type: integer\n required:\n - date\n - action\n type: object\ntype: object\n"), Example: examples, Group: "machines", - Args: cobra.MinimumNArgs(0), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListMachines(params) + _, decoded, outputOptions, err := MistApiV2EditMachine(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5564,14 +5611,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -5619,46 +5659,6 @@ func mistApiV2Register(subcommand bool) { }() - func() { - params := viper.New() - - var examples string - - cmd := &cobra.Command{ - Use: "edit-machine machine", - Short: "Edit machine", - Long: cli.Markdown("Edit target machine\n## Request Schema (application/json)\n\nproperties:\n expiration:\n properties:\n action:\n enum:\n - stop\n - destroy\n type: string\n date:\n description: format should be ΥΥΥΥ-ΜΜ-DD HH:MM:SS\n type: string\n notify:\n description: seconds before the expiration date to be notified\n type: integer\n required:\n - date\n - action\n type: object\ntype: object\n"), - Example: examples, - Group: "machines", - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - - _, decoded, outputOptions, err := MistApiV2EditMachine(args[0], params, body) - if err != nil { - logger.Fatalf("Error calling operation: %s", err.Error()) - } - - if err := cli.Formatter.Format(decoded, outputOptions); err != nil { - logger.Fatalf("Formatting failed: %s", err.Error()) - } - - }, - } - root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - - cli.SetCustomFlags(cmd) - - if cmd.Flags().HasFlags() { - params.BindPFlags(cmd.Flags()) - } - - }() - func() { params := viper.New() @@ -5731,7 +5731,7 @@ func mistApiV2Register(subcommand bool) { root.AddCommand(cmd) cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("async", "", "") + cmd.Flags().String("run-async", "", "") cli.SetCustomFlags(cmd) @@ -7087,19 +7087,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-script script", - Short: "Edit script", - Long: cli.Markdown("Edit target script"), + Use: "delete-script script", + Short: "Delete script", + Long: cli.Markdown("Delete target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7111,10 +7107,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - - cmd.Flags().String("name", "", "New script name") - cmd.Flags().String("description", "", "New script description") cli.SetCustomFlags(cmd) @@ -7130,15 +7122,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-script script", - Short: "Delete script", - Long: cli.Markdown("Delete target script"), + Use: "get-script script", + Short: "Get script", + Long: cli.Markdown("Get details about target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7151,6 +7143,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7165,15 +7160,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-script script", - Short: "Get script", - Long: cli.Markdown("Get details about target script"), + Use: "run-script script", + Short: "Run script", + Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7185,9 +7184,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7203,19 +7200,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "run-script script", - Short: "Run script", - Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), + Use: "edit-script script", + Short: "Edit script", + Long: cli.Markdown("Edit target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7229,6 +7226,9 @@ func mistApiV2Register(subcommand bool) { root.AddCommand(cmd) cmd.Flags().StringP("filename", "f", "", "Filename") + cmd.Flags().String("name", "", "New script name") + cmd.Flags().String("description", "", "New script description") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7436,15 +7436,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-volumes", - Short: "List volumes", - Long: cli.Markdown("List volumes owned by the active org. READ permission required on volume & cloud."), + Use: "create-volume", + Short: "Create volume", + Long: cli.Markdown("Creates one or more volumes on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on volume.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n ex_disk_type:\n description: GCE-specific\n enum:\n - pd-standard\n - pd-ssd\n example: pd-standard\n type: string\n ex_iops:\n description: EC2-specific. Needs to be specified if volume_type='io1'\n type: string\n ex_volume_type:\n description: EC2-specific\n enum:\n - standard\n - io1\n - gp2\n - sc1\n - st1\n example: standard\n type: string\n extra:\n description: Configure additional parameters\n type: object\n location:\n description: Where to provision e.g. region, datacenter, rack\n example: us-central1-a\n type: string\n name:\n description: Specify volume name\n example: my-volume\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple volumes of this type\n type: integer\n save:\n description: Save provisioning plan as template\n type: boolean\n size:\n description: Volume sizing spec\n example: 1\n type: integer\n tags:\n description: Assign tags to provisioned volume\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\n- size\n- location\ntype: object\n"), Example: examples, Group: "volumes", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListVolumes(params) + _, decoded, outputOptions, err := MistApiV2CreateVolume(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7456,14 +7460,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7479,19 +7476,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-volume", - Short: "Create volume", - Long: cli.Markdown("Creates one or more volumes on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on volume.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n ex_disk_type:\n description: GCE-specific\n enum:\n - pd-standard\n - pd-ssd\n example: pd-standard\n type: string\n ex_iops:\n description: EC2-specific. Needs to be specified if volume_type='io1'\n type: string\n ex_volume_type:\n description: EC2-specific\n enum:\n - standard\n - io1\n - gp2\n - sc1\n - st1\n example: standard\n type: string\n extra:\n description: Configure additional parameters\n type: object\n location:\n description: Where to provision e.g. region, datacenter, rack\n example: us-central1-a\n type: string\n name:\n description: Specify volume name\n example: my-volume\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple volumes of this type\n type: integer\n save:\n description: Save provisioning plan as template\n type: boolean\n size:\n description: Volume sizing spec\n example: 1\n type: integer\n tags:\n description: Assign tags to provisioned volume\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\n- size\n- location\ntype: object\n"), + Use: "list-volumes", + Short: "List volumes", + Long: cli.Markdown("List volumes owned by the active org. READ permission required on volume & cloud."), Example: examples, Group: "volumes", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateVolume(params, body) + _, decoded, outputOptions, err := MistApiV2ListVolumes(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7503,7 +7496,14 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -7717,15 +7717,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-zone zone", - Short: "Delete zone", - Long: cli.Markdown("Delete target zone"), + Use: "edit-zone zone", + Short: "Edit zone", + Long: cli.Markdown("Edit target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7737,6 +7741,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7752,15 +7757,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-zone zone", - Short: "Get zone", - Long: cli.Markdown("Get details about target zone"), + Use: "delete-zone zone", + Short: "Delete zone", + Long: cli.Markdown("Delete target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7773,9 +7778,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7790,19 +7792,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-zone zone", - Short: "Edit zone", - Long: cli.Markdown("Edit target zone"), + Use: "get-zone zone", + Short: "Get zone", + Long: cli.Markdown("Get details about target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7814,7 +7812,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) From b0bc9565973eaf785be010a2960b2e4ef70b27d5 Mon Sep 17 00:00:00 2001 From: Mist Gitlab Runner Date: Tue, 16 Nov 2021 16:47:51 +0000 Subject: [PATCH 4/5] Regenerate mist-cli after: Improve clone operation --- mist-api-v2.go | 790 ++++++++++++++++++++++++------------------------- 1 file changed, 395 insertions(+), 395 deletions(-) diff --git a/mist-api-v2.go b/mist-api-v2.go index 368e313..b1378cc 100644 --- a/mist-api-v2.go +++ b/mist-api-v2.go @@ -206,9 +206,9 @@ func MistApiV2AddCloud(params *viper.Viper, body string) (*gentleman.Response, m return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditCloud Edit cloud -func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-cloud" +// MistApiV2RemoveCloud Remove cloud +func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "remove-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -226,11 +226,7 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Put().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -257,9 +253,9 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RemoveCloud Remove cloud -func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "remove-cloud" +// MistApiV2GetCloud Get cloud +func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -277,7 +273,20 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -286,7 +295,7 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -298,15 +307,15 @@ func MistApiV2RemoveCloud(paramCloud string, params *viper.Viper) (*gentleman.Re after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetCloud Get cloud -func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-cloud" +// MistApiV2EditCloud Edit cloud +func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-cloud" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -324,19 +333,10 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo url := server + "/api/v2/clouds/{cloud}" url = strings.Replace(url, "{cloud}", paramCloud, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -346,7 +346,7 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -358,15 +358,15 @@ func MistApiV2GetCloud(paramCloud string, params *viper.Viper) (*gentleman.Respo after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "provider", "tags"}, []string{"id", "name", "provider", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2ListClusters List clusters -func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-clusters" +// MistApiV2CreateCluster Create cluster +func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-cluster" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -383,35 +383,10 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string url := server + "/api/v2/clusters" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramCloud := params.GetString("cloud") - if paramCloud != "" { - req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) - } - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -421,7 +396,7 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -433,15 +408,15 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "total_nodes", "tags"}, []string{"id", "name", "cloud", "total_nodes", "total_cpus", "total_ram", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2CreateCluster Create cluster -func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-cluster" +// MistApiV2ListClusters List clusters +func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-clusters" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -458,10 +433,35 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon url := server + "/api/v2/clusters" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramCloud := params.GetString("cloud") + if paramCloud != "" { + req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) + } + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -471,7 +471,7 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -483,10 +483,10 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "total_nodes", "tags"}, []string{"id", "name", "cloud", "total_nodes", "total_cpus", "total_ram", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2DestroyCluster Destroy cluster @@ -1391,9 +1391,9 @@ func MistApiV2CreateMachine(params *viper.Viper, body string) (*gentleman.Respon return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditMachine Edit machine -func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-machine" +// MistApiV2GetMachine Get machine +func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1411,10 +1411,15 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) url := server + "/api/v2/machines/{machine}" url = strings.Replace(url, "{machine}", paramMachine, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -1424,7 +1429,7 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -1436,15 +1441,15 @@ func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetMachine Get machine -func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-machine" +// MistApiV2EditMachine Edit machine +func MistApiV2EditMachine(paramMachine string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-machine" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -1462,15 +1467,10 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R url := server + "/api/v2/machines/{machine}" url = strings.Replace(url, "{machine}", paramMachine, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -1480,7 +1480,7 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -1492,10 +1492,10 @@ func MistApiV2GetMachine(paramMachine string, params *viper.Viper) (*gentleman.R after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "state", "tags"}, []string{"id", "name", "state", "cloud", "external_id", "public_ips", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2AssociateKey Associate a key with a machine @@ -3095,53 +3095,6 @@ func MistApiV2AddRule(params *viper.Viper, body string) (*gentleman.Response, ma return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteRule Delete rule -func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-rule" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/rules/{rule}" - url = strings.Replace(url, "{rule}", paramRule, 1) - - req := cli.Client.Delete().URL(url) - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after - } - - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil -} - // MistApiV2GetRule Get rule func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { handlerPath := "get-rule" @@ -3355,9 +3308,9 @@ func MistApiV2ToggleRule(paramRule string, paramAction string, params *viper.Vip return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2ListScripts List scripts -func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-scripts" +// MistApiV2DeleteRule Delete rule +func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3372,33 +3325,59 @@ func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string] return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/scripts" + url := server + "/api/v2/rules/{rule}" + url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Delete().URL(url) - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + + var decoded interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + +// MistApiV2AddScript Add script +func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-script" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/scripts" + + req := cli.Client.Post().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3423,12 +3402,12 @@ func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string] decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2AddScript Add script -func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-script" +// MistApiV2ListScripts List scripts +func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-scripts" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3445,10 +3424,31 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, url := server + "/api/v2/scripts" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -3473,7 +3473,7 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2DeleteScript Delete script @@ -3986,9 +3986,9 @@ func MistApiV2ListUsers(params *viper.Viper) (*gentleman.Response, map[string]in return resp, decoded, cli.CLIOutputOptions{[]string{"email"}, []string{"email", "id", "last_login", "registration_date"}, []string{}, []string{}}, nil } -// MistApiV2CreateVolume Create volume -func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-volume" +// MistApiV2ListVolumes List volumes +func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-volumes" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4005,10 +4005,35 @@ func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Respons url := server + "/api/v2/volumes" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramCloud := params.GetString("cloud") + if paramCloud != "" { + req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) + } + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -4033,12 +4058,12 @@ func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Respons decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "size", "cloud", "location", "attached_to", "tags"}, []string{"id", "name", "size", "cloud", "location", "external_id", "attached_to", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2ListVolumes List volumes -func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-volumes" +// MistApiV2CreateVolume Create volume +func MistApiV2CreateVolume(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-volume" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4055,35 +4080,10 @@ func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string] url := server + "/api/v2/volumes" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramCloud := params.GetString("cloud") - if paramCloud != "" { - req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) - } - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -4108,7 +4108,7 @@ func MistApiV2ListVolumes(params *viper.Viper) (*gentleman.Response, map[string] decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "size", "cloud", "location", "attached_to", "tags"}, []string{"id", "name", "size", "cloud", "location", "external_id", "attached_to", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2DeleteVolume Delete volume @@ -4395,9 +4395,9 @@ func MistApiV2CreateZone(params *viper.Viper, body string) (*gentleman.Response, return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditZone Edit zone -func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-zone" +// MistApiV2DeleteZone Delete zone +func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4415,11 +4415,7 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Put().URL(url) - - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) - } + req := cli.Client.Delete().URL(url) cli.HandleBefore(handlerPath, params, req) @@ -4446,9 +4442,9 @@ func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gen return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2DeleteZone Delete zone -func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-zone" +// MistApiV2GetZone Get zone +func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4466,7 +4462,16 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Delete().URL(url) + req := cli.Client.Get().URL(url) + + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + } cli.HandleBefore(handlerPath, params, req) @@ -4475,7 +4480,7 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4487,15 +4492,15 @@ func MistApiV2DeleteZone(paramZone string, params *viper.Viper) (*gentleman.Resp after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2GetZone Get zone -func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-zone" +// MistApiV2EditZone Edit zone +func MistApiV2EditZone(paramZone string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-zone" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -4513,15 +4518,10 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons url := server + "/api/v2/zones/{zone}" url = strings.Replace(url, "{zone}", paramZone, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Put().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -4531,7 +4531,7 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -4543,10 +4543,10 @@ func MistApiV2GetZone(paramZone string, params *viper.Viper) (*gentleman.Respons after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "machines", "tags"}, []string{"id", "name", "cloud", "location", "external_id", "subnets", "machines", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } func MistApiV2JobFinishedWaiter(paramJobId string, params *viper.Viper) error { @@ -4775,19 +4775,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-cloud cloud", - Short: "Edit cloud", - Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), + Use: "remove-cloud cloud", + Short: "Remove cloud", + Long: cli.Markdown("Remove target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4799,7 +4795,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4815,15 +4810,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "remove-cloud cloud", - Short: "Remove cloud", - Long: cli.Markdown("Remove target cloud"), + Use: "get-cloud cloud", + Short: "Get cloud", + Long: cli.Markdown("Get details about target cloud"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2RemoveCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4836,6 +4831,10 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -4850,15 +4849,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-cloud cloud", - Short: "Get cloud", - Long: cli.Markdown("Get details about target cloud"), + Use: "edit-cloud cloud", + Short: "Edit cloud", + Long: cli.Markdown("Update target cloud name or credentials\n## Request Schema (application/json)\n\nanyOf:\n- $ref: '#/components/schemas/EditCloudRequest_anyOf'\n- allOf:\n - properties:\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n required:\n - provider\n type: object\n - discriminator:\n mapping:\n alibaba: '#/components/schemas/AlibabaCloudRequest'\n amazon: '#/components/schemas/AmazonCloudRequest'\n azure: '#/components/schemas/AzureCloudRequest'\n cloudsigma: '#/components/schemas/CloudSigmaCloudRequest'\n docker: '#/components/schemas/DockerCloudRequest'\n equinix: '#/components/schemas/EquinixCloudRequest'\n google: '#/components/schemas/GoogleCloudRequest'\n ibm: '#/components/schemas/IbmCloudRequest'\n kubernetes: '#/components/schemas/KubernetesCloudRequest'\n kubevirt: '#/components/schemas/KubevirtCloudRequest'\n kvm: '#/components/schemas/KvmCloudRequest'\n linode: '#/components/schemas/LinodeCloudRequest'\n lxd: '#/components/schemas/LxdCloudRequest'\n maxihost: '#/components/schemas/MaxihostCloudRequest'\n onapp: '#/components/schemas/OnappCloudRequest'\n openshift: '#/components/schemas/OpenshiftCloudRequest'\n openstack: '#/components/schemas/OpenstackCloudRequest'\n other: '#/components/schemas/OtherCloudRequest'\n rackspace: '#/components/schemas/RackspaceCloudRequest'\n vsphere: '#/components/schemas/VsphereCloudRequest'\n vultr: '#/components/schemas/VultrCloudRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonCloudRequest'\n - $ref: '#/components/schemas/AzureCloudRequest'\n - $ref: '#/components/schemas/GoogleCloudRequest'\n - $ref: '#/components/schemas/AlibabaCloudRequest'\n - $ref: '#/components/schemas/CloudSigmaCloudRequest'\n - $ref: '#/components/schemas/EquinixCloudRequest'\n - $ref: '#/components/schemas/IbmCloudRequest'\n - $ref: '#/components/schemas/DigitaloceanCloudRequest'\n - $ref: '#/components/schemas/LinodeCloudRequest'\n - $ref: '#/components/schemas/RackspaceCloudRequest'\n - $ref: '#/components/schemas/MaxihostCloudRequest'\n - $ref: '#/components/schemas/VultrCloudRequest'\n - $ref: '#/components/schemas/OpenstackCloudRequest'\n - $ref: '#/components/schemas/OnappCloudRequest'\n - $ref: '#/components/schemas/VsphereCloudRequest'\n - $ref: '#/components/schemas/KvmCloudRequest'\n - $ref: '#/components/schemas/LxdCloudRequest'\n - $ref: '#/components/schemas/DockerCloudRequest'\n - $ref: '#/components/schemas/KubernetesCloudRequest'\n - $ref: '#/components/schemas/KubevirtCloudRequest'\n - $ref: '#/components/schemas/OpenshiftCloudRequest'\n - $ref: '#/components/schemas/OtherCloudRequest'\nexample:\n name: my-renamed-cloud\n"), Example: examples, Group: "clouds", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetCloud(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditCloud(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4867,13 +4870,10 @@ func mistApiV2Register(subcommand bool) { logger.Fatalf("Formatting failed: %s", err.Error()) } - }, - } - root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + }, + } + root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4889,15 +4889,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-clusters", - Short: "List clusters", - Long: cli.Markdown("List clusters"), + Use: "create-cluster", + Short: "Create cluster", + Long: cli.Markdown("Create a new cluster and return the cluster's id\n## Request Schema (application/json)\n\nallOf:\n- properties:\n cloud:\n description: The cloud the cluster belongs to\n type: string\n name:\n description: The name of the cluster to create\n type: string\n provider:\n $ref: '#/components/schemas/ClusterProviders'\n required:\n - name\n - cloud\n - provider\n type: object\n- discriminator:\n mapping:\n amazon: '#/components/schemas/AmazonClusterRequest'\n google: '#/components/schemas/GoogleClusterRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonClusterRequest'\n - $ref: '#/components/schemas/GoogleClusterRequest'\nexample:\n cloud: my-cloud\n location: my-location\n name: my-cluster\n provider: google\n"), Example: examples, Group: "clusters", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListClusters(params) + _, decoded, outputOptions, err := MistApiV2CreateCluster(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4909,14 +4913,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -4932,19 +4929,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-cluster", - Short: "Create cluster", - Long: cli.Markdown("Create a new cluster and return the cluster's id\n## Request Schema (application/json)\n\nallOf:\n- properties:\n cloud:\n description: The cloud the cluster belongs to\n type: string\n name:\n description: The name of the cluster to create\n type: string\n provider:\n $ref: '#/components/schemas/ClusterProviders'\n required:\n - name\n - cloud\n - provider\n type: object\n- discriminator:\n mapping:\n amazon: '#/components/schemas/AmazonClusterRequest'\n google: '#/components/schemas/GoogleClusterRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonClusterRequest'\n - $ref: '#/components/schemas/GoogleClusterRequest'\nexample:\n cloud: my-cloud\n location: my-location\n name: my-cluster\n provider: google\n"), + Use: "list-clusters", + Short: "List clusters", + Long: cli.Markdown("List clusters"), Example: examples, Group: "clusters", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateCluster(params, body) + _, decoded, outputOptions, err := MistApiV2ListClusters(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4956,7 +4949,14 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -5587,19 +5587,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-machine machine", - Short: "Edit machine", - Long: cli.Markdown("Edit target machine\n## Request Schema (application/json)\n\nproperties:\n expiration:\n properties:\n action:\n enum:\n - stop\n - destroy\n type: string\n date:\n description: format should be ΥΥΥΥ-ΜΜ-DD HH:MM:SS\n type: string\n notify:\n description: seconds before the expiration date to be notified\n type: integer\n required:\n - date\n - action\n type: object\ntype: object\n"), + Use: "get-machine machine", + Short: "Get machine", + Long: cli.Markdown("Get details about target machine"), Example: examples, Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditMachine(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2GetMachine(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5611,7 +5607,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -5627,15 +5625,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-machine machine", - Short: "Get machine", - Long: cli.Markdown("Get details about target machine"), + Use: "edit-machine machine", + Short: "Edit machine", + Long: cli.Markdown("Edit target machine\n## Request Schema (application/json)\n\nproperties:\n expiration:\n properties:\n action:\n enum:\n - stop\n - destroy\n type: string\n date:\n description: format should be ΥΥΥΥ-ΜΜ-DD HH:MM:SS\n type: string\n notify:\n description: seconds before the expiration date to be notified\n type: integer\n required:\n - date\n - action\n type: object\ntype: object\n"), Example: examples, Group: "machines", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetMachine(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditMachine(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -5647,9 +5649,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6806,41 +6806,6 @@ func mistApiV2Register(subcommand bool) { }() - func() { - params := viper.New() - - var examples string - - cmd := &cobra.Command{ - Use: "delete-rule rule", - Short: "Delete rule", - Long: cli.Markdown("Delete a rule given its UUID."), - Example: examples, - Group: "rules", - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - - _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) - if err != nil { - logger.Fatalf("Error calling operation: %s", err.Error()) - } - - if err := cli.Formatter.Format(decoded, outputOptions); err != nil { - logger.Fatalf("Formatting failed: %s", err.Error()) - } - - }, - } - root.AddCommand(cmd) - - cli.SetCustomFlags(cmd) - - if cmd.Flags().HasFlags() { - params.BindPFlags(cmd.Flags()) - } - - }() - func() { params := viper.New() @@ -7005,15 +6970,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-scripts", - Short: "List scripts", - Long: cli.Markdown("List scripts owned by the active org. READ permission required on script."), + Use: "delete-rule rule", + Short: "Delete rule", + Long: cli.Markdown("Delete a rule given its UUID."), Example: examples, - Group: "scripts", - Args: cobra.MinimumNArgs(0), + Group: "rules", + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2ListScripts(params) + _, decoded, outputOptions, err := MistApiV2DeleteRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7026,13 +6991,6 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") - cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7081,6 +7039,48 @@ func mistApiV2Register(subcommand bool) { }() + func() { + params := viper.New() + + var examples string + + cmd := &cobra.Command{ + Use: "list-scripts", + Short: "List scripts", + Long: cli.Markdown("List scripts owned by the active org. READ permission required on script."), + Example: examples, + Group: "scripts", + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + + _, decoded, outputOptions, err := MistApiV2ListScripts(params) + if err != nil { + logger.Fatalf("Error calling operation: %s", err.Error()) + } + + if err := cli.Formatter.Format(decoded, outputOptions); err != nil { + logger.Fatalf("Formatting failed: %s", err.Error()) + } + + }, + } + root.AddCommand(cmd) + + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + + cli.SetCustomFlags(cmd) + + if cmd.Flags().HasFlags() { + params.BindPFlags(cmd.Flags()) + } + + }() + func() { params := viper.New() @@ -7436,19 +7436,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-volume", - Short: "Create volume", - Long: cli.Markdown("Creates one or more volumes on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on volume.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n ex_disk_type:\n description: GCE-specific\n enum:\n - pd-standard\n - pd-ssd\n example: pd-standard\n type: string\n ex_iops:\n description: EC2-specific. Needs to be specified if volume_type='io1'\n type: string\n ex_volume_type:\n description: EC2-specific\n enum:\n - standard\n - io1\n - gp2\n - sc1\n - st1\n example: standard\n type: string\n extra:\n description: Configure additional parameters\n type: object\n location:\n description: Where to provision e.g. region, datacenter, rack\n example: us-central1-a\n type: string\n name:\n description: Specify volume name\n example: my-volume\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple volumes of this type\n type: integer\n save:\n description: Save provisioning plan as template\n type: boolean\n size:\n description: Volume sizing spec\n example: 1\n type: integer\n tags:\n description: Assign tags to provisioned volume\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\n- size\n- location\ntype: object\n"), + Use: "list-volumes", + Short: "List volumes", + Long: cli.Markdown("List volumes owned by the active org. READ permission required on volume & cloud."), Example: examples, Group: "volumes", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateVolume(params, body) + _, decoded, outputOptions, err := MistApiV2ListVolumes(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7460,7 +7456,14 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -7476,15 +7479,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-volumes", - Short: "List volumes", - Long: cli.Markdown("List volumes owned by the active org. READ permission required on volume & cloud."), + Use: "create-volume", + Short: "Create volume", + Long: cli.Markdown("Creates one or more volumes on the specified cloud. If async is true, a jobId will be returned. READ permission required on cloud. CREATE_RESOURCES permission required on cloud. READ permission required on location. CREATE_RESOURCES permission required on location. CREATE permission required on volume.\n## Request Schema (application/json)\n\nproperties:\n cloud:\n description: Specify cloud to provision on\n example: my-cloud\n type: string\n dry:\n description: Return provisioning plan and exit without executing it\n type: boolean\n ex_disk_type:\n description: GCE-specific\n enum:\n - pd-standard\n - pd-ssd\n example: pd-standard\n type: string\n ex_iops:\n description: EC2-specific. Needs to be specified if volume_type='io1'\n type: string\n ex_volume_type:\n description: EC2-specific\n enum:\n - standard\n - io1\n - gp2\n - sc1\n - st1\n example: standard\n type: string\n extra:\n description: Configure additional parameters\n type: object\n location:\n description: Where to provision e.g. region, datacenter, rack\n example: us-central1-a\n type: string\n name:\n description: Specify volume name\n example: my-volume\n type: string\n provider:\n $ref: '#/components/schemas/SupportedProviders'\n quantity:\n description: Provision multiple volumes of this type\n type: integer\n save:\n description: Save provisioning plan as template\n type: boolean\n size:\n description: Volume sizing spec\n example: 1\n type: integer\n tags:\n description: Assign tags to provisioned volume\n type: object\n template:\n type: object\nrequired:\n- name\n- cloud\n- size\n- location\ntype: object\n"), Example: examples, Group: "volumes", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListVolumes(params) + _, decoded, outputOptions, err := MistApiV2CreateVolume(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7496,14 +7503,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7717,19 +7717,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-zone zone", - Short: "Edit zone", - Long: cli.Markdown("Edit target zone"), + Use: "delete-zone zone", + Short: "Delete zone", + Long: cli.Markdown("Delete target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7741,7 +7737,6 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7757,15 +7752,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-zone zone", - Short: "Delete zone", - Long: cli.Markdown("Delete target zone"), + Use: "get-zone zone", + Short: "Get zone", + Long: cli.Markdown("Get details about target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - _, decoded, outputOptions, err := MistApiV2DeleteZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7778,6 +7773,9 @@ func mistApiV2Register(subcommand bool) { } root.AddCommand(cmd) + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7792,15 +7790,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-zone zone", - Short: "Get zone", - Long: cli.Markdown("Get details about target zone"), + Use: "edit-zone zone", + Short: "Edit zone", + Long: cli.Markdown("Edit target zone"), Example: examples, Group: "zones", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetZone(args[0], params) + _, decoded, outputOptions, err := MistApiV2EditZone(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7812,9 +7814,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) From 3b7df3b0fe556eff7085bb211c28e4788f20bb40 Mon Sep 17 00:00:00 2001 From: Mist Gitlab Runner Date: Tue, 16 Nov 2021 16:56:26 +0000 Subject: [PATCH 5/5] Regenerate mist-cli after: Improve clone operation --- mist-api-v2.go | 490 ++++++++++++++++++++++++------------------------- 1 file changed, 245 insertions(+), 245 deletions(-) diff --git a/mist-api-v2.go b/mist-api-v2.go index b1378cc..94a6416 100644 --- a/mist-api-v2.go +++ b/mist-api-v2.go @@ -364,9 +364,9 @@ func MistApiV2EditCloud(paramCloud string, params *viper.Viper, body string) (*g return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2CreateCluster Create cluster -func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "create-cluster" +// MistApiV2ListClusters List clusters +func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "list-clusters" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -383,10 +383,35 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon url := server + "/api/v2/clusters" - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramCloud := params.GetString("cloud") + if paramCloud != "" { + req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) + } + paramSearch := params.GetString("search") + if paramSearch != "" { + req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) + } + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramStart := params.GetString("start") + if paramStart != "" { + req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) + } + paramLimit := params.GetInt64("limit") + if paramLimit != 0 { + req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -396,7 +421,7 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -408,15 +433,15 @@ func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Respon after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "total_nodes", "tags"}, []string{"id", "name", "cloud", "total_nodes", "total_cpus", "total_ram", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2ListClusters List clusters -func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "list-clusters" +// MistApiV2CreateCluster Create cluster +func MistApiV2CreateCluster(params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "create-cluster" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -433,35 +458,10 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string url := server + "/api/v2/clusters" - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramCloud := params.GetString("cloud") - if paramCloud != "" { - req = req.AddQuery("cloud", fmt.Sprintf("%v", paramCloud)) - } - paramSearch := params.GetString("search") - if paramSearch != "" { - req = req.AddQuery("search", fmt.Sprintf("%v", paramSearch)) - } - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramStart := params.GetString("start") - if paramStart != "" { - req = req.AddQuery("start", fmt.Sprintf("%v", paramStart)) - } - paramLimit := params.GetInt64("limit") - if paramLimit != 0 { - req = req.AddQuery("limit", fmt.Sprintf("%v", paramLimit)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -471,7 +471,7 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -483,10 +483,10 @@ func MistApiV2ListClusters(params *viper.Viper) (*gentleman.Response, map[string after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "cloud", "total_nodes", "tags"}, []string{"id", "name", "cloud", "total_nodes", "total_cpus", "total_ram", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } // MistApiV2DestroyCluster Destroy cluster @@ -3095,62 +3095,6 @@ func MistApiV2AddRule(params *viper.Viper, body string) (*gentleman.Response, ma return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetRule Get rule -func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-rule" - if mistApiV2Subcommand { - handlerPath = "Mist CLI " + handlerPath - } - - err := setMistContext() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - server, err := getServer() - if err != nil { - return nil, nil, cli.CLIOutputOptions{}, err - } - - url := server + "/api/v2/rules/{rule}" - url = strings.Replace(url, "{rule}", paramRule, 1) - - req := cli.Client.Get().URL(url) - - paramSort := params.GetString("sort") - if paramSort != "" { - req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) - } - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - - cli.HandleBefore(handlerPath, params, req) - - resp, err := req.Do() - if err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") - } - - var decoded map[string]interface{} - - if resp.StatusCode < 400 { - if err := cli.UnmarshalResponse(resp, &decoded); err != nil { - return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") - } - } else { - return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) - } - - after := cli.HandleAfter(handlerPath, params, resp, decoded) - if after != nil { - decoded = after.(map[string]interface{}) - } - - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "queries", "actions", "tags"}, []string{"id", "name", "resource_type", "selectors", "queries", "actions", "window", "frequency", "tags"}, []string{}, []string{}}, nil -} - // MistApiV2RenameRule Rename rule func MistApiV2RenameRule(paramRule string, paramName string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { handlerPath := "rename-rule" @@ -3355,9 +3299,9 @@ func MistApiV2DeleteRule(paramRule string, params *viper.Viper) (*gentleman.Resp return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2AddScript Add script -func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "add-script" +// MistApiV2GetRule Get rule +func MistApiV2GetRule(paramRule string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-rule" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3372,12 +3316,18 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/scripts" + url := server + "/api/v2/rules/{rule}" + url = strings.Replace(url, "{rule}", paramRule, 1) - req := cli.Client.Post().URL(url) + req := cli.Client.Get().URL(url) - if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + paramSort := params.GetString("sort") + if paramSort != "" { + req = req.AddQuery("sort", fmt.Sprintf("%v", paramSort)) + } + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) } cli.HandleBefore(handlerPath, params, req) @@ -3402,7 +3352,7 @@ func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "queries", "actions", "tags"}, []string{"id", "name", "resource_type", "selectors", "queries", "actions", "window", "frequency", "tags"}, []string{}, []string{}}, nil } // MistApiV2ListScripts List scripts @@ -3476,9 +3426,9 @@ func MistApiV2ListScripts(params *viper.Viper) (*gentleman.Response, map[string] return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } -// MistApiV2DeleteScript Delete script -func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "delete-script" +// MistApiV2AddScript Add script +func MistApiV2AddScript(params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "add-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3493,10 +3443,13 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. return nil, nil, cli.CLIOutputOptions{}, err } - url := server + "/api/v2/scripts/{script}" - url = strings.Replace(url, "{script}", paramScript, 1) + url := server + "/api/v2/scripts" - req := cli.Client.Delete().URL(url) + req := cli.Client.Post().URL(url) + + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) + } cli.HandleBefore(handlerPath, params, req) @@ -3505,7 +3458,7 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3517,15 +3470,15 @@ func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman. after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2GetScript Get script -func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "get-script" +// MistApiV2RunScript Run script +func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "run-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3543,15 +3496,10 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Get().URL(url) + req := cli.Client.Post().URL(url) - paramOnly := params.GetString("only") - if paramOnly != "" { - req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) - } - paramDeref := params.GetString("deref") - if paramDeref != "" { - req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) + if body != "" { + req = req.AddHeader("Content-Type", "application/json").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3576,12 +3524,12 @@ func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Res decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2RunScript Run script -func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { - handlerPath := "run-script" +// MistApiV2EditScript Edit script +func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "edit-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3599,10 +3547,19 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Post().URL(url) + req := cli.Client.Put().URL(url) + + paramName := params.GetString("name") + if paramName != "" { + req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + } + paramDescription := params.GetString("description") + if paramDescription != "" { + req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + } if body != "" { - req = req.AddHeader("Content-Type", "application/json").BodyString(body) + req = req.AddHeader("Content-Type", "").BodyString(body) } cli.HandleBefore(handlerPath, params, req) @@ -3612,7 +3569,7 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded map[string]interface{} + var decoded interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3624,15 +3581,15 @@ func MistApiV2RunScript(paramScript string, params *viper.Viper, body string) (* after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after.(map[string]interface{}) + decoded = after } return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil } -// MistApiV2EditScript Edit script -func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { - handlerPath := "edit-script" +// MistApiV2DeleteScript Delete script +func MistApiV2DeleteScript(paramScript string, params *viper.Viper) (*gentleman.Response, interface{}, cli.CLIOutputOptions, error) { + handlerPath := "delete-script" if mistApiV2Subcommand { handlerPath = "Mist CLI " + handlerPath } @@ -3650,19 +3607,62 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( url := server + "/api/v2/scripts/{script}" url = strings.Replace(url, "{script}", paramScript, 1) - req := cli.Client.Put().URL(url) + req := cli.Client.Delete().URL(url) - paramName := params.GetString("name") - if paramName != "" { - req = req.AddQuery("name", fmt.Sprintf("%v", paramName)) + cli.HandleBefore(handlerPath, params, req) + + resp, err := req.Do() + if err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - paramDescription := params.GetString("description") - if paramDescription != "" { - req = req.AddQuery("description", fmt.Sprintf("%v", paramDescription)) + + var decoded interface{} + + if resp.StatusCode < 400 { + if err := cli.UnmarshalResponse(resp, &decoded); err != nil { + return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Unmarshalling response failed") + } + } else { + return resp, nil, cli.CLIOutputOptions{}, errors.Errorf("HTTP %d: %s", resp.StatusCode, resp.String()) } - if body != "" { - req = req.AddHeader("Content-Type", "").BodyString(body) + after := cli.HandleAfter(handlerPath, params, resp, decoded) + if after != nil { + decoded = after + } + + return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil +} + +// MistApiV2GetScript Get script +func MistApiV2GetScript(paramScript string, params *viper.Viper) (*gentleman.Response, map[string]interface{}, cli.CLIOutputOptions, error) { + handlerPath := "get-script" + if mistApiV2Subcommand { + handlerPath = "Mist CLI " + handlerPath + } + + err := setMistContext() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + server, err := getServer() + if err != nil { + return nil, nil, cli.CLIOutputOptions{}, err + } + + url := server + "/api/v2/scripts/{script}" + url = strings.Replace(url, "{script}", paramScript, 1) + + req := cli.Client.Get().URL(url) + + paramOnly := params.GetString("only") + if paramOnly != "" { + req = req.AddQuery("only", fmt.Sprintf("%v", paramOnly)) + } + paramDeref := params.GetString("deref") + if paramDeref != "" { + req = req.AddQuery("deref", fmt.Sprintf("%v", paramDeref)) } cli.HandleBefore(handlerPath, params, req) @@ -3672,7 +3672,7 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( return resp, nil, cli.CLIOutputOptions{}, errors.Wrap(err, "Request failed") } - var decoded interface{} + var decoded map[string]interface{} if resp.StatusCode < 400 { if err := cli.UnmarshalResponse(resp, &decoded); err != nil { @@ -3684,10 +3684,10 @@ func MistApiV2EditScript(paramScript string, params *viper.Viper, body string) ( after := cli.HandleAfter(handlerPath, params, resp, decoded) if after != nil { - decoded = after + decoded = after.(map[string]interface{}) } - return resp, decoded, cli.CLIOutputOptions{[]string{}, []string{}, []string{}, []string{}}, nil + return resp, decoded, cli.CLIOutputOptions{[]string{"name", "tags"}, []string{"id", "name", "description", "tags", "owned_by", "created_by"}, []string{}, []string{}}, nil } // MistApiV2DownloadScript Download script @@ -4889,19 +4889,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "create-cluster", - Short: "Create cluster", - Long: cli.Markdown("Create a new cluster and return the cluster's id\n## Request Schema (application/json)\n\nallOf:\n- properties:\n cloud:\n description: The cloud the cluster belongs to\n type: string\n name:\n description: The name of the cluster to create\n type: string\n provider:\n $ref: '#/components/schemas/ClusterProviders'\n required:\n - name\n - cloud\n - provider\n type: object\n- discriminator:\n mapping:\n amazon: '#/components/schemas/AmazonClusterRequest'\n google: '#/components/schemas/GoogleClusterRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonClusterRequest'\n - $ref: '#/components/schemas/GoogleClusterRequest'\nexample:\n cloud: my-cloud\n location: my-location\n name: my-cluster\n provider: google\n"), + Use: "list-clusters", + Short: "List clusters", + Long: cli.Markdown("List clusters"), Example: examples, Group: "clusters", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2CreateCluster(params, body) + _, decoded, outputOptions, err := MistApiV2ListClusters(params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4913,7 +4909,14 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("cloud", "", "") + cmd.Flags().String("search", "", "Only return results matching search filter") + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("start", "", "Start results from index or id") + cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd) @@ -4929,15 +4932,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "list-clusters", - Short: "List clusters", - Long: cli.Markdown("List clusters"), + Use: "create-cluster", + Short: "Create cluster", + Long: cli.Markdown("Create a new cluster and return the cluster's id\n## Request Schema (application/json)\n\nallOf:\n- properties:\n cloud:\n description: The cloud the cluster belongs to\n type: string\n name:\n description: The name of the cluster to create\n type: string\n provider:\n $ref: '#/components/schemas/ClusterProviders'\n required:\n - name\n - cloud\n - provider\n type: object\n- discriminator:\n mapping:\n amazon: '#/components/schemas/AmazonClusterRequest'\n google: '#/components/schemas/GoogleClusterRequest'\n propertyName: provider\n oneOf:\n - $ref: '#/components/schemas/AmazonClusterRequest'\n - $ref: '#/components/schemas/GoogleClusterRequest'\nexample:\n cloud: my-cloud\n location: my-location\n name: my-cluster\n provider: google\n"), Example: examples, Group: "clusters", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2ListClusters(params) + _, decoded, outputOptions, err := MistApiV2CreateCluster(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -4949,14 +4956,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("cloud", "", "") - cmd.Flags().String("search", "", "Only return results matching search filter") - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("start", "", "Start results from index or id") - cmd.Flags().Int64("limit", 0, "Limit number of results, 1000 max") - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -6806,44 +6806,6 @@ func mistApiV2Register(subcommand bool) { }() - func() { - params := viper.New() - - var examples string - - cmd := &cobra.Command{ - Use: "get-rule rule", - Short: "Get rule", - Long: cli.Markdown("Get details about target rule"), - Example: examples, - Group: "rules", - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - - _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) - if err != nil { - logger.Fatalf("Error calling operation: %s", err.Error()) - } - - if err := cli.Formatter.Format(decoded, outputOptions); err != nil { - logger.Fatalf("Formatting failed: %s", err.Error()) - } - - }, - } - root.AddCommand(cmd) - - cmd.Flags().String("sort", "", "Order results by") - cmd.Flags().String("only", "", "Only return these fields") - - cli.SetCustomFlags(cmd) - - if cmd.Flags().HasFlags() { - params.BindPFlags(cmd.Flags()) - } - - }() - func() { params := viper.New() @@ -7005,19 +6967,15 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "add-script", - Short: "Add script", - Long: cli.Markdown("Add script to user scripts\n## Request Schema (application/json)\n\nproperties:\n description:\n type: string\n entrypoint:\n example: entrypoint.sh\n type: string\n exec_type:\n enum:\n - executable\n - ansible\n example: executable\n type: string\n location_type:\n enum:\n - inline\n - github\n - url\n example: inline\n type: string\n name:\n example: my-script\n type: string\n script:\n example: |-\n #!/usr/bin/env bash\n echo Hello, World!\n type: string\nrequired:\n- name\n- script\n- location_type\n- exec_type\ntype: object\n"), + Use: "get-rule rule", + Short: "Get rule", + Long: cli.Markdown("Get details about target rule"), Example: examples, - Group: "scripts", - Args: cobra.MinimumNArgs(0), + Group: "rules", + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) - if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) - } - _, decoded, outputOptions, err := MistApiV2AddScript(params, body) + _, decoded, outputOptions, err := MistApiV2GetRule(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7029,7 +6987,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") + + cmd.Flags().String("sort", "", "Order results by") + cmd.Flags().String("only", "", "Only return these fields") cli.SetCustomFlags(cmd) @@ -7087,15 +7047,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "delete-script script", - Short: "Delete script", - Long: cli.Markdown("Delete target script"), + Use: "add-script", + Short: "Add script", + Long: cli.Markdown("Add script to user scripts\n## Request Schema (application/json)\n\nproperties:\n description:\n type: string\n entrypoint:\n example: entrypoint.sh\n type: string\n exec_type:\n enum:\n - executable\n - ansible\n example: executable\n type: string\n location_type:\n enum:\n - inline\n - github\n - url\n example: inline\n type: string\n name:\n example: my-script\n type: string\n script:\n example: |-\n #!/usr/bin/env bash\n echo Hello, World!\n type: string\nrequired:\n- name\n- script\n- location_type\n- exec_type\ntype: object\n"), Example: examples, Group: "scripts", - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[0:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2AddScript(params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7107,6 +7071,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7122,15 +7087,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "get-script script", - Short: "Get script", - Long: cli.Markdown("Get details about target script"), + Use: "run-script script", + Short: "Run script", + Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + if err != nil { + logger.Fatalf("Unable to get body: %s", err.Error()) + } - _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) + _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7142,9 +7111,7 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - - cmd.Flags().String("only", "", "Only return these fields") - cmd.Flags().String("deref", "", "Dereference foreign keys") + cmd.Flags().StringP("filename", "f", "", "Filename") cli.SetCustomFlags(cmd) @@ -7160,19 +7127,19 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "run-script script", - Short: "Run script", - Long: cli.Markdown("Start a script job to run the script.\n## Request Schema (application/json)\n\nproperties:\n env:\n example: EXAMPLE_VAR=123\n type: string\n job_id:\n example: ab74e2f0b7ae4999b1e4013e20dac418\n type: string\n machine:\n example: my-machine\n type: string\n params:\n example: -v\n type: string\n su:\n enum:\n - \"true\"\n - \"false\"\n example: \"false\"\n type: string\nrequired:\n- machine\ntype: object\n"), + Use: "edit-script script", + Short: "Edit script", + Long: cli.Markdown("Edit target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("application/json", args[1:], params.GetString("filename")) + body, err := cli.GetBody("", args[1:], params.GetString("filename")) if err != nil { logger.Fatalf("Unable to get body: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2RunScript(args[0], params, body) + _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7186,6 +7153,9 @@ func mistApiV2Register(subcommand bool) { root.AddCommand(cmd) cmd.Flags().StringP("filename", "f", "", "Filename") + cmd.Flags().String("name", "", "New script name") + cmd.Flags().String("description", "", "New script description") + cli.SetCustomFlags(cmd) if cmd.Flags().HasFlags() { @@ -7200,19 +7170,50 @@ func mistApiV2Register(subcommand bool) { var examples string cmd := &cobra.Command{ - Use: "edit-script script", - Short: "Edit script", - Long: cli.Markdown("Edit target script"), + Use: "delete-script script", + Short: "Delete script", + Long: cli.Markdown("Delete target script"), Example: examples, Group: "scripts", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - body, err := cli.GetBody("", args[1:], params.GetString("filename")) + + _, decoded, outputOptions, err := MistApiV2DeleteScript(args[0], params) if err != nil { - logger.Fatalf("Unable to get body: %s", err.Error()) + logger.Fatalf("Error calling operation: %s", err.Error()) } - _, decoded, outputOptions, err := MistApiV2EditScript(args[0], params, body) + if err := cli.Formatter.Format(decoded, outputOptions); err != nil { + logger.Fatalf("Formatting failed: %s", err.Error()) + } + + }, + } + root.AddCommand(cmd) + + cli.SetCustomFlags(cmd) + + if cmd.Flags().HasFlags() { + params.BindPFlags(cmd.Flags()) + } + + }() + + func() { + params := viper.New() + + var examples string + + cmd := &cobra.Command{ + Use: "get-script script", + Short: "Get script", + Long: cli.Markdown("Get details about target script"), + Example: examples, + Group: "scripts", + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + + _, decoded, outputOptions, err := MistApiV2GetScript(args[0], params) if err != nil { logger.Fatalf("Error calling operation: %s", err.Error()) } @@ -7224,10 +7225,9 @@ func mistApiV2Register(subcommand bool) { }, } root.AddCommand(cmd) - cmd.Flags().StringP("filename", "f", "", "Filename") - cmd.Flags().String("name", "", "New script name") - cmd.Flags().String("description", "", "New script description") + cmd.Flags().String("only", "", "Only return these fields") + cmd.Flags().String("deref", "", "Dereference foreign keys") cli.SetCustomFlags(cmd)