refactor(api module): enforce typed definitions (#2238)
This commit is contained in:
1 parent
d6c1402223
commit
c2bfcc0664
79 files changed
+906
-551
No files matched your search
@@ -277,8 +277,7 @@ func (c *Command) PrintCliError(err error) {
|
||||
}
|
||||
|
||||
// PrintJsonItem prints the given item to the UI in JSON format
|
||||
func (c *Command) PrintJsonItem(result api.GenericResult, opt ...Option) bool {
|
||||
resp := result.GetResponse()
|
||||
func (c *Command) PrintJsonItem(resp *api.Response, opt ...Option) bool {
|
||||
if resp == nil {
|
||||
c.PrintCliError(errors.New("Error formatting as JSON: no response given to item formatter"))
|
||||
return false
|
||||
@@ -309,8 +308,7 @@ func (c *Command) PrintJson(input json.RawMessage, opt ...Option) bool {
|
||||
}
|
||||
|
||||
// PrintJsonItems prints the given items to the UI in JSON format
|
||||
func (c *Command) PrintJsonItems(result api.GenericListResult) bool {
|
||||
resp := result.GetResponse()
|
||||
func (c *Command) PrintJsonItems(resp *api.Response) bool {
|
||||
if resp == nil {
|
||||
c.PrintCliError(errors.New("Error formatting as JSON: no response given to items formatter"))
|
||||
return false
|
||||
|
||||
@@ -217,24 +217,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *accounts.Account
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*accounts.Account
|
||||
|
||||
var readResult *accounts.AccountReadResult
|
||||
|
||||
var deleteResult *accounts.AccountDeleteResult
|
||||
|
||||
var listResult *accounts.AccountListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = accountsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = accountsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = accountsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = accountsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = accountsClient.List(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, accountsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, accountsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -261,7 +273,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -274,13 +286,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*accounts.Account)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -289,10 +300,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -307,8 +318,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]accounts.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *accounts.Account, inItems []*accounts.Account, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (*api.Response, *accounts.Account, []*accounts.Account, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -174,14 +174,16 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]accounts.O
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, accountClient *accounts.Client, version uint32, opts []accounts.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *accounts.Account, origItems []*accounts.Account, origError error, accountClient *accounts.Client, version uint32, opts []accounts.Option) (*api.Response, *accounts.Account, []*accounts.Account, error) {
|
||||
switch c.Func {
|
||||
case "set-password":
|
||||
return accountClient.SetPassword(c.Context, c.FlagId, c.flagPassword, version, opts...)
|
||||
result, err := accountClient.SetPassword(c.Context, c.FlagId, c.flagPassword, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "change-password":
|
||||
return accountClient.ChangePassword(c.Context, c.FlagId, c.flagCurrentPassword, c.flagNewPassword, version, opts...)
|
||||
result, err := accountClient.ChangePassword(c.Context, c.FlagId, c.flagCurrentPassword, c.flagNewPassword, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*accounts.Account) string {
|
||||
@@ -237,8 +239,7 @@ func (c *Command) printListTable(items []*accounts.Account) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*accounts.Account)
|
||||
func printItemTable(item *accounts.Account, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -193,19 +193,28 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *accounts.Account
|
||||
|
||||
var createResult *accounts.AccountCreateResult
|
||||
|
||||
var updateResult *accounts.AccountUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = accountsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
createResult, err = accountsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = accountsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = accountsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraOidcActions(c, result, err, accountsClient, version, opts)
|
||||
resp, item, err = executeExtraOidcActions(c, resp, item, err, accountsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -233,10 +242,10 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -249,8 +258,8 @@ var (
|
||||
extraOidcSynopsisFunc = func(*OidcCommand) string { return "" }
|
||||
extraOidcFlagsFunc = func(*OidcCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraOidcFlagsHandlingFunc = func(*OidcCommand, *base.FlagSets, *[]accounts.Option) bool { return true }
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResult api.GenericResult, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResp *api.Response, inItem *accounts.Account, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (*api.Response, *accounts.Account, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomOidcActionOutput = func(*OidcCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -193,19 +193,28 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *accounts.Account
|
||||
|
||||
var createResult *accounts.AccountCreateResult
|
||||
|
||||
var updateResult *accounts.AccountUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = accountsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
createResult, err = accountsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = accountsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = accountsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraPasswordActions(c, result, err, accountsClient, version, opts)
|
||||
resp, item, err = executeExtraPasswordActions(c, resp, item, err, accountsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -233,10 +242,10 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -249,8 +258,8 @@ var (
|
||||
extraPasswordSynopsisFunc = func(*PasswordCommand) string { return "" }
|
||||
extraPasswordFlagsFunc = func(*PasswordCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraPasswordFlagsHandlingFunc = func(*PasswordCommand, *base.FlagSets, *[]accounts.Option) bool { return true }
|
||||
executeExtraPasswordActions = func(_ *PasswordCommand, inResult api.GenericResult, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraPasswordActions = func(_ *PasswordCommand, inResp *api.Response, inItem *accounts.Account, inErr error, _ *accounts.Client, _ uint32, _ []accounts.Option) (*api.Response, *accounts.Account, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomPasswordActionOutput = func(*PasswordCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -32,10 +32,7 @@ func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult
|
||||
}))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(&dummyGenericResponse{
|
||||
item: token,
|
||||
response: result.GetResponse(),
|
||||
}); !ok {
|
||||
if ok := c.PrintJsonItem(result.GetResponse()); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
return base.CommandSuccess
|
||||
|
||||
@@ -84,21 +84,6 @@ func (c *PasswordCommand) AutocompleteFlags() complete.Flags {
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
type dummyGenericResponse struct {
|
||||
item interface{}
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
var _ api.GenericResult = (*dummyGenericResponse)(nil)
|
||||
|
||||
func (d *dummyGenericResponse) GetItem() interface{} {
|
||||
return d.item
|
||||
}
|
||||
|
||||
func (d *dummyGenericResponse) GetResponse() *api.Response {
|
||||
return d.response
|
||||
}
|
||||
|
||||
func (c *PasswordCommand) Run(args []string) int {
|
||||
f := c.Flags()
|
||||
|
||||
|
||||
@@ -184,24 +184,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *authmethods.AuthMethod
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*authmethods.AuthMethod
|
||||
|
||||
var readResult *authmethods.AuthMethodReadResult
|
||||
|
||||
var deleteResult *authmethods.AuthMethodDeleteResult
|
||||
|
||||
var listResult *authmethods.AuthMethodListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = authmethodsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = authmethodsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = authmethodsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = authmethodsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = authmethodsClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, authmethodsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, authmethodsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -228,7 +240,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -241,13 +253,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*authmethods.AuthMethod)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -256,10 +267,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -274,8 +285,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]authmethods.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *authmethods.AuthMethod, inItems []*authmethods.AuthMethod, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (*api.Response, *authmethods.AuthMethod, []*authmethods.AuthMethod, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -133,8 +133,7 @@ func (c *Command) printListTable(items []*authmethods.AuthMethod) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*authmethods.AuthMethod)
|
||||
func printItemTable(item *authmethods.AuthMethod, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
@@ -157,8 +156,8 @@ func printItemTable(result api.GenericResult) string {
|
||||
if item.Description != "" {
|
||||
nonAttributeMap["Description"] = item.Description
|
||||
}
|
||||
if result.GetResponse() != nil && result.GetResponse().Map != nil {
|
||||
if result.GetResponse().Map[globals.IsPrimaryField] != nil {
|
||||
if resp != nil && resp.Map != nil {
|
||||
if resp.Map[globals.IsPrimaryField] != nil {
|
||||
nonAttributeMap["Is Primary For Scope"] = item.IsPrimary
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,19 +206,28 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *authmethods.AuthMethod
|
||||
|
||||
var createResult *authmethods.AuthMethodCreateResult
|
||||
|
||||
var updateResult *authmethods.AuthMethodUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = authmethodsClient.Create(c.Context, "oidc", c.FlagScopeId, opts...)
|
||||
createResult, err = authmethodsClient.Create(c.Context, "oidc", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = authmethodsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = authmethodsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraOidcActions(c, result, err, authmethodsClient, version, opts)
|
||||
resp, item, err = executeExtraOidcActions(c, resp, item, err, authmethodsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -246,10 +255,10 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -262,8 +271,8 @@ var (
|
||||
extraOidcSynopsisFunc = func(*OidcCommand) string { return "" }
|
||||
extraOidcFlagsFunc = func(*OidcCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraOidcFlagsHandlingFunc = func(*OidcCommand, *base.FlagSets, *[]authmethods.Option) bool { return true }
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResult api.GenericResult, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResp *api.Response, inItem *authmethods.AuthMethod, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (*api.Response, *authmethods.AuthMethod, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomOidcActionOutput = func(*OidcCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -284,13 +284,14 @@ func extraOidcFlagHandlingFuncImpl(c *OidcCommand, f *base.FlagSets, opts *[]aut
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraOidcActionsImpl(c *OidcCommand, origResult api.GenericResult, origError error, amClient *authmethods.Client, version uint32, opts []authmethods.Option) (api.GenericResult, error) {
|
||||
func executeExtraOidcActionsImpl(c *OidcCommand, origResp *api.Response, origItem *authmethods.AuthMethod, origError error, amClient *authmethods.Client, version uint32, opts []authmethods.Option) (*api.Response, *authmethods.AuthMethod, error) {
|
||||
switch c.Func {
|
||||
case "change-state":
|
||||
if c.flagDisableDiscoveredConfigValidation {
|
||||
opts = append(opts, authmethods.WithOidcAuthMethodDisableDiscoveredConfigValidation(true))
|
||||
}
|
||||
return amClient.ChangeState(c.Context, c.FlagId, version, c.flagState, opts...)
|
||||
result, err := amClient.ChangeState(c.Context, c.FlagId, version, c.flagState, opts...)
|
||||
return result.GetResponse(), result.GetItem(), err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origError
|
||||
}
|
||||
@@ -198,19 +198,28 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *authmethods.AuthMethod
|
||||
|
||||
var createResult *authmethods.AuthMethodCreateResult
|
||||
|
||||
var updateResult *authmethods.AuthMethodUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = authmethodsClient.Create(c.Context, "password", c.FlagScopeId, opts...)
|
||||
createResult, err = authmethodsClient.Create(c.Context, "password", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = authmethodsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = authmethodsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraPasswordActions(c, result, err, authmethodsClient, version, opts)
|
||||
resp, item, err = executeExtraPasswordActions(c, resp, item, err, authmethodsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -238,10 +247,10 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -254,8 +263,8 @@ var (
|
||||
extraPasswordSynopsisFunc = func(*PasswordCommand) string { return "" }
|
||||
extraPasswordFlagsFunc = func(*PasswordCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraPasswordFlagsHandlingFunc = func(*PasswordCommand, *base.FlagSets, *[]authmethods.Option) bool { return true }
|
||||
executeExtraPasswordActions = func(_ *PasswordCommand, inResult api.GenericResult, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraPasswordActions = func(_ *PasswordCommand, inResp *api.Response, inItem *authmethods.AuthMethod, inErr error, _ *authmethods.Client, _ uint32, _ []authmethods.Option) (*api.Response, *authmethods.AuthMethod, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomPasswordActionOutput = func(*PasswordCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -179,24 +179,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *authtokens.AuthToken
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*authtokens.AuthToken
|
||||
|
||||
var readResult *authtokens.AuthTokenReadResult
|
||||
|
||||
var deleteResult *authtokens.AuthTokenDeleteResult
|
||||
|
||||
var listResult *authtokens.AuthTokenListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = authtokensClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = authtokensClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = authtokensClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = authtokensClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = authtokensClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, authtokensClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, authtokensClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -223,7 +235,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -236,13 +248,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*authtokens.AuthToken)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -251,10 +262,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -269,8 +280,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]authtokens.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *authtokens.Client, _ uint32, _ []authtokens.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *authtokens.AuthToken, inItems []*authtokens.AuthToken, inErr error, _ *authtokens.Client, _ uint32, _ []authtokens.Option) (*api.Response, *authtokens.AuthToken, []*authtokens.AuthToken, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -121,8 +121,7 @@ func (c *Command) printListTable(items []*authtokens.AuthToken) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*authtokens.AuthToken)
|
||||
func printItemTable(item *authtokens.AuthToken, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{
|
||||
"ID": item.Id,
|
||||
"Auth Method ID": item.AuthMethodId,
|
||||
|
||||
@@ -179,24 +179,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentiallibraries.CredentialLibrary
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*credentiallibraries.CredentialLibrary
|
||||
|
||||
var readResult *credentiallibraries.CredentialLibraryReadResult
|
||||
|
||||
var deleteResult *credentiallibraries.CredentialLibraryDeleteResult
|
||||
|
||||
var listResult *credentiallibraries.CredentialLibraryListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = credentiallibrariesClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = credentiallibrariesClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = credentiallibrariesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = credentiallibrariesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = credentiallibrariesClient.List(c.Context, c.FlagCredentialStoreId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, credentiallibrariesClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, credentiallibrariesClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -223,7 +235,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -236,13 +248,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*credentiallibraries.CredentialLibrary)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -251,10 +262,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -269,8 +280,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]credentiallibraries.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *credentiallibraries.Client, _ uint32, _ []credentiallibraries.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *credentiallibraries.CredentialLibrary, inItems []*credentiallibraries.CredentialLibrary, inErr error, _ *credentiallibraries.Client, _ uint32, _ []credentiallibraries.Option) (*api.Response, *credentiallibraries.CredentialLibrary, []*credentiallibraries.CredentialLibrary, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -113,8 +113,7 @@ func (c *Command) printListTable(items []*credentiallibraries.CredentialLibrary)
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*credentiallibraries.CredentialLibrary)
|
||||
func printItemTable(item *credentiallibraries.CredentialLibrary, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -193,19 +193,28 @@ func (c *VaultCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentiallibraries.CredentialLibrary
|
||||
|
||||
var createResult *credentiallibraries.CredentialLibraryCreateResult
|
||||
|
||||
var updateResult *credentiallibraries.CredentialLibraryUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentiallibrariesClient.Create(c.Context, c.FlagCredentialStoreId, opts...)
|
||||
createResult, err = credentiallibrariesClient.Create(c.Context, c.FlagCredentialStoreId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = credentiallibrariesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = credentiallibrariesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraVaultActions(c, result, err, credentiallibrariesClient, version, opts)
|
||||
resp, item, err = executeExtraVaultActions(c, resp, item, err, credentiallibrariesClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -235,10 +244,10 @@ func (c *VaultCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -251,8 +260,8 @@ var (
|
||||
extraVaultSynopsisFunc = func(*VaultCommand) string { return "" }
|
||||
extraVaultFlagsFunc = func(*VaultCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraVaultFlagsHandlingFunc = func(*VaultCommand, *base.FlagSets, *[]credentiallibraries.Option) bool { return true }
|
||||
executeExtraVaultActions = func(_ *VaultCommand, inResult api.GenericResult, inErr error, _ *credentiallibraries.Client, _ uint32, _ []credentiallibraries.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraVaultActions = func(_ *VaultCommand, inResp *api.Response, inItem *credentiallibraries.CredentialLibrary, inErr error, _ *credentiallibraries.Client, _ uint32, _ []credentiallibraries.Option) (*api.Response, *credentiallibraries.CredentialLibrary, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomVaultActionOutput = func(*VaultCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -179,24 +179,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentials.Credential
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*credentials.Credential
|
||||
|
||||
var readResult *credentials.CredentialReadResult
|
||||
|
||||
var deleteResult *credentials.CredentialDeleteResult
|
||||
|
||||
var listResult *credentials.CredentialListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = credentialsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = credentialsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = credentialsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = credentialsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = credentialsClient.List(c.Context, c.FlagCredentialStoreId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, credentialsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, credentialsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -223,7 +235,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -236,13 +248,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*credentials.Credential)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -251,10 +262,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -269,8 +280,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]credentials.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *credentials.Credential, inItems []*credentials.Credential, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (*api.Response, *credentials.Credential, []*credentials.Credential, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -114,8 +114,7 @@ func (c *Command) printListTable(items []*credentials.Credential) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*credentials.Credential)
|
||||
func printItemTable(item *credentials.Credential, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -193,19 +193,28 @@ func (c *SshPrivateKeyCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentials.Credential
|
||||
|
||||
var createResult *credentials.CredentialCreateResult
|
||||
|
||||
var updateResult *credentials.CredentialUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialsClient.Create(c.Context, "ssh_private_key", c.FlagCredentialStoreId, opts...)
|
||||
createResult, err = credentialsClient.Create(c.Context, "ssh_private_key", c.FlagCredentialStoreId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = credentialsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = credentialsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraSshPrivateKeyActions(c, result, err, credentialsClient, version, opts)
|
||||
resp, item, err = executeExtraSshPrivateKeyActions(c, resp, item, err, credentialsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -235,10 +244,10 @@ func (c *SshPrivateKeyCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -251,8 +260,8 @@ var (
|
||||
extraSshPrivateKeySynopsisFunc = func(*SshPrivateKeyCommand) string { return "" }
|
||||
extraSshPrivateKeyFlagsFunc = func(*SshPrivateKeyCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraSshPrivateKeyFlagsHandlingFunc = func(*SshPrivateKeyCommand, *base.FlagSets, *[]credentials.Option) bool { return true }
|
||||
executeExtraSshPrivateKeyActions = func(_ *SshPrivateKeyCommand, inResult api.GenericResult, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraSshPrivateKeyActions = func(_ *SshPrivateKeyCommand, inResp *api.Response, inItem *credentials.Credential, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (*api.Response, *credentials.Credential, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomSshPrivateKeyActionOutput = func(*SshPrivateKeyCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -193,19 +193,28 @@ func (c *UsernamePasswordCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentials.Credential
|
||||
|
||||
var createResult *credentials.CredentialCreateResult
|
||||
|
||||
var updateResult *credentials.CredentialUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialsClient.Create(c.Context, "username_password", c.FlagCredentialStoreId, opts...)
|
||||
createResult, err = credentialsClient.Create(c.Context, "username_password", c.FlagCredentialStoreId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = credentialsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = credentialsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraUsernamePasswordActions(c, result, err, credentialsClient, version, opts)
|
||||
resp, item, err = executeExtraUsernamePasswordActions(c, resp, item, err, credentialsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -235,10 +244,10 @@ func (c *UsernamePasswordCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -251,8 +260,8 @@ var (
|
||||
extraUsernamePasswordSynopsisFunc = func(*UsernamePasswordCommand) string { return "" }
|
||||
extraUsernamePasswordFlagsFunc = func(*UsernamePasswordCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraUsernamePasswordFlagsHandlingFunc = func(*UsernamePasswordCommand, *base.FlagSets, *[]credentials.Option) bool { return true }
|
||||
executeExtraUsernamePasswordActions = func(_ *UsernamePasswordCommand, inResult api.GenericResult, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraUsernamePasswordActions = func(_ *UsernamePasswordCommand, inResp *api.Response, inItem *credentials.Credential, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (*api.Response, *credentials.Credential, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomUsernamePasswordActionOutput = func(*UsernamePasswordCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -184,24 +184,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentialstores.CredentialStore
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*credentialstores.CredentialStore
|
||||
|
||||
var readResult *credentialstores.CredentialStoreReadResult
|
||||
|
||||
var deleteResult *credentialstores.CredentialStoreDeleteResult
|
||||
|
||||
var listResult *credentialstores.CredentialStoreListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = credentialstoresClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = credentialstoresClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = credentialstoresClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = credentialstoresClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = credentialstoresClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, credentialstoresClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, credentialstoresClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -228,7 +240,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -241,13 +253,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*credentialstores.CredentialStore)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -256,10 +267,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -274,8 +285,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]credentialstores.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *credentialstores.CredentialStore, inItems []*credentialstores.CredentialStore, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (*api.Response, *credentialstores.CredentialStore, []*credentialstores.CredentialStore, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -122,8 +122,7 @@ func (c *Command) printListTable(items []*credentialstores.CredentialStore) stri
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*credentialstores.CredentialStore)
|
||||
func printItemTable(item *credentialstores.CredentialStore, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -196,19 +196,28 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentialstores.CredentialStore
|
||||
|
||||
var createResult *credentialstores.CredentialStoreCreateResult
|
||||
|
||||
var updateResult *credentialstores.CredentialStoreUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialstoresClient.Create(c.Context, "static", c.FlagScopeId, opts...)
|
||||
createResult, err = credentialstoresClient.Create(c.Context, "static", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = credentialstoresClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = credentialstoresClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraStaticActions(c, result, err, credentialstoresClient, version, opts)
|
||||
resp, item, err = executeExtraStaticActions(c, resp, item, err, credentialstoresClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -238,10 +247,10 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -254,8 +263,8 @@ var (
|
||||
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
||||
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraStaticFlagsHandlingFunc = func(*StaticCommand, *base.FlagSets, *[]credentialstores.Option) bool { return true }
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResp *api.Response, inItem *credentialstores.CredentialStore, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (*api.Response, *credentialstores.CredentialStore, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -198,19 +198,28 @@ func (c *VaultCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *credentialstores.CredentialStore
|
||||
|
||||
var createResult *credentialstores.CredentialStoreCreateResult
|
||||
|
||||
var updateResult *credentialstores.CredentialStoreUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialstoresClient.Create(c.Context, "vault", c.FlagScopeId, opts...)
|
||||
createResult, err = credentialstoresClient.Create(c.Context, "vault", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = credentialstoresClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = credentialstoresClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraVaultActions(c, result, err, credentialstoresClient, version, opts)
|
||||
resp, item, err = executeExtraVaultActions(c, resp, item, err, credentialstoresClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -240,10 +249,10 @@ func (c *VaultCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -256,8 +265,8 @@ var (
|
||||
extraVaultSynopsisFunc = func(*VaultCommand) string { return "" }
|
||||
extraVaultFlagsFunc = func(*VaultCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraVaultFlagsHandlingFunc = func(*VaultCommand, *base.FlagSets, *[]credentialstores.Option) bool { return true }
|
||||
executeExtraVaultActions = func(_ *VaultCommand, inResult api.GenericResult, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraVaultActions = func(_ *VaultCommand, inResp *api.Response, inItem *credentialstores.CredentialStore, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (*api.Response, *credentialstores.CredentialStore, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomVaultActionOutput = func(*VaultCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -128,16 +128,19 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]groups.Opt
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, groupClient *groups.Client, version uint32, opts []groups.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *groups.Group, origItems []*groups.Group, origError error, groupClient *groups.Client, version uint32, opts []groups.Option) (*api.Response, *groups.Group, []*groups.Group, error) {
|
||||
switch c.Func {
|
||||
case "add-members":
|
||||
return groupClient.AddMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
result, err := groupClient.AddMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-members":
|
||||
return groupClient.SetMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
result, err := groupClient.SetMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-members":
|
||||
return groupClient.RemoveMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
result, err := groupClient.RemoveMembers(c.Context, c.FlagId, version, c.flagMembers, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*groups.Group) string {
|
||||
@@ -193,8 +196,7 @@ func (c *Command) printListTable(items []*groups.Group) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*groups.Group)
|
||||
func printItemTable(item *groups.Group, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -248,30 +248,50 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *groups.Group
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*groups.Group
|
||||
|
||||
var createResult *groups.GroupCreateResult
|
||||
|
||||
var readResult *groups.GroupReadResult
|
||||
|
||||
var updateResult *groups.GroupUpdateResult
|
||||
|
||||
var deleteResult *groups.GroupDeleteResult
|
||||
|
||||
var listResult *groups.GroupListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = groupsClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
createResult, err = groupsClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "read":
|
||||
result, err = groupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = groupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = groupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = groupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = groupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = groupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = groupsClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, groupsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, groupsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -298,7 +318,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -311,13 +331,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*groups.Group)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -326,10 +345,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -344,8 +363,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]groups.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *groups.Client, _ uint32, _ []groups.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *groups.Group, inItems []*groups.Group, inErr error, _ *groups.Client, _ uint32, _ []groups.Option) (*api.Response, *groups.Group, []*groups.Group, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -119,8 +119,7 @@ func (c *Command) printListTable(items []*hostcatalogs.HostCatalog) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*hostcatalogs.HostCatalog)
|
||||
func printItemTable(item *hostcatalogs.HostCatalog, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -184,24 +184,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostcatalogs.HostCatalog
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*hostcatalogs.HostCatalog
|
||||
|
||||
var readResult *hostcatalogs.HostCatalogReadResult
|
||||
|
||||
var deleteResult *hostcatalogs.HostCatalogDeleteResult
|
||||
|
||||
var listResult *hostcatalogs.HostCatalogListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = hostcatalogsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = hostcatalogsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = hostcatalogsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = hostcatalogsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = hostcatalogsClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, hostcatalogsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, hostcatalogsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -228,7 +240,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -241,13 +253,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*hostcatalogs.HostCatalog)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -256,10 +267,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -274,8 +285,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]hostcatalogs.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *hostcatalogs.HostCatalog, inItems []*hostcatalogs.HostCatalog, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (*api.Response, *hostcatalogs.HostCatalog, []*hostcatalogs.HostCatalog, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -243,19 +243,28 @@ func (c *PluginCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostcatalogs.HostCatalog
|
||||
|
||||
var createResult *hostcatalogs.HostCatalogCreateResult
|
||||
|
||||
var updateResult *hostcatalogs.HostCatalogUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = hostcatalogsClient.Create(c.Context, "plugin", c.FlagScopeId, opts...)
|
||||
createResult, err = hostcatalogsClient.Create(c.Context, "plugin", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = hostcatalogsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = hostcatalogsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraPluginActions(c, result, err, hostcatalogsClient, version, opts)
|
||||
resp, item, err = executeExtraPluginActions(c, resp, item, err, hostcatalogsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -283,10 +292,10 @@ func (c *PluginCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -299,8 +308,8 @@ var (
|
||||
extraPluginSynopsisFunc = func(*PluginCommand) string { return "" }
|
||||
extraPluginFlagsFunc = func(*PluginCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraPluginFlagsHandlingFunc = func(*PluginCommand, *base.FlagSets, *[]hostcatalogs.Option) bool { return true }
|
||||
executeExtraPluginActions = func(_ *PluginCommand, inResult api.GenericResult, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraPluginActions = func(_ *PluginCommand, inResp *api.Response, inItem *hostcatalogs.HostCatalog, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (*api.Response, *hostcatalogs.HostCatalog, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomPluginActionOutput = func(*PluginCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -196,19 +196,28 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostcatalogs.HostCatalog
|
||||
|
||||
var createResult *hostcatalogs.HostCatalogCreateResult
|
||||
|
||||
var updateResult *hostcatalogs.HostCatalogUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = hostcatalogsClient.Create(c.Context, "static", c.FlagScopeId, opts...)
|
||||
createResult, err = hostcatalogsClient.Create(c.Context, "static", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = hostcatalogsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = hostcatalogsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraStaticActions(c, result, err, hostcatalogsClient, version, opts)
|
||||
resp, item, err = executeExtraStaticActions(c, resp, item, err, hostcatalogsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -236,10 +245,10 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -252,8 +261,8 @@ var (
|
||||
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
||||
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraStaticFlagsHandlingFunc = func(*StaticCommand, *base.FlagSets, *[]hostcatalogs.Option) bool { return true }
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResp *api.Response, inItem *hostcatalogs.HostCatalog, inErr error, _ *hostcatalogs.Client, _ uint32, _ []hostcatalogs.Option) (*api.Response, *hostcatalogs.HostCatalog, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -113,8 +113,7 @@ func (c *Command) printListTable(items []*hosts.Host) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*hosts.Host)
|
||||
func printItemTable(item *hosts.Host, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -195,24 +195,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hosts.Host
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*hosts.Host
|
||||
|
||||
var readResult *hosts.HostReadResult
|
||||
|
||||
var deleteResult *hosts.HostDeleteResult
|
||||
|
||||
var listResult *hosts.HostListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = hostsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = hostsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = hostsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = hostsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = hostsClient.List(c.Context, c.FlagHostCatalogId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, hostsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, hostsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -239,7 +251,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -252,13 +264,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*hosts.Host)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -267,10 +278,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -285,8 +296,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]hosts.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *hosts.Client, _ uint32, _ []hosts.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *hosts.Host, inItems []*hosts.Host, inErr error, _ *hosts.Client, _ uint32, _ []hosts.Option) (*api.Response, *hosts.Host, []*hosts.Host, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -193,19 +193,28 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hosts.Host
|
||||
|
||||
var createResult *hosts.HostCreateResult
|
||||
|
||||
var updateResult *hosts.HostUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = hostsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
createResult, err = hostsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = hostsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = hostsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraStaticActions(c, result, err, hostsClient, version, opts)
|
||||
resp, item, err = executeExtraStaticActions(c, resp, item, err, hostsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -233,10 +242,10 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -249,8 +258,8 @@ var (
|
||||
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
||||
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraStaticFlagsHandlingFunc = func(*StaticCommand, *base.FlagSets, *[]hosts.Option) bool { return true }
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *hosts.Client, _ uint32, _ []hosts.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResp *api.Response, inItem *hosts.Host, inErr error, _ *hosts.Client, _ uint32, _ []hosts.Option) (*api.Response, *hosts.Host, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -160,16 +160,19 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]hostsets.O
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, hostsetClient *hostsets.Client, version uint32, opts []hostsets.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *hostsets.HostSet, origItems []*hostsets.HostSet, origError error, hostsetClient *hostsets.Client, version uint32, opts []hostsets.Option) (*api.Response, *hostsets.HostSet, []*hostsets.HostSet, error) {
|
||||
switch c.Func {
|
||||
case "add-hosts":
|
||||
return hostsetClient.AddHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
result, err := hostsetClient.AddHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-hosts":
|
||||
return hostsetClient.RemoveHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
result, err := hostsetClient.RemoveHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-hosts":
|
||||
return hostsetClient.SetHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
result, err := hostsetClient.SetHosts(c.Context, c.FlagId, version, c.flagHosts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*hostsets.HostSet) string {
|
||||
@@ -231,8 +234,7 @@ func (c *Command) printListTable(items []*hostsets.HostSet) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*hostsets.HostSet)
|
||||
func printItemTable(item *hostsets.HostSet, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -225,24 +225,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostsets.HostSet
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*hostsets.HostSet
|
||||
|
||||
var readResult *hostsets.HostSetReadResult
|
||||
|
||||
var deleteResult *hostsets.HostSetDeleteResult
|
||||
|
||||
var listResult *hostsets.HostSetListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = hostsetsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = hostsetsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = hostsetsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = hostsetsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = hostsetsClient.List(c.Context, c.FlagHostCatalogId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, hostsetsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, hostsetsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -269,7 +281,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -282,13 +294,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*hostsets.HostSet)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -297,10 +308,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -315,8 +326,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]hostsets.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *hostsets.HostSet, inItems []*hostsets.HostSet, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (*api.Response, *hostsets.HostSet, []*hostsets.HostSet, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -211,19 +211,28 @@ func (c *PluginCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostsets.HostSet
|
||||
|
||||
var createResult *hostsets.HostSetCreateResult
|
||||
|
||||
var updateResult *hostsets.HostSetUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = hostsetsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
createResult, err = hostsetsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = hostsetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = hostsetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraPluginActions(c, result, err, hostsetsClient, version, opts)
|
||||
resp, item, err = executeExtraPluginActions(c, resp, item, err, hostsetsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -251,10 +260,10 @@ func (c *PluginCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -267,8 +276,8 @@ var (
|
||||
extraPluginSynopsisFunc = func(*PluginCommand) string { return "" }
|
||||
extraPluginFlagsFunc = func(*PluginCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraPluginFlagsHandlingFunc = func(*PluginCommand, *base.FlagSets, *[]hostsets.Option) bool { return true }
|
||||
executeExtraPluginActions = func(_ *PluginCommand, inResult api.GenericResult, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraPluginActions = func(_ *PluginCommand, inResp *api.Response, inItem *hostsets.HostSet, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (*api.Response, *hostsets.HostSet, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomPluginActionOutput = func(*PluginCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -191,19 +191,28 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *hostsets.HostSet
|
||||
|
||||
var createResult *hostsets.HostSetCreateResult
|
||||
|
||||
var updateResult *hostsets.HostSetUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = hostsetsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
createResult, err = hostsetsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = hostsetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = hostsetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraStaticActions(c, result, err, hostsetsClient, version, opts)
|
||||
resp, item, err = executeExtraStaticActions(c, resp, item, err, hostsetsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -231,10 +240,10 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -247,8 +256,8 @@ var (
|
||||
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
||||
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraStaticFlagsHandlingFunc = func(*StaticCommand, *base.FlagSets, *[]hostsets.Option) bool { return true }
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResp *api.Response, inItem *hostsets.HostSet, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (*api.Response, *hostsets.HostSet, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -62,8 +62,7 @@ func (c *Command) printListTable(items []*managedgroups.ManagedGroup) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*managedgroups.ManagedGroup)
|
||||
func printItemTable(item *managedgroups.ManagedGroup, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -195,24 +195,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *managedgroups.ManagedGroup
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*managedgroups.ManagedGroup
|
||||
|
||||
var readResult *managedgroups.ManagedGroupReadResult
|
||||
|
||||
var deleteResult *managedgroups.ManagedGroupDeleteResult
|
||||
|
||||
var listResult *managedgroups.ManagedGroupListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = managedgroupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = managedgroupsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = managedgroupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = managedgroupsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = managedgroupsClient.List(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, managedgroupsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, managedgroupsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -239,7 +251,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -252,13 +264,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*managedgroups.ManagedGroup)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -267,10 +278,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -285,8 +296,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]managedgroups.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *managedgroups.ManagedGroup, inItems []*managedgroups.ManagedGroup, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (*api.Response, *managedgroups.ManagedGroup, []*managedgroups.ManagedGroup, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -193,19 +193,28 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *managedgroups.ManagedGroup
|
||||
|
||||
var createResult *managedgroups.ManagedGroupCreateResult
|
||||
|
||||
var updateResult *managedgroups.ManagedGroupUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = managedgroupsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
createResult, err = managedgroupsClient.Create(c.Context, c.FlagAuthMethodId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = managedgroupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = managedgroupsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraOidcActions(c, result, err, managedgroupsClient, version, opts)
|
||||
resp, item, err = executeExtraOidcActions(c, resp, item, err, managedgroupsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -233,10 +242,10 @@ func (c *OidcCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -249,8 +258,8 @@ var (
|
||||
extraOidcSynopsisFunc = func(*OidcCommand) string { return "" }
|
||||
extraOidcFlagsFunc = func(*OidcCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraOidcFlagsHandlingFunc = func(*OidcCommand, *base.FlagSets, *[]managedgroups.Option) bool { return true }
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResult api.GenericResult, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraOidcActions = func(_ *OidcCommand, inResp *api.Response, inItem *managedgroups.ManagedGroup, inErr error, _ *managedgroups.Client, _ uint32, _ []managedgroups.Option) (*api.Response, *managedgroups.ManagedGroup, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomOidcActionOutput = func(*OidcCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -226,22 +226,28 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]roles.Opti
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, roleClient *roles.Client, version uint32, opts []roles.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *roles.Role, origItems []*roles.Role, origError error, roleClient *roles.Client, version uint32, opts []roles.Option) (*api.Response, *roles.Role, []*roles.Role, error) {
|
||||
switch c.Func {
|
||||
case "add-principals":
|
||||
return roleClient.AddPrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
result, err := roleClient.AddPrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-principals":
|
||||
return roleClient.SetPrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
result, err := roleClient.SetPrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-principals":
|
||||
return roleClient.RemovePrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
result, err := roleClient.RemovePrincipals(c.Context, c.FlagId, version, c.flagPrincipals, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "add-grants":
|
||||
return roleClient.AddGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
result, err := roleClient.AddGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-grants":
|
||||
return roleClient.SetGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
result, err := roleClient.SetGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-grants":
|
||||
return roleClient.RemoveGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
result, err := roleClient.RemoveGrants(c.Context, c.FlagId, version, c.flagGrants, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*roles.Role) string {
|
||||
@@ -298,8 +304,7 @@ func (c *Command) printListTable(items []*roles.Role) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*roles.Role)
|
||||
func printItemTable(item *roles.Role, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -272,30 +272,50 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *roles.Role
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*roles.Role
|
||||
|
||||
var createResult *roles.RoleCreateResult
|
||||
|
||||
var readResult *roles.RoleReadResult
|
||||
|
||||
var updateResult *roles.RoleUpdateResult
|
||||
|
||||
var deleteResult *roles.RoleDeleteResult
|
||||
|
||||
var listResult *roles.RoleListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = rolesClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
createResult, err = rolesClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "read":
|
||||
result, err = rolesClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = rolesClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = rolesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = rolesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = rolesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = rolesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = rolesClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, rolesClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, rolesClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -322,7 +342,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -335,13 +355,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*roles.Role)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -350,10 +369,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -368,8 +387,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]roles.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *roles.Client, _ uint32, _ []roles.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *roles.Role, inItems []*roles.Role, inErr error, _ *roles.Client, _ uint32, _ []roles.Option) (*api.Response, *roles.Role, []*roles.Role, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -128,8 +128,7 @@ func (c *Command) printListTable(items []*scopes.Scope) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*scopes.Scope)
|
||||
func printItemTable(item *scopes.Scope, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -224,30 +224,50 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *scopes.Scope
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*scopes.Scope
|
||||
|
||||
var createResult *scopes.ScopeCreateResult
|
||||
|
||||
var readResult *scopes.ScopeReadResult
|
||||
|
||||
var updateResult *scopes.ScopeUpdateResult
|
||||
|
||||
var deleteResult *scopes.ScopeDeleteResult
|
||||
|
||||
var listResult *scopes.ScopeListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = scopesClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
createResult, err = scopesClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "read":
|
||||
result, err = scopesClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = scopesClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = scopesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = scopesClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = scopesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = scopesClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = scopesClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, scopesClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, scopesClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -274,7 +294,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -287,13 +307,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*scopes.Scope)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -302,10 +321,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -320,8 +339,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]scopes.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *scopes.Client, _ uint32, _ []scopes.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *scopes.Scope, inItems []*scopes.Scope, inErr error, _ *scopes.Client, _ uint32, _ []scopes.Option) (*api.Response, *scopes.Scope, []*scopes.Scope, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -86,12 +86,13 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
return helpStr + c.Flags().Help()
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, sessionClient *sessions.Client, version uint32, opts []sessions.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *sessions.Session, origItems []*sessions.Session, origError error, sessionClient *sessions.Client, version uint32, opts []sessions.Option) (*api.Response, *sessions.Session, []*sessions.Session, error) {
|
||||
switch c.Func {
|
||||
case "cancel":
|
||||
return sessionClient.Cancel(c.Context, c.FlagId, version, opts...)
|
||||
result, err := sessionClient.Cancel(c.Context, c.FlagId, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*sessions.Session) string {
|
||||
@@ -162,8 +163,7 @@ func (c *Command) printListTable(items []*sessions.Session) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*sessions.Session)
|
||||
func printItemTable(item *sessions.Session, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -193,21 +193,30 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *sessions.Session
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*sessions.Session
|
||||
|
||||
var readResult *sessions.SessionReadResult
|
||||
|
||||
var listResult *sessions.SessionListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = sessionsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = sessionsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "list":
|
||||
listResult, err = sessionsClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, sessionsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, sessionsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -234,13 +243,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*sessions.Session)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -249,10 +257,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -267,8 +275,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]sessions.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *sessions.Client, _ uint32, _ []sessions.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *sessions.Session, inItems []*sessions.Session, inErr error, _ *sessions.Client, _ uint32, _ []sessions.Option) (*api.Response, *sessions.Session, []*sessions.Session, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -462,33 +462,42 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]targets.Op
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, targetClient *targets.Client, version uint32, opts []targets.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *targets.Target, origItems []*targets.Target, origError error, targetClient *targets.Client, version uint32, opts []targets.Option) (*api.Response, *targets.Target, []*targets.Target, error) {
|
||||
switch c.Func {
|
||||
case "add-host-sets":
|
||||
return targetClient.AddHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
result, err := targetClient.AddHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-host-sets":
|
||||
return targetClient.RemoveHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
result, err := targetClient.RemoveHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-host-sets":
|
||||
return targetClient.SetHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
result, err := targetClient.SetHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "add-host-sources":
|
||||
return targetClient.AddHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
result, err := targetClient.AddHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-host-sources":
|
||||
return targetClient.RemoveHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
result, err := targetClient.RemoveHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-host-sources":
|
||||
return targetClient.SetHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
result, err := targetClient.SetHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "add-credential-sources":
|
||||
return targetClient.AddCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
result, err := targetClient.AddCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-credential-sources":
|
||||
return targetClient.RemoveCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
result, err := targetClient.RemoveCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-credential-sources":
|
||||
return targetClient.SetCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
result, err := targetClient.SetCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "authorize-session":
|
||||
var err error
|
||||
c.plural = "a session against target"
|
||||
c.sar, err = targetClient.AuthorizeSession(c.Context, c.FlagId, opts...)
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*targets.Target) string {
|
||||
@@ -549,8 +558,7 @@ func (c *Command) printListTable(items []*targets.Target) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*targets.Target)
|
||||
func printItemTable(item *targets.Target, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
@@ -576,11 +584,11 @@ func printItemTable(result api.GenericResult) string {
|
||||
if item.WorkerFilter != "" {
|
||||
nonAttributeMap["Worker Filter"] = item.WorkerFilter
|
||||
}
|
||||
if result.GetResponse() != nil && result.GetResponse().Map != nil {
|
||||
if result.GetResponse().Map[globals.SessionConnectionLimitField] != nil {
|
||||
if resp != nil && resp.Map != nil {
|
||||
if resp.Map[globals.SessionConnectionLimitField] != nil {
|
||||
nonAttributeMap["Session Connection Limit"] = item.SessionConnectionLimit
|
||||
}
|
||||
if result.GetResponse().Map[globals.SessionMaxSecondsField] != nil {
|
||||
if resp.Map[globals.SessionMaxSecondsField] != nil {
|
||||
nonAttributeMap["Session Max Seconds"] = item.SessionMaxSeconds
|
||||
}
|
||||
}
|
||||
@@ -830,7 +838,7 @@ func printCustomActionOutputImpl(c *Command) (bool, error) {
|
||||
return true, nil
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(c.sar); !ok {
|
||||
if ok := c.PrintJsonItem(c.sar.GetResponse()); !ok {
|
||||
return false, fmt.Errorf("Error formatting as JSON")
|
||||
}
|
||||
return true, nil
|
||||
@@ -883,7 +891,5 @@ func exampleOutput() string {
|
||||
"default_port": 22,
|
||||
},
|
||||
}
|
||||
target := new(targets.TargetReadResult)
|
||||
target.Item = item
|
||||
return printItemTable(target)
|
||||
return printItemTable(item, nil)
|
||||
}
|
||||
@@ -279,24 +279,36 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *targets.Target
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*targets.Target
|
||||
|
||||
var readResult *targets.TargetReadResult
|
||||
|
||||
var deleteResult *targets.TargetDeleteResult
|
||||
|
||||
var listResult *targets.TargetListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = targetsClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = targetsClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = targetsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = targetsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = targetsClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, targetsClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, targetsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -323,7 +335,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -336,13 +348,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*targets.Target)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -351,10 +362,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -369,8 +380,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]targets.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *targets.Client, _ uint32, _ []targets.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *targets.Target, inItems []*targets.Target, inErr error, _ *targets.Client, _ uint32, _ []targets.Option) (*api.Response, *targets.Target, []*targets.Target, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -198,19 +198,28 @@ func (c *TcpCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *targets.Target
|
||||
|
||||
var createResult *targets.TargetCreateResult
|
||||
|
||||
var updateResult *targets.TargetUpdateResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = targetsClient.Create(c.Context, "tcp", c.FlagScopeId, opts...)
|
||||
createResult, err = targetsClient.Create(c.Context, "tcp", c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = targetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = targetsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraTcpActions(c, result, err, targetsClient, version, opts)
|
||||
resp, item, err = executeExtraTcpActions(c, resp, item, err, targetsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -238,10 +247,10 @@ func (c *TcpCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -254,8 +263,8 @@ var (
|
||||
extraTcpSynopsisFunc = func(*TcpCommand) string { return "" }
|
||||
extraTcpFlagsFunc = func(*TcpCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraTcpFlagsHandlingFunc = func(*TcpCommand, *base.FlagSets, *[]targets.Option) bool { return true }
|
||||
executeExtraTcpActions = func(_ *TcpCommand, inResult api.GenericResult, inErr error, _ *targets.Client, _ uint32, _ []targets.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraTcpActions = func(_ *TcpCommand, inResp *api.Response, inItem *targets.Target, inErr error, _ *targets.Client, _ uint32, _ []targets.Option) (*api.Response, *targets.Target, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomTcpActionOutput = func(*TcpCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -127,16 +127,19 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]users.Opti
|
||||
return true
|
||||
}
|
||||
|
||||
func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError error, userClient *users.Client, version uint32, opts []users.Option) (api.GenericResult, error) {
|
||||
func executeExtraActionsImpl(c *Command, origResp *api.Response, origItem *users.User, origItems []*users.User, origError error, userClient *users.Client, version uint32, opts []users.Option) (*api.Response, *users.User, []*users.User, error) {
|
||||
switch c.Func {
|
||||
case "add-accounts":
|
||||
return userClient.AddAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
result, err := userClient.AddAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "set-accounts":
|
||||
return userClient.SetAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
result, err := userClient.SetAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
case "remove-accounts":
|
||||
return userClient.RemoveAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
result, err := userClient.RemoveAccounts(c.Context, c.FlagId, version, c.flagAccounts, opts...)
|
||||
return result.GetResponse(), result.GetItem(), nil, err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origItems, origError
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*users.User) string {
|
||||
@@ -215,8 +218,7 @@ func (c *Command) printListTable(items []*users.User) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*users.User)
|
||||
func printItemTable(item *users.User, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
|
||||
@@ -248,30 +248,50 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *users.User
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*users.User
|
||||
|
||||
var createResult *users.UserCreateResult
|
||||
|
||||
var readResult *users.UserReadResult
|
||||
|
||||
var updateResult *users.UserUpdateResult
|
||||
|
||||
var deleteResult *users.UserDeleteResult
|
||||
|
||||
var listResult *users.UserListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = usersClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
createResult, err = usersClient.Create(c.Context, c.FlagScopeId, opts...)
|
||||
resp = createResult.GetResponse()
|
||||
item = createResult.GetItem()
|
||||
|
||||
case "read":
|
||||
result, err = usersClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = usersClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = usersClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = usersClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = usersClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = usersClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = usersClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, usersClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, usersClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -298,7 +318,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -311,13 +331,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*users.User)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -326,10 +345,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -344,8 +363,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]users.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *users.Client, _ uint32, _ []users.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *users.User, inItems []*users.User, inErr error, _ *users.Client, _ uint32, _ []users.Option) (*api.Response, *users.User, []*users.User, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -101,8 +101,7 @@ func (c *Command) printListTable(items []*workers.Worker) string {
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*workers.Worker)
|
||||
func printItemTable(item *workers.Worker, resp *api.Response) string {
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
@@ -132,7 +131,7 @@ func printItemTable(result api.GenericResult) string {
|
||||
nonAttributeMap["Last Status Time"] = item.LastStatusTime
|
||||
}
|
||||
|
||||
resultMap := result.GetResponse().Map
|
||||
resultMap := resp.Map
|
||||
if count, ok := resultMap[globals.ActiveConnectionCountField]; ok {
|
||||
nonAttributeMap["Active Connection Count"] = count
|
||||
}
|
||||
|
||||
@@ -54,10 +54,11 @@ func extraWorkerLedFlagsFuncImpl(c *WorkerLedCommand, set *base.FlagSets, f *bas
|
||||
}
|
||||
}
|
||||
|
||||
func executeExtraWorkerLedActionsImpl(c *WorkerLedCommand, origResult api.GenericResult, origError error, workerClient *workers.Client, version uint32, opts []workers.Option) (api.GenericResult, error) {
|
||||
func executeExtraWorkerLedActionsImpl(c *WorkerLedCommand, origResp *api.Response, origItem *workers.Worker, origError error, workerClient *workers.Client, version uint32, opts []workers.Option) (*api.Response, *workers.Worker, error) {
|
||||
switch c.Func {
|
||||
case "create":
|
||||
return workerClient.CreateWorkerLed(c.Context, c.flagWorkerGeneratedAuthToken, c.FlagScopeId, opts...)
|
||||
result, err := workerClient.CreateWorkerLed(c.Context, c.flagWorkerGeneratedAuthToken, c.FlagScopeId, opts...)
|
||||
return result.GetResponse(), result.GetItem(), err
|
||||
}
|
||||
return origResult, origError
|
||||
return origResp, origItem, origError
|
||||
}
|
||||
@@ -187,13 +187,14 @@ func (c *WorkerLedCommand) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *workers.Worker
|
||||
|
||||
switch c.Func {
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraWorkerLedActions(c, result, err, workersClient, version, opts)
|
||||
resp, item, err = executeExtraWorkerLedActions(c, resp, item, err, workersClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -221,10 +222,10 @@ func (c *WorkerLedCommand) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -237,8 +238,8 @@ var (
|
||||
extraWorkerLedSynopsisFunc = func(*WorkerLedCommand) string { return "" }
|
||||
extraWorkerLedFlagsFunc = func(*WorkerLedCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraWorkerLedFlagsHandlingFunc = func(*WorkerLedCommand, *base.FlagSets, *[]workers.Option) bool { return true }
|
||||
executeExtraWorkerLedActions = func(_ *WorkerLedCommand, inResult api.GenericResult, inErr error, _ *workers.Client, _ uint32, _ []workers.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraWorkerLedActions = func(_ *WorkerLedCommand, inResp *api.Response, inItem *workers.Worker, inErr error, _ *workers.Client, _ uint32, _ []workers.Option) (*api.Response, *workers.Worker, error) {
|
||||
return inResp, inItem, inErr
|
||||
}
|
||||
printCustomWorkerLedActionOutput = func(*WorkerLedCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -214,27 +214,43 @@ func (c *Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *workers.Worker
|
||||
|
||||
var listResult api.GenericListResult
|
||||
var items []*workers.Worker
|
||||
|
||||
var readResult *workers.WorkerReadResult
|
||||
|
||||
var updateResult *workers.WorkerUpdateResult
|
||||
|
||||
var deleteResult *workers.WorkerDeleteResult
|
||||
|
||||
var listResult *workers.WorkerListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = workersClient.Read(c.Context, c.FlagId, opts...)
|
||||
readResult, err = workersClient.Read(c.Context, c.FlagId, opts...)
|
||||
resp = readResult.GetResponse()
|
||||
item = readResult.GetItem()
|
||||
|
||||
case "update":
|
||||
result, err = workersClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
updateResult, err = workersClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = updateResult.GetResponse()
|
||||
item = updateResult.GetItem()
|
||||
|
||||
case "delete":
|
||||
result, err = workersClient.Delete(c.Context, c.FlagId, opts...)
|
||||
deleteResult, err = workersClient.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = deleteResult.GetResponse()
|
||||
|
||||
case "list":
|
||||
listResult, err = workersClient.List(c.Context, c.FlagScopeId, opts...)
|
||||
resp = listResult.GetResponse()
|
||||
items = listResult.GetItems()
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, workersClient, version, opts)
|
||||
resp, item, items, err = executeExtraActions(c, resp, item, items, err, workersClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -261,7 +277,7 @@ func (c *Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -274,13 +290,12 @@ func (c *Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*workers.Worker)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -289,10 +304,10 @@ func (c *Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -307,8 +322,8 @@ var (
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]workers.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *workers.Client, _ uint32, _ []workers.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtraActions = func(_ *Command, inResp *api.Response, inItem *workers.Worker, inItems []*workers.Worker, inErr error, _ *workers.Client, _ uint32, _ []workers.Option) (*api.Response, *workers.Worker, []*workers.Worker, error) {
|
||||
return inResp, inItem, inItems, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -399,9 +399,15 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
var resp *api.Response
|
||||
var item *{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}
|
||||
{{ if hasAction .StdActions "list" }}
|
||||
var listResult api.GenericListResult
|
||||
var items []*{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}
|
||||
{{ end }}
|
||||
{{ range $i, $action := $input.StdActions }}
|
||||
{{ if ( not ( hasAction $input.SkipClientCallActions $action) ) }}
|
||||
var {{ $action }}Result *{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}{{ camelCase $action }}Result
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
switch c.Func {
|
||||
@@ -409,29 +415,38 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
{{ if eq $action "create" }}
|
||||
{{ if ( not ( hasAction $input.SkipClientCallActions "create") ) }}
|
||||
case "create":
|
||||
result, err = {{ $input.Pkg }}Client.Create(c.Context, {{ if (and $input.SubActionPrefix $input.NeedsSubtypeInCreate) }}"{{ $input.SubActionPrefix }}",{{ end }} c.Flag{{ $input.Container }}Id, opts...)
|
||||
{{ $action }}Result, err = {{ $input.Pkg }}Client.Create(c.Context, {{ if (and $input.SubActionPrefix $input.NeedsSubtypeInCreate) }}"{{ $input.SubActionPrefix }}",{{ end }} c.Flag{{ $input.Container }}Id, opts...)
|
||||
resp = {{ $action }}Result.GetResponse()
|
||||
item = {{ $action }}Result.GetItem()
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if eq $action "read" }}
|
||||
case "read":
|
||||
result, err = {{ $input.Pkg }}Client.Read(c.Context, c.FlagId, opts...)
|
||||
{{ $action }}Result, err = {{ $input.Pkg }}Client.Read(c.Context, c.FlagId, opts...)
|
||||
resp = {{ $action }}Result.GetResponse()
|
||||
item = {{ $action }}Result.GetItem()
|
||||
{{ end }}
|
||||
{{ if eq $action "update" }}
|
||||
case "update":
|
||||
result, err = {{ $input.Pkg }}Client.Update(c.Context, c.FlagId, version, opts...)
|
||||
{{ $action }}Result, err = {{ $input.Pkg }}Client.Update(c.Context, c.FlagId, version, opts...)
|
||||
resp = {{ $action }}Result.GetResponse()
|
||||
item = {{ $action }}Result.GetItem()
|
||||
{{ end }}
|
||||
{{ if eq $action "delete" }}
|
||||
case "delete":
|
||||
result, err = {{ $input.Pkg }}Client.Delete(c.Context, c.FlagId, opts...)
|
||||
{{ $action }}Result, err = {{ $input.Pkg }}Client.Delete(c.Context, c.FlagId, opts...)
|
||||
resp = {{ $action }}Result.GetResponse()
|
||||
{{ end }}
|
||||
{{ if eq $action "list" }}
|
||||
case "list":
|
||||
listResult, err = {{ $input.Pkg}}Client.List(c.Context, c.Flag{{ $input.Container }}Id, opts...)
|
||||
{{ $action }}Result, err = {{ $input.Pkg}}Client.List(c.Context, c.Flag{{ $input.Container }}Id, opts...)
|
||||
resp = {{ $action }}Result.GetResponse()
|
||||
items = {{ $action }}Result.GetItems()
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
result, err = executeExtra{{ camelCase .SubActionPrefix }}Actions(c, result, err, {{ .Pkg }}Client, version, opts)
|
||||
resp, item, {{ if hasAction .StdActions "list" }}items, {{ end }}err = executeExtra{{ camelCase .SubActionPrefix }}Actions(c, resp, item, {{ if hasAction .StdActions "list" }}items, {{ end }}err, {{ .Pkg }}Client, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
@@ -461,7 +476,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
@@ -475,13 +490,12 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
if ok := c.PrintJsonItems(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*{{ $input.Pkg }}.{{ camelCase $input.ResourceType }})
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
c.UI.Output(c.printListTable(items))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
@@ -491,10 +505,10 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
c.UI.Output(printItemTable(item, resp))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
if ok := c.PrintJsonItem(resp); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
@@ -510,8 +524,8 @@ var (
|
||||
extra{{ camelCase .SubActionPrefix }}SynopsisFunc = func(*{{ camelCase .SubActionPrefix }}Command) string { return "" }
|
||||
extra{{ camelCase .SubActionPrefix }}FlagsFunc = func(*{{ camelCase .SubActionPrefix }}Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extra{{ camelCase .SubActionPrefix }}FlagsHandlingFunc = func(*{{ camelCase .SubActionPrefix }}Command, *base.FlagSets, *[]{{ .Pkg }}.Option) bool { return true }
|
||||
executeExtra{{ camelCase .SubActionPrefix }}Actions = func(_ *{{ camelCase .SubActionPrefix }}Command, inResult api.GenericResult, inErr error, _ *{{ .Pkg }}.Client, _ uint32, _ []{{ .Pkg }}.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
executeExtra{{ camelCase .SubActionPrefix }}Actions = func(_ *{{ camelCase .SubActionPrefix }}Command, inResp *api.Response, inItem *{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}, {{ if hasAction .StdActions "list" }}inItems []*{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}, {{ end }}inErr error, _ *{{ .Pkg }}.Client, _ uint32, _ []{{ .Pkg }}.Option) (*api.Response, *{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}, {{ if hasAction .StdActions "list" }}[]*{{ $input.Pkg }}.{{ camelCase $input.ResourceType }}, {{ end }}error) {
|
||||
return inResp, inItem, {{ if hasAction .StdActions "list" }}inItems, {{ end }}inErr
|
||||
}
|
||||
printCustom{{ camelCase .SubActionPrefix }}ActionOutput = func(*{{ camelCase .SubActionPrefix }}Command) (bool, error) { return false, nil }
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user