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
@@ -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 }
|
||||
)
|
||||
Reference in new issue
Block a user