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 {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package base
|
||||
|
||||
import "github.com/hashicorp/boundary/api/targets"
|
||||
|
||||
// getOpts - iterate the inbound Options and return a struct.
|
||||
func getOpts(opt ...Option) Options {
|
||||
opts := getDefaultOptions()
|
||||
@@ -25,6 +27,8 @@ type Options struct {
|
||||
withContainerImage string
|
||||
withDialect string
|
||||
withAttributeFieldPrefix string
|
||||
withStatusCode int
|
||||
withDecodedCredentials []*targets.SessionCredential
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
@@ -120,3 +124,17 @@ func WithAttributeFieldPrefix(p string) Option {
|
||||
o.withAttributeFieldPrefix = p
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCode allows passing status codes to functions
|
||||
func WithStatusCode(statusCode int) Option {
|
||||
return func(o *Options) {
|
||||
o.withStatusCode = statusCode
|
||||
}
|
||||
}
|
||||
|
||||
// WithDecodedCredentials allows passing decoded credentials
|
||||
func WithDecodedCredentials(creds []*targets.SessionCredential) Option {
|
||||
return func(o *Options) {
|
||||
o.withDecodedCredentials = creds
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user