Update target credential library service, API, SDK, CLI (#1343)
This commit is contained in:
1 parent
83c65d0d4b
commit
86c9a90554
27 files changed
+1474
-1127
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/scopes"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/mitchellh/go-wordwrap"
|
||||
"github.com/pkg/errors"
|
||||
@@ -241,18 +242,29 @@ func (c *Command) PrintCliError(err error) {
|
||||
}
|
||||
|
||||
// PrintJsonItem prints the given item to the UI in JSON format
|
||||
func (c *Command) PrintJsonItem(result api.GenericResult) bool {
|
||||
func (c *Command) PrintJsonItem(result api.GenericResult, opt ...Option) bool {
|
||||
resp := result.GetResponse()
|
||||
if resp == nil {
|
||||
c.PrintCliError(errors.New("Error formatting as JSON: no response given to item formatter"))
|
||||
return false
|
||||
}
|
||||
if r := resp.HttpResponse(); r != nil {
|
||||
opt = append(opt, WithStatusCode(r.StatusCode))
|
||||
}
|
||||
return c.PrintJson(resp.Body.Bytes(), opt...)
|
||||
}
|
||||
|
||||
// PrintJson prints the given raw JSON in our common format
|
||||
func (c *Command) PrintJson(input json.RawMessage, opt ...Option) bool {
|
||||
opts := getOpts(opt...)
|
||||
output := struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
Item json.RawMessage `json:"item,omitempty"`
|
||||
StatusCode int `json:"status_code,omitempty"`
|
||||
DecodedCredentials []*targets.SessionCredential `json:"decoded_credentials,omitempty"`
|
||||
Item json.RawMessage `json:"item,omitempty"`
|
||||
}{
|
||||
StatusCode: resp.HttpResponse().StatusCode,
|
||||
Item: resp.Body.Bytes(),
|
||||
StatusCode: opts.withStatusCode,
|
||||
DecodedCredentials: opts.withDecodedCredentials,
|
||||
Item: input,
|
||||
}
|
||||
b, err := JsonFormatter{}.Format(output)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user