From 02fabe21c541ec0f53bd530cb80e76e2a2d79bc0 Mon Sep 17 00:00:00 2001 From: Jeff Malnick Date: Wed, 24 Feb 2021 11:02:47 -0800 Subject: [PATCH 1/6] docs: add brew install instructions (#951) --- website/content/docs/api-clients/desktop.mdx | 2 +- website/content/docs/getting-started/index.mdx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/website/content/docs/api-clients/desktop.mdx b/website/content/docs/api-clients/desktop.mdx index caa38375c2..0a99ad59c2 100644 --- a/website/content/docs/api-clients/desktop.mdx +++ b/website/content/docs/api-clients/desktop.mdx @@ -26,7 +26,7 @@ $ boundary dev ### Install Boundary Desktop -1. Download the latest .dmg installer from our [releases page](https://releases.hashicorp.com/boundary-desktop) +1. Download the latest .dmg installer from our [releases page](https://releases.hashicorp.com/boundary-desktop). Alternatively, if you're a homebrew user, you can run `brew install hashicorp-boundary-desktop` 1. Double-click the downloaded .dmg to run the installer 1. Drag and drop Boundary into the applications folder ![](/img/boundary-desktop-drag-to-install.png) diff --git a/website/content/docs/getting-started/index.mdx b/website/content/docs/getting-started/index.mdx index a69d9a0415..00c102a875 100644 --- a/website/content/docs/getting-started/index.mdx +++ b/website/content/docs/getting-started/index.mdx @@ -14,8 +14,10 @@ Before getting started with Boundary, it's important to understand a few key con The examples in Getting Started all revolve around running in `dev mode`. There are a few requirements for running dev mode: 1. [Docker](https://docs.docker.com/get-docker/) is installed -2. A route to download the [Postgres Docker image](https://hub.docker.com/_/postgres) is available or a local image cache is available -3. A [Boundary binary](https://www.boundaryproject.io/downloads) in your `$PATH` +1. A route to download the [Postgres Docker image](https://hub.docker.com/_/postgres) is available or a local image cache is available +1. A [Boundary binary](https://www.boundaryproject.io/downloads) in your `$PATH` +1. Optionally, an [installation of Boundary Desktop](/docs/api-clients/desktop#install-boundary-desktop) if you want to use the +desktop examples ## What is Dev Mode? From 3ab8bb03de4d039fe7e3dd63d9480fae0542d590 Mon Sep 17 00:00:00 2001 From: Sam Salisbury Date: Wed, 24 Feb 2021 22:45:33 +0000 Subject: [PATCH 2/6] Upgrading packagespec to v0.2.1 (#941) Co-authored-by: Michele --- packages-oss.lock/pkgs.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages-oss.lock/pkgs.yml b/packages-oss.lock/pkgs.yml index 375af8dda9..713c3e1c89 100644 --- a/packages-oss.lock/pkgs.yml +++ b/packages-oss.lock/pkgs.yml @@ -2,7 +2,7 @@ # WARNING: Do not EDIT or MERGE this file, it is generated by packagespec. # *** lockid: 6f2c5f02a174ad0f -packagespec-version: 0.2.0 +packagespec-version: 0.2.1 cache-version: 10 packages: - packagespecid: d388953fd9afcb2e22ca07a7d1d1203400dc73fa @@ -665,7 +665,7 @@ layers: sourceexclude: "" archivefile: .buildcache/archives/00-base-5d6560da565d7aaf001590c9ee19f099afda2fc9.tar.gz dockerfile: | - # syntax=hashicorp.jfrog.io/docker/docker/dockerfile:1.1.7-experimental + # syntax=docker.mirror.hashicorp.services/docker/dockerfile:1.1.7-experimental FROM hashicorp.jfrog.io/docker/golang@sha256:cbd6b4a560adbd00e3fe1eb1a6191a85e82839a69dcb757d57aa5be311f09cfe COPY . ./ ENV \ @@ -706,7 +706,7 @@ layers: sourceexclude: "" archivefile: .buildcache/archives/01-ui-ee02eda076af5c8427789646d2c258cfa8a6e013.tar.gz dockerfile: | - # syntax=hashicorp.jfrog.io/docker/docker/dockerfile:1.1.7-experimental + # syntax=docker.mirror.hashicorp.services/docker/dockerfile:1.1.7-experimental ARG BASE_IMAGE FROM $BASE_IMAGE COPY . ./ @@ -752,7 +752,7 @@ layers: sourceexclude: "" archivefile: .buildcache/archives/02-go-modules-2560d6fc1e63067e058686961997fd8ee0bfa8ad.tar.gz dockerfile: | - # syntax=hashicorp.jfrog.io/docker/docker/dockerfile:1.1.7-experimental + # syntax=docker.mirror.hashicorp.services/docker/dockerfile:1.1.7-experimental ARG BASE_IMAGE FROM $BASE_IMAGE COPY . ./ @@ -788,7 +788,7 @@ layers: sourceexclude: "" archivefile: .buildcache/archives/03-copy-source-30c9ff65608c26f2b30c4133dc36d5c976e94d2d.tar.gz dockerfile: | - # syntax=hashicorp.jfrog.io/docker/docker/dockerfile:1.1.7-experimental + # syntax=docker.mirror.hashicorp.services/docker/dockerfile:1.1.7-experimental ARG BASE_IMAGE FROM $BASE_IMAGE COPY . ./ From ea237372583e343f5865a4bde71bee1788aba40e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 25 Feb 2021 12:39:51 -0500 Subject: [PATCH 3/6] Port over API bits from #962 (#965) --- api/accounts/account.gen.go | 37 +++++----------------------- api/apierror.go | 7 +++++- api/authmethods/authmethods.gen.go | 37 +++++----------------------- api/authtokens/authtokens.gen.go | 37 +++++----------------------- api/error.gen.go | 14 ----------- api/go.sum | 9 +++++++ api/groups/group.gen.go | 37 +++++----------------------- api/hostcatalogs/host_catalog.gen.go | 37 +++++----------------------- api/hosts/host.gen.go | 37 +++++----------------------- api/hostsets/host_set.gen.go | 37 +++++----------------------- api/response.go | 5 ++++ api/roles/role.gen.go | 37 +++++----------------------- api/scopes/scope.gen.go | 37 +++++----------------------- api/sessions/session.gen.go | 37 +++++----------------------- api/targets/custom.go | 18 +++++--------- api/targets/target.gen.go | 37 +++++----------------------- api/users/user.gen.go | 37 +++++----------------------- api/util.go | 11 +++------ 18 files changed, 101 insertions(+), 407 deletions(-) diff --git a/api/accounts/account.gen.go b/api/accounts/account.gen.go index f0eddbfc35..41eb136867 100644 --- a/api/accounts/account.gen.go +++ b/api/accounts/account.gen.go @@ -2,7 +2,6 @@ package accounts import ( - "bytes" "context" "errors" "fmt" @@ -29,18 +28,6 @@ type Account struct { response *api.Response } -func (n Account) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Account) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Account) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type AccountReadResult struct { Item *Account response *api.Response @@ -50,12 +37,8 @@ func (n AccountReadResult) GetItem() interface{} { return n.Item } -func (n AccountReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AccountReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AccountReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -67,12 +50,8 @@ type AccountDeleteResult struct { response *api.Response } -func (n AccountDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AccountDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AccountDeleteResult) GetResponse() *api.Response { + return n.response } type AccountListResult struct { @@ -84,12 +63,8 @@ func (n AccountListResult) GetItems() interface{} { return n.Items } -func (n AccountListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AccountListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AccountListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/apierror.go b/api/apierror.go index 6bf6923a0f..5d996f3526 100644 --- a/api/apierror.go +++ b/api/apierror.go @@ -32,5 +32,10 @@ func (e *Error) Error() string { // Errors are considered the same iff they are both api.Errors and their statuses are the same. func (e *Error) Is(target error) bool { tApiErr := AsServerError(target) - return tApiErr != nil && tApiErr.Kind == e.Kind && e.ResponseStatus() == tApiErr.ResponseStatus() + return tApiErr != nil && tApiErr.Kind == e.Kind && e.Response().StatusCode() == tApiErr.Response().StatusCode() +} + +// Response returns the API response associated with the error +func (e *Error) Response() *Response { + return e.response } diff --git a/api/authmethods/authmethods.gen.go b/api/authmethods/authmethods.gen.go index 325c7744dc..be9bcb9844 100644 --- a/api/authmethods/authmethods.gen.go +++ b/api/authmethods/authmethods.gen.go @@ -2,7 +2,6 @@ package authmethods import ( - "bytes" "context" "errors" "fmt" @@ -30,18 +29,6 @@ type AuthMethod struct { response *api.Response } -func (n AuthMethod) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthMethod) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n AuthMethod) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type AuthMethodReadResult struct { Item *AuthMethod response *api.Response @@ -51,12 +38,8 @@ func (n AuthMethodReadResult) GetItem() interface{} { return n.Item } -func (n AuthMethodReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthMethodReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthMethodReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -68,12 +51,8 @@ type AuthMethodDeleteResult struct { response *api.Response } -func (n AuthMethodDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthMethodDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthMethodDeleteResult) GetResponse() *api.Response { + return n.response } type AuthMethodListResult struct { @@ -85,12 +64,8 @@ func (n AuthMethodListResult) GetItems() interface{} { return n.Items } -func (n AuthMethodListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthMethodListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthMethodListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/authtokens/authtokens.gen.go b/api/authtokens/authtokens.gen.go index 1425219ca7..09acb68783 100644 --- a/api/authtokens/authtokens.gen.go +++ b/api/authtokens/authtokens.gen.go @@ -2,7 +2,6 @@ package authtokens import ( - "bytes" "context" "fmt" "net/url" @@ -29,18 +28,6 @@ type AuthToken struct { response *api.Response } -func (n AuthToken) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthToken) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n AuthToken) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type AuthTokenReadResult struct { Item *AuthToken response *api.Response @@ -50,12 +37,8 @@ func (n AuthTokenReadResult) GetItem() interface{} { return n.Item } -func (n AuthTokenReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthTokenReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthTokenReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -67,12 +50,8 @@ type AuthTokenDeleteResult struct { response *api.Response } -func (n AuthTokenDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthTokenDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthTokenDeleteResult) GetResponse() *api.Response { + return n.response } type AuthTokenListResult struct { @@ -84,12 +63,8 @@ func (n AuthTokenListResult) GetItems() interface{} { return n.Items } -func (n AuthTokenListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n AuthTokenListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n AuthTokenListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/error.gen.go b/api/error.gen.go index 924ecb32fe..25fb4c592a 100644 --- a/api/error.gen.go +++ b/api/error.gen.go @@ -1,8 +1,6 @@ // Code generated by "make api"; DO NOT EDIT. package api -import "bytes" - type Error struct { Kind string `json:"kind,omitempty"` Op string `json:"op,omitempty"` @@ -11,15 +9,3 @@ type Error struct { response *Response } - -func (n Error) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Error) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Error) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} diff --git a/api/go.sum b/api/go.sum index ca70beb76b..11996002f8 100644 --- a/api/go.sum +++ b/api/go.sum @@ -188,6 +188,7 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -243,6 +244,7 @@ github.com/hashicorp/go-kms-wrapping v0.5.16/go.mod h1:lxD7e9q7ZyCtDEP+tnMevsEvw github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= @@ -268,6 +270,7 @@ github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= @@ -276,12 +279,14 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/hashicorp/shared-secure-libs v0.0.2/go.mod h1:xhtA0FH6AYYFOy0sir7u0O0zzdLi7ofU6oWxy+gjnuc= github.com/hashicorp/vault/api v1.0.5-0.20200514164214-89b1987e38c2/go.mod h1:P8A7gn1a6j/7qQ4zOaWI6FC/Q9jQWEBRTOwZH33tC9o= github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE= +github.com/hashicorp/vault/api v1.0.5-0.20200805123347-1ef507638af6 h1:ChHpobQse3kjVX7GmbpUFVqaMTf4lb1gcLrJltsUmS4= github.com/hashicorp/vault/api v1.0.5-0.20200805123347-1ef507638af6/go.mod h1:R3Umvhlxi2TN7Ex2hzOowyeNb+SfbVWI973N+ctaFMk= github.com/hashicorp/vault/sdk v0.1.14-0.20200514144402-4bfac290c352/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10= github.com/hashicorp/vault/sdk v0.1.14-0.20200514164214-89b1987e38c2/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10= github.com/hashicorp/vault/sdk v0.1.14-0.20200519221530-14615acda45f/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10= github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10= github.com/hashicorp/vault/sdk v0.1.14-0.20200805123347-1ef507638af6/go.mod h1:+S2qzS1Tex9JgbHxb/Jv7CdZyKydxqg09G/qVvyVmUc= +github.com/hashicorp/vault/sdk v0.1.14-0.20200916184745-5576096032f8 h1:oin8pbTJ+5OTk9JLzcCF1To0A/5Xsq5xJXQYhBTaOS8= github.com/hashicorp/vault/sdk v0.1.14-0.20200916184745-5576096032f8/go.mod h1:7GBJyKruotYxJlye8yHyGICV7kN7dQCNsCMTrb+v5J0= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= @@ -401,6 +406,7 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI= github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -573,6 +579,7 @@ golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -630,6 +637,7 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -768,6 +776,7 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKW gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w= gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= diff --git a/api/groups/group.gen.go b/api/groups/group.gen.go index c04179b3f1..6d83396ba2 100644 --- a/api/groups/group.gen.go +++ b/api/groups/group.gen.go @@ -2,7 +2,6 @@ package groups import ( - "bytes" "context" "errors" "fmt" @@ -29,18 +28,6 @@ type Group struct { response *api.Response } -func (n Group) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Group) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Group) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type GroupReadResult struct { Item *Group response *api.Response @@ -50,12 +37,8 @@ func (n GroupReadResult) GetItem() interface{} { return n.Item } -func (n GroupReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n GroupReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n GroupReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -67,12 +50,8 @@ type GroupDeleteResult struct { response *api.Response } -func (n GroupDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n GroupDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n GroupDeleteResult) GetResponse() *api.Response { + return n.response } type GroupListResult struct { @@ -84,12 +63,8 @@ func (n GroupListResult) GetItems() interface{} { return n.Items } -func (n GroupListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n GroupListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n GroupListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/hostcatalogs/host_catalog.gen.go b/api/hostcatalogs/host_catalog.gen.go index 7a0fe8ea75..f9238a4e88 100644 --- a/api/hostcatalogs/host_catalog.gen.go +++ b/api/hostcatalogs/host_catalog.gen.go @@ -2,7 +2,6 @@ package hostcatalogs import ( - "bytes" "context" "errors" "fmt" @@ -30,18 +29,6 @@ type HostCatalog struct { response *api.Response } -func (n HostCatalog) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostCatalog) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n HostCatalog) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type HostCatalogReadResult struct { Item *HostCatalog response *api.Response @@ -51,12 +38,8 @@ func (n HostCatalogReadResult) GetItem() interface{} { return n.Item } -func (n HostCatalogReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostCatalogReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostCatalogReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -68,12 +51,8 @@ type HostCatalogDeleteResult struct { response *api.Response } -func (n HostCatalogDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostCatalogDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostCatalogDeleteResult) GetResponse() *api.Response { + return n.response } type HostCatalogListResult struct { @@ -85,12 +64,8 @@ func (n HostCatalogListResult) GetItems() interface{} { return n.Items } -func (n HostCatalogListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostCatalogListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostCatalogListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/hosts/host.gen.go b/api/hosts/host.gen.go index 32dd78fb0f..f942333553 100644 --- a/api/hosts/host.gen.go +++ b/api/hosts/host.gen.go @@ -2,7 +2,6 @@ package hosts import ( - "bytes" "context" "errors" "fmt" @@ -30,18 +29,6 @@ type Host struct { response *api.Response } -func (n Host) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Host) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Host) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type HostReadResult struct { Item *Host response *api.Response @@ -51,12 +38,8 @@ func (n HostReadResult) GetItem() interface{} { return n.Item } -func (n HostReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -68,12 +51,8 @@ type HostDeleteResult struct { response *api.Response } -func (n HostDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostDeleteResult) GetResponse() *api.Response { + return n.response } type HostListResult struct { @@ -85,12 +64,8 @@ func (n HostListResult) GetItems() interface{} { return n.Items } -func (n HostListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/hostsets/host_set.gen.go b/api/hostsets/host_set.gen.go index d721ae6ae8..a1278da720 100644 --- a/api/hostsets/host_set.gen.go +++ b/api/hostsets/host_set.gen.go @@ -2,7 +2,6 @@ package hostsets import ( - "bytes" "context" "errors" "fmt" @@ -30,18 +29,6 @@ type HostSet struct { response *api.Response } -func (n HostSet) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostSet) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n HostSet) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type HostSetReadResult struct { Item *HostSet response *api.Response @@ -51,12 +38,8 @@ func (n HostSetReadResult) GetItem() interface{} { return n.Item } -func (n HostSetReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostSetReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostSetReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -68,12 +51,8 @@ type HostSetDeleteResult struct { response *api.Response } -func (n HostSetDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostSetDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostSetDeleteResult) GetResponse() *api.Response { + return n.response } type HostSetListResult struct { @@ -85,12 +64,8 @@ func (n HostSetListResult) GetItems() interface{} { return n.Items } -func (n HostSetListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n HostSetListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n HostSetListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/response.go b/api/response.go index 85c4d3e1b1..189343e06c 100644 --- a/api/response.go +++ b/api/response.go @@ -22,6 +22,11 @@ func (r *Response) HttpResponse() *http.Response { return r.resp } +// StatusCode returns the underlying HTTP status code +func (r *Response) StatusCode() int { + return r.resp.StatusCode +} + func (r *Response) Decode(inStruct interface{}) (*Error, error) { if r == nil || r.resp == nil { return nil, fmt.Errorf("nil response, cannot decode") diff --git a/api/roles/role.gen.go b/api/roles/role.gen.go index 0bebd58ea7..af6d28856c 100644 --- a/api/roles/role.gen.go +++ b/api/roles/role.gen.go @@ -2,7 +2,6 @@ package roles import ( - "bytes" "context" "errors" "fmt" @@ -32,18 +31,6 @@ type Role struct { response *api.Response } -func (n Role) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Role) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Role) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type RoleReadResult struct { Item *Role response *api.Response @@ -53,12 +40,8 @@ func (n RoleReadResult) GetItem() interface{} { return n.Item } -func (n RoleReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n RoleReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n RoleReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -70,12 +53,8 @@ type RoleDeleteResult struct { response *api.Response } -func (n RoleDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n RoleDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n RoleDeleteResult) GetResponse() *api.Response { + return n.response } type RoleListResult struct { @@ -87,12 +66,8 @@ func (n RoleListResult) GetItems() interface{} { return n.Items } -func (n RoleListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n RoleListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n RoleListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/scopes/scope.gen.go b/api/scopes/scope.gen.go index b04c603bcc..85bc1c9cca 100644 --- a/api/scopes/scope.gen.go +++ b/api/scopes/scope.gen.go @@ -2,7 +2,6 @@ package scopes import ( - "bytes" "context" "errors" "fmt" @@ -28,18 +27,6 @@ type Scope struct { response *api.Response } -func (n Scope) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Scope) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Scope) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type ScopeReadResult struct { Item *Scope response *api.Response @@ -49,12 +36,8 @@ func (n ScopeReadResult) GetItem() interface{} { return n.Item } -func (n ScopeReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n ScopeReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n ScopeReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -66,12 +49,8 @@ type ScopeDeleteResult struct { response *api.Response } -func (n ScopeDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n ScopeDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n ScopeDeleteResult) GetResponse() *api.Response { + return n.response } type ScopeListResult struct { @@ -83,12 +62,8 @@ func (n ScopeListResult) GetItems() interface{} { return n.Items } -func (n ScopeListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n ScopeListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n ScopeListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/sessions/session.gen.go b/api/sessions/session.gen.go index 99d956b56b..2d68a6b951 100644 --- a/api/sessions/session.gen.go +++ b/api/sessions/session.gen.go @@ -2,7 +2,6 @@ package sessions import ( - "bytes" "context" "fmt" "net/url" @@ -37,18 +36,6 @@ type Session struct { response *api.Response } -func (n Session) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Session) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Session) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type SessionReadResult struct { Item *Session response *api.Response @@ -58,12 +45,8 @@ func (n SessionReadResult) GetItem() interface{} { return n.Item } -func (n SessionReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n SessionReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n SessionReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -75,12 +58,8 @@ type SessionDeleteResult struct { response *api.Response } -func (n SessionDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n SessionDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n SessionDeleteResult) GetResponse() *api.Response { + return n.response } type SessionListResult struct { @@ -92,12 +71,8 @@ func (n SessionListResult) GetItems() interface{} { return n.Items } -func (n SessionListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n SessionListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n SessionListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/targets/custom.go b/api/targets/custom.go index 89a9bb7198..30d59ab852 100644 --- a/api/targets/custom.go +++ b/api/targets/custom.go @@ -1,28 +1,24 @@ package targets import ( - "bytes" "context" "fmt" "net/url" + + "github.com/hashicorp/boundary/api" ) type SessionAuthorizationResult struct { - Item *SessionAuthorization - responseBody *bytes.Buffer - responseMap map[string]interface{} + Item *SessionAuthorization + response *api.Response } func (n SessionAuthorizationResult) GetItem() interface{} { return n.Item } -func (n SessionAuthorizationResult) GetResponseBody() *bytes.Buffer { - return n.responseBody -} - -func (n SessionAuthorizationResult) GetResponseMap() map[string]interface{} { - return n.responseMap +func (n SessionAuthorizationResult) GetResponse() *api.Response { + return n.response } func (c *Client) AuthorizeSession(ctx context.Context, targetId string, opt ...Option) (*SessionAuthorizationResult, error) { @@ -76,7 +72,5 @@ func (c *Client) AuthorizeSession(ctx context.Context, targetId string, opt ...O if apiErr != nil { return nil, apiErr } - sar.responseBody = resp.Body - sar.responseMap = resp.Map return sar, nil } diff --git a/api/targets/target.gen.go b/api/targets/target.gen.go index 76905db417..4f9c528e1d 100644 --- a/api/targets/target.gen.go +++ b/api/targets/target.gen.go @@ -2,7 +2,6 @@ package targets import ( - "bytes" "context" "errors" "fmt" @@ -34,18 +33,6 @@ type Target struct { response *api.Response } -func (n Target) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n Target) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n Target) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type TargetReadResult struct { Item *Target response *api.Response @@ -55,12 +42,8 @@ func (n TargetReadResult) GetItem() interface{} { return n.Item } -func (n TargetReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n TargetReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n TargetReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -72,12 +55,8 @@ type TargetDeleteResult struct { response *api.Response } -func (n TargetDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n TargetDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n TargetDeleteResult) GetResponse() *api.Response { + return n.response } type TargetListResult struct { @@ -89,12 +68,8 @@ func (n TargetListResult) GetItems() interface{} { return n.Items } -func (n TargetListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n TargetListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n TargetListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/users/user.gen.go b/api/users/user.gen.go index 6bf8d98524..d9ba598aa9 100644 --- a/api/users/user.gen.go +++ b/api/users/user.gen.go @@ -2,7 +2,6 @@ package users import ( - "bytes" "context" "errors" "fmt" @@ -29,18 +28,6 @@ type User struct { response *api.Response } -func (n User) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n User) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n User) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} - type UserReadResult struct { Item *User response *api.Response @@ -50,12 +37,8 @@ func (n UserReadResult) GetItem() interface{} { return n.Item } -func (n UserReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n UserReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n UserReadResult) GetResponse() *api.Response { + return n.response } type ( @@ -67,12 +50,8 @@ type UserDeleteResult struct { response *api.Response } -func (n UserDeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n UserDeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n UserDeleteResult) GetResponse() *api.Response { + return n.response } type UserListResult struct { @@ -84,12 +63,8 @@ func (n UserListResult) GetItems() interface{} { return n.Items } -func (n UserListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n UserListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n UserListResult) GetResponse() *api.Response { + return n.response } // Client is a client for this collection diff --git a/api/util.go b/api/util.go index b6d549cc6c..4dd69368cf 100644 --- a/api/util.go +++ b/api/util.go @@ -1,8 +1,6 @@ package api import ( - "bytes" - "github.com/fatih/structs" ) @@ -12,17 +10,14 @@ func init() { type GenericResult interface { GetItem() interface{} - GetResponseBody() *bytes.Buffer - GetResponseMap() map[string]interface{} + GetResponse() *Response } type GenericDeleteResult interface { - GetResponseBody() *bytes.Buffer - GetResponseMap() map[string]interface{} + GetResponse() *Response } type GenericListResult interface { GetItems() interface{} - GetResponseBody() *bytes.Buffer - GetResponseMap() map[string]interface{} + GetResponse() *Response } From f5490e95a6c12ee30401874c3a44020ae9e0297e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 25 Feb 2021 12:41:18 -0500 Subject: [PATCH 4/6] Sync API deps to main in preparation for tag --- api/go.mod | 10 +++++----- api/go.sum | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/api/go.mod b/api/go.mod index dc9e3b2fec..9fc44148ab 100644 --- a/api/go.mod +++ b/api/go.mod @@ -5,11 +5,11 @@ go 1.15 require ( github.com/fatih/structs v1.1.0 github.com/hashicorp/boundary/sdk v0.0.3 - github.com/hashicorp/go-cleanhttp v0.5.1 - github.com/hashicorp/go-kms-wrapping v0.5.16 - github.com/hashicorp/go-retryablehttp v0.6.7 + github.com/hashicorp/go-cleanhttp v0.5.2 + github.com/hashicorp/go-kms-wrapping v0.6.1 + github.com/hashicorp/go-retryablehttp v0.6.8 github.com/hashicorp/go-rootcerts v1.0.2 - github.com/stretchr/testify v1.6.1 + github.com/stretchr/testify v1.7.0 golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e - google.golang.org/grpc v1.32.0 + google.golang.org/grpc v1.35.0 ) diff --git a/api/go.sum b/api/go.sum index 11996002f8..b10ccfec88 100644 --- a/api/go.sum +++ b/api/go.sum @@ -93,6 +93,7 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= @@ -130,6 +131,7 @@ github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4s github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -209,6 +211,7 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -230,6 +233,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= @@ -241,6 +246,8 @@ github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh github.com/hashicorp/go-kms-wrapping v0.5.12/go.mod h1:yVIWtGOTh/cdGc++/NOlXLus0hJ19Lz4iFrpF6WsZh4= github.com/hashicorp/go-kms-wrapping v0.5.16 h1:7qvB7JYLFART/bt1wafobMU5dDeyseE3ZBKB6UiyxWs= github.com/hashicorp/go-kms-wrapping v0.5.16/go.mod h1:lxD7e9q7ZyCtDEP+tnMevsEvw3M0gmZnneAgv8BaO1Q= +github.com/hashicorp/go-kms-wrapping v0.6.1 h1:QwG2nGi3BXa8xpU5BRWKY5z6Xg1aqAErC9tAvDfMA3Y= +github.com/hashicorp/go-kms-wrapping v0.6.1/go.mod h1:lxD7e9q7ZyCtDEP+tnMevsEvw3M0gmZnneAgv8BaO1Q= github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -250,8 +257,8 @@ github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.6.2/go.mod h1:gEx6HMUGxYYhJScX7W1Il64m6cc2C1mDaW3NQ9sY1FY= github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo= -github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs= +github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= @@ -475,6 +482,7 @@ github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3 github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -482,6 +490,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tencentcloud/tencentcloud-sdk-go v3.0.171+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -749,8 +759,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= -google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From b967ff7f059a43171c029d8074b3f9c4ad4f97d2 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 25 Feb 2021 12:41:56 -0500 Subject: [PATCH 5/6] Pull in new API tag --- go.mod | 2 +- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d26dfd803f..e78193e487 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/golang/protobuf v1.4.3 github.com/google/go-cmp v0.5.4 github.com/grpc-ecosystem/grpc-gateway/v2 v2.2.0 - github.com/hashicorp/boundary/api v0.0.6 + github.com/hashicorp/boundary/api v0.0.7 github.com/hashicorp/boundary/sdk v0.0.3 github.com/hashicorp/dbassert v0.0.0-20200930125617-6218396928df github.com/hashicorp/errwrap v1.1.0 diff --git a/go.sum b/go.sum index 5678af0555..37fef29afa 100644 --- a/go.sum +++ b/go.sum @@ -568,8 +568,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway/v2 v2.2.0 h1:HlJcTiqGHvaWDG7/s85d68Kw7G7FqMz+9LlcyVauOAw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.2.0/go.mod h1:gRq9gZWcIFvz68EgWqy2qQpRbmtn5j2qLZ4zHjqiLpg= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/hashicorp/boundary/api v0.0.6 h1:su5jSwwV4JM9bO3p5n4TQ6nN7UmhUt9AhOCD7b4Zy4c= -github.com/hashicorp/boundary/api v0.0.6/go.mod h1:7UdSNnUHkrvEn3HrD6hQYO/HtzpnYt6u6UDiCfLWn1o= +github.com/hashicorp/boundary/api v0.0.7 h1:BdDnbt4Ufp/4ylL4hTbOGAOAiotN/bMRgQ/PrPL+cCA= +github.com/hashicorp/boundary/api v0.0.7/go.mod h1:fWESFnitZg/5EHEtg8cuvT0E9rFywnBrRtGdLjhDwqU= github.com/hashicorp/boundary/sdk v0.0.3 h1:xCj1LLvoLkJ6qP6oyn9k5uVHn8N40TGRG+iw7GdDmmU= github.com/hashicorp/boundary/sdk v0.0.3/go.mod h1:hu1j0/j9FY+G/vhl+6zoT18dCFs+wzeyTI+EuTHg4OY= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= @@ -612,7 +612,6 @@ github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.6.2/go.mod h1:gEx6HMUGxYYhJScX7W1Il64m6cc2C1mDaW3NQ9sY1FY= github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs= github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= From 72aa110f727d2db58135f4f83f1205aded39c2e0 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 25 Feb 2021 12:43:17 -0500 Subject: [PATCH 6/6] CLI JSON updates (#962) See Changelog for details. --- CHANGELOG.md | 20 +++ go.mod | 4 +- go.sum | 5 - internal/api/genapi/templates.go | 38 +---- internal/cmd/base/format.go | 156 +++++++++++++----- .../cmd/commands/accountscmd/accounts.gen.go | 33 ++-- .../accountscmd/password_accounts.gen.go | 22 +-- .../cmd/commands/authenticate/password.go | 20 +-- .../authmethodscmd/authmethods.gen.go | 33 ++-- .../password_authmethods.gen.go | 22 +-- .../commands/authtokenscmd/authtokens.gen.go | 33 ++-- internal/cmd/commands/connect/connect.go | 87 ++++------ internal/cmd/commands/groupscmd/groups.gen.go | 35 ++-- .../hostcatalogscmd/hostcatalogs.gen.go | 33 ++-- .../static_hostcatalogs.gen.go | 22 +-- internal/cmd/commands/hostscmd/hosts.gen.go | 33 ++-- .../cmd/commands/hostscmd/static_hosts.gen.go | 22 +-- .../cmd/commands/hostsetscmd/hostsets.gen.go | 33 ++-- .../hostsetscmd/static_hostsets.gen.go | 22 +-- internal/cmd/commands/rolescmd/roles.gen.go | 35 ++-- internal/cmd/commands/scopescmd/scopes.gen.go | 35 ++-- .../cmd/commands/sessionscmd/sessions.gen.go | 31 ++-- .../cmd/commands/targetscmd/targets.gen.go | 31 ++-- .../commands/targetscmd/tcp_targets.gen.go | 22 +-- internal/cmd/commands/userscmd/users.gen.go | 35 ++-- internal/cmd/gencli/templates.go | 37 ++--- internal/tests/api/accounts/account_test.go | 8 +- .../api/authmethods/authenticate_test.go | 2 +- .../tests/api/authtokens/authtoken_test.go | 4 +- internal/tests/api/groups/group_test.go | 10 +- .../api/hostcatalogs/host_catalog_test.go | 8 +- internal/tests/api/hosts/host_test.go | 8 +- internal/tests/api/hostsets/host_set_test.go | 8 +- internal/tests/api/roles/role_test.go | 8 +- internal/tests/api/scopes/scope_test.go | 8 +- internal/tests/api/targets/target_test.go | 8 +- internal/tests/api/users/user_test.go | 10 +- internal/tests/cli/boundary/_accounts.bash | 2 +- .../cli/boundary/_authorized_actions.bash | 2 +- internal/tests/cli/boundary/_groups.bash | 4 +- .../tests/cli/boundary/_host_catalogs.bash | 2 +- internal/tests/cli/boundary/_host_sets.bash | 4 +- internal/tests/cli/boundary/_hosts.bash | 2 +- internal/tests/cli/boundary/_roles.bash | 6 +- internal/tests/cli/boundary/_scopes.bash | 2 +- internal/tests/cli/boundary/_sessions.bash | 4 +- internal/tests/cli/boundary/_targets.bash | 4 +- internal/tests/cli/boundary/_users.bash | 2 +- internal/tests/cli/boundary/sessions.bats | 4 +- .../content/docs/getting-started/index.mdx | 2 +- 50 files changed, 485 insertions(+), 536 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab6fd4b80..4ebb35e20b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. +## Next + +### Changes/Deprecations + +All of these changes are from [PR +962](https://github.com/hashicorp/boundary/pull/962): + +* api: A few functions have changed places. Notably, instead of `ResponseMap()` + and `ResponseBody()`, resources simply expose `Response()`. This higher-level + response object contains the map and body, and also exposes `StatusCode()` in + place of indivdidual resources. +* cli: In `json` output format, a resource item is now an object under the + top-level key `item`; a list of resource items is now an list of objects under + the top-level key `items`. This preserves the top level for putting in other + useful information later on (and the HTTP status code is included now). +* cli: In `json` output format, errors are now serialized as a JSON object with + an `error` key instead of outputting normal text +* cli: All errors, including API errors, are now written to `stderr`. Previously + in the default table format, API errors would be written to `stdout`. + ## 0.1.7 (2021/02/16) *Note* This release fixes an upgrade issue affecting users on Postgres 11 diff --git a/go.mod b/go.mod index e78193e487..12afcb97fb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/hashicorp/boundary -go 1.14 +go 1.15 + +replace github.com/hashicorp/boundary/api => ./api require ( github.com/armon/go-metrics v0.3.6 diff --git a/go.sum b/go.sum index 37fef29afa..c043ff90d2 100644 --- a/go.sum +++ b/go.sum @@ -568,8 +568,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway/v2 v2.2.0 h1:HlJcTiqGHvaWDG7/s85d68Kw7G7FqMz+9LlcyVauOAw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.2.0/go.mod h1:gRq9gZWcIFvz68EgWqy2qQpRbmtn5j2qLZ4zHjqiLpg= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/hashicorp/boundary/api v0.0.7 h1:BdDnbt4Ufp/4ylL4hTbOGAOAiotN/bMRgQ/PrPL+cCA= -github.com/hashicorp/boundary/api v0.0.7/go.mod h1:fWESFnitZg/5EHEtg8cuvT0E9rFywnBrRtGdLjhDwqU= github.com/hashicorp/boundary/sdk v0.0.3 h1:xCj1LLvoLkJ6qP6oyn9k5uVHn8N40TGRG+iw7GdDmmU= github.com/hashicorp/boundary/sdk v0.0.3/go.mod h1:hu1j0/j9FY+G/vhl+6zoT18dCFs+wzeyTI+EuTHg4OY= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= @@ -1362,12 +1360,10 @@ golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1454,7 +1450,6 @@ golang.org/x/tools v0.0.0-20200818005847-188abfa75333/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201125231158-b5590deeca9b/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= diff --git a/internal/api/genapi/templates.go b/internal/api/genapi/templates.go index 434ccad621..7c77f2a037 100644 --- a/internal/api/genapi/templates.go +++ b/internal/api/genapi/templates.go @@ -548,20 +548,6 @@ type {{ .Name }} struct { {{ range .Fields }} {{ end }} } -{{ if ( or .CreateResponseTypes ( eq .Name "Error" ) ) }} -func (n {{ .Name }}) ResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n {{ .Name }}) ResponseMap() map[string]interface{} { - return n.response.Map -} - -func (n {{ .Name }}) ResponseStatus() int { - return n.response.HttpResponse().StatusCode -} -{{ end }} - {{ if .CreateResponseTypes }} type {{ .Name }}ReadResult struct { Item *{{ .Name }} @@ -572,12 +558,8 @@ func (n {{ .Name }}ReadResult) GetItem() interface{} { return n.Item } -func (n {{ .Name }}ReadResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n {{ .Name }}ReadResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n {{ .Name }}ReadResult) GetResponse() *api.Response { + return n.response } type {{ .Name }}CreateResult = {{ .Name }}ReadResult @@ -587,12 +569,8 @@ type {{ .Name }}DeleteResult struct { response *api.Response } -func (n {{ .Name }}DeleteResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n {{ .Name }}DeleteResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n {{ .Name }}DeleteResult) GetResponse() *api.Response { + return n.response } type {{ .Name }}ListResult struct { @@ -604,12 +582,8 @@ func (n {{ .Name }}ListResult) GetItems() interface{} { return n.Items } -func (n {{ .Name }}ListResult) GetResponseBody() *bytes.Buffer { - return n.response.Body -} - -func (n {{ .Name }}ListResult) GetResponseMap() map[string]interface{} { - return n.response.Map +func (n {{ .Name }}ListResult) GetResponse() *api.Response { + return n.response } {{ end }} `))) diff --git a/internal/cmd/base/format.go b/internal/cmd/base/format.go index 908fd0ed43..bd070d23e8 100644 --- a/internal/cmd/base/format.go +++ b/internal/cmd/base/format.go @@ -134,58 +134,134 @@ func WrapMap(prefixSpaces, maxLengthOverride int, input map[string]interface{}) return strings.Join(ret, "\n") } -func PrintApiError(in *api.Error) string { - nonAttributeMap := map[string]interface{}{ - "Status": in.ResponseStatus(), - "Kind": in.Kind, - "Message": in.Message, - } +// PrintApiError prints the given API error, optionally with context +// information, to the UI in the appropriate format +func (c *Command) PrintApiError(in *api.Error, contextStr string) { + switch Format(c.UI) { + case "json": + output := struct { + Context string `json:"context,omitempty"` + Status int `json:"status"` + ApiError json.RawMessage `json:"api_error"` + }{ + Context: contextStr, + Status: in.Response().StatusCode(), + ApiError: in.Response().Body.Bytes(), + } + b, _ := JsonFormatter{}.Format(output) + c.UI.Error(string(b)) - if in.Op != "" { - nonAttributeMap["Operation"] = in.Op - } + default: + nonAttributeMap := map[string]interface{}{ + "Status": in.Response().StatusCode(), + "Kind": in.Kind, + "Message": in.Message, + } + if contextStr != "" { + nonAttributeMap["context"] = contextStr + } + if in.Op != "" { + nonAttributeMap["Operation"] = in.Op + } - maxLength := MaxAttributesLength(nonAttributeMap, nil, nil) + maxLength := MaxAttributesLength(nonAttributeMap, nil, nil) - ret := []string{ - "", - "Error information:", - WrapMap(2, maxLength+2, nonAttributeMap), - } + var output []string + if contextStr != "" { + output = append(output, contextStr) + } + output = append(output, + "", + "Error information:", + WrapMap(2, maxLength+2, nonAttributeMap), + ) - if in.Details != nil { - if len(in.Details.WrappedErrors) > 0 { - ret = append(ret, - "", - " Wrapped Errors:", - ) - for _, we := range in.Details.WrappedErrors { - ret = append(ret, - fmt.Sprintf(" Message: %s", we.Message), - fmt.Sprintf(" Operation: %s", we.Op), + if in.Details != nil { + if len(in.Details.WrappedErrors) > 0 { + output = append(output, + "", + " Wrapped Errors:", ) + for _, we := range in.Details.WrappedErrors { + output = append(output, + fmt.Sprintf(" Message: %s", we.Message), + fmt.Sprintf(" Operation: %s", we.Op), + ) + } } - } - if len(in.Details.RequestFields) > 0 { - ret = append(ret, - "", - " Field-specific Errors:", - ) - for _, field := range in.Details.RequestFields { - if field.Name == "update_mask" { - // TODO: Report useful error messages related to "update_mask". - continue - } - ret = append(ret, - fmt.Sprintf(" Name: -%s", strings.ReplaceAll(field.Name, "_", "-")), - fmt.Sprintf(" Error: %s", field.Description), + if len(in.Details.RequestFields) > 0 { + output = append(output, + "", + " Field-specific Errors:", ) + for _, field := range in.Details.RequestFields { + if field.Name == "update_mask" { + // TODO: Report useful error messages related to "update_mask". + continue + } + output = append(output, + fmt.Sprintf(" Name: -%s", strings.ReplaceAll(field.Name, "_", "-")), + fmt.Sprintf(" Error: %s", field.Description), + ) + } } } + + c.UI.Error(WrapForHelpText(output)) + } +} + +// PrintCliError prints the given CLI error to the UI in the appropriate format +func (c *Command) PrintCliError(err error) { + switch Format(c.UI) { + case "table": + c.UI.Error(err.Error()) + case "json": + output := struct { + Error string `json:"error"` + }{ + Error: err.Error(), + } + b, _ := JsonFormatter{}.Format(output) + c.UI.Error(string(b)) + } +} + +// PrintJsonItem prints the given item to the UI in JSON format +func (c *Command) PrintJsonItem(result api.GenericResult, item interface{}) int { + output := struct { + StatusCode int `json:"status_code"` + Item interface{} `json:"item"` + }{ + StatusCode: result.GetResponse().HttpResponse().StatusCode, + Item: item, + } + b, err := JsonFormatter{}.Format(output) + if err != nil { + c.PrintCliError(err) + return 1 } + c.UI.Output(string(b)) + return 0 +} - return WrapForHelpText(ret) +// PrintJsonItems prints the given items to the UI in JSON format +func (c *Command) PrintJsonItems(result api.GenericListResult, items []interface{}) int { + output := struct { + StatusCode int `json:"status_code"` + Items []interface{} `json:"items"` + }{ + StatusCode: result.GetResponse().HttpResponse().StatusCode, + Items: items, + } + b, err := JsonFormatter{}.Format(output) + if err != nil { + c.PrintCliError(err) + return 1 + } + c.UI.Output(string(b)) + return 0 } // An output formatter for json output of an object diff --git a/internal/cmd/commands/accountscmd/accounts.gen.go b/internal/cmd/commands/accountscmd/accounts.gen.go index 7ddd3247a9..8879c1b936 100644 --- a/internal/cmd/commands/accountscmd/accounts.gen.go +++ b/internal/cmd/commands/accountscmd/accounts.gen.go @@ -2,6 +2,7 @@ package accountscmd import ( + "errors" "fmt" "net/http" "sync" @@ -131,12 +132,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -146,7 +147,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagAuthMethodId == "" { - c.UI.Error("AuthMethod ID must be passed in via -auth-method-id or BOUNDARY_AUTH_METHOD_ID") + c.PrintCliError(errors.New("AuthMethod ID must be passed in via -auth-method-id or BOUNDARY_AUTH_METHOD_ID")) return 1 } } @@ -154,7 +155,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } accountsClient := accounts.NewClient(client) @@ -214,7 +215,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = accountsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -228,16 +229,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -274,12 +275,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -296,12 +296,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/accountscmd/password_accounts.gen.go b/internal/cmd/commands/accountscmd/password_accounts.gen.go index 912a6d1f3f..7056644c3a 100644 --- a/internal/cmd/commands/accountscmd/password_accounts.gen.go +++ b/internal/cmd/commands/accountscmd/password_accounts.gen.go @@ -2,6 +2,7 @@ package accountscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -114,12 +115,12 @@ func (c *PasswordCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsPasswordMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -129,7 +130,7 @@ func (c *PasswordCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagAuthMethodId == "" { - c.UI.Error("AuthMethod ID must be passed in via -auth-method-id or BOUNDARY_AUTH_METHOD_ID") + c.PrintCliError(errors.New("AuthMethod ID must be passed in via -auth-method-id or BOUNDARY_AUTH_METHOD_ID")) return 1 } } @@ -137,7 +138,7 @@ func (c *PasswordCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } accountsClient := accounts.NewClient(client) @@ -190,16 +191,16 @@ func (c *PasswordCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomPasswordActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -215,12 +216,7 @@ func (c *PasswordCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/authenticate/password.go b/internal/cmd/commands/authenticate/password.go index a04f50dd9a..2eab0a2c4e 100644 --- a/internal/cmd/commands/authenticate/password.go +++ b/internal/cmd/commands/authenticate/password.go @@ -3,6 +3,7 @@ package authenticate import ( "encoding/base64" "encoding/json" + "errors" "fmt" "os" "strings" @@ -94,16 +95,16 @@ func (c *PasswordCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } switch { case c.flagLoginName == "": - c.UI.Error("Login name must be provided via -login-name") + c.PrintCliError(errors.New("Login name must be provided via -login-name")) return 1 case c.FlagAuthMethodId == "": - c.UI.Error("Auth method ID must be provided via -auth-method-id") + c.PrintCliError(errors.New("Auth method ID must be provided via -auth-method-id")) return 1 } @@ -120,7 +121,7 @@ func (c *PasswordCommand) Run(args []string) int { client, err := c.Client(base.WithNoTokenScope(), base.WithNoTokenValue()) if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %w", err)) return 2 } @@ -134,10 +135,10 @@ func (c *PasswordCommand) Run(args []string) int { }) if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing authentication: %s", base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, "Error from controller when performing authentication") return 1 } - c.UI.Error(fmt.Sprintf("Error trying to perform authentication: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to perform authentication: %w", err)) return 2 } @@ -155,12 +156,7 @@ func (c *PasswordCommand) Run(args []string) int { })) case "json": - jsonOut, err := base.JsonFormatter{}.Format(token) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(jsonOut)) + return c.PrintJsonItem(result, token) } var gotErr bool diff --git a/internal/cmd/commands/authmethodscmd/authmethods.gen.go b/internal/cmd/commands/authmethodscmd/authmethods.gen.go index d89a22105f..c6e3751670 100644 --- a/internal/cmd/commands/authmethodscmd/authmethods.gen.go +++ b/internal/cmd/commands/authmethodscmd/authmethods.gen.go @@ -2,6 +2,7 @@ package authmethodscmd import ( + "errors" "fmt" "net/http" "sync" @@ -129,12 +130,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -144,7 +145,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -152,7 +153,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } authmethodsClient := authmethods.NewClient(client) @@ -181,7 +182,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = authmethodsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -195,16 +196,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -241,12 +242,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -263,12 +263,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/authmethodscmd/password_authmethods.gen.go b/internal/cmd/commands/authmethodscmd/password_authmethods.gen.go index 6c8a773755..5b6c59e9fb 100644 --- a/internal/cmd/commands/authmethodscmd/password_authmethods.gen.go +++ b/internal/cmd/commands/authmethodscmd/password_authmethods.gen.go @@ -2,6 +2,7 @@ package authmethodscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -114,12 +115,12 @@ func (c *PasswordCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsPasswordMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -129,7 +130,7 @@ func (c *PasswordCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -137,7 +138,7 @@ func (c *PasswordCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } authmethodsClient := authmethods.NewClient(client) @@ -195,16 +196,16 @@ func (c *PasswordCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomPasswordActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -220,12 +221,7 @@ func (c *PasswordCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/authtokenscmd/authtokens.gen.go b/internal/cmd/commands/authtokenscmd/authtokens.gen.go index 947bbaf7a3..ec4e9b43bb 100644 --- a/internal/cmd/commands/authtokenscmd/authtokens.gen.go +++ b/internal/cmd/commands/authtokenscmd/authtokens.gen.go @@ -2,6 +2,7 @@ package authtokenscmd import ( + "errors" "fmt" "net/http" "sync" @@ -125,12 +126,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -140,7 +141,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -148,7 +149,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } authtokensClient := authtokens.NewClient(client) @@ -177,7 +178,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = authtokensClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -191,16 +192,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -237,12 +238,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -259,12 +259,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/connect/connect.go b/internal/cmd/commands/connect/connect.go index 079415fd7d..3af6bbdbd1 100644 --- a/internal/cmd/commands/connect/connect.go +++ b/internal/cmd/commands/connect/connect.go @@ -208,15 +208,6 @@ func (c *Command) Flags() *base.FlagSets { Usage: "Target scope name, if authorizing the session via scope parameters and target name. Mutually exclusive with -scope-id.", }) - f.BoolVar(&base.BoolVar{ - Name: "output-json-errors", - Target: &c.outputJsonErrors, - EnvVar: "BOUNDARY_CONNECT_OUTPUT_JSON_ERRORS", - Completion: complete.PredictNothing, - Usage: "Cause errors coming from this command to be output as JSON. This is experimental only and currently only meant for internal purposes. The format may change at any time and this flag/env var may be removed or modified at any time.", - Hidden: true, - }) - switch c.Func { case "connect": f.StringVar(&base.StringVar{ @@ -274,7 +265,7 @@ func (c *Command) Run(args []string) (retCode int) { f := c.Flags() if err := f.Parse(args); err != nil { - c.Error(err.Error()) + c.PrintCliError(err) return 3 } @@ -282,22 +273,22 @@ func (c *Command) Run(args []string) (retCode int) { case c.flagAuthzToken != "": switch { case c.flagTargetId != "": - c.Error(`-target-id and -authz-token cannot both be specified`) + c.PrintCliError(errors.New(`-target-id and -authz-token cannot both be specified`)) return 3 case c.flagTargetName != "": - c.Error(`-target-name and -authz-token cannot both be specified`) + c.PrintCliError(errors.New(`-target-name and -authz-token cannot both be specified`)) return 3 } default: if c.flagTargetId == "" && (c.flagTargetName == "" || (c.FlagScopeId == "" && c.FlagScopeName == "")) { - c.Error("Target ID was not passed in, but no combination of target name and scope ID/name was passed in either") + c.PrintCliError(errors.New("Target ID was not passed in, but no combination of target name and scope ID/name was passed in either")) return 3 } if c.flagTargetId != "" && (c.flagTargetName != "" || c.FlagScopeId != "" || c.FlagScopeName != "") { - c.Error("Cannot specify a target ID and also other lookup parameters") + c.PrintCliError(errors.New("Cannot specify a target ID and also other lookup parameters")) return 3 } } @@ -319,7 +310,7 @@ func (c *Command) Run(args []string) (retCode int) { tofuToken, err := base62.Random(20) if err != nil { - c.Error(fmt.Errorf("Could not derive random bytes for tofu token: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Could not derive random bytes for tofu token: %w", err)) return 2 } @@ -330,7 +321,7 @@ func (c *Command) Run(args []string) (retCode int) { } listenAddr := net.ParseIP(c.flagListenAddr) if listenAddr == nil { - c.Error(fmt.Sprintf("Could not successfully parse listen address of %s", c.flagListenAddr)) + c.PrintCliError(fmt.Errorf("Could not successfully parse listen address of %s", c.flagListenAddr)) return 3 } @@ -340,18 +331,18 @@ func (c *Command) Run(args []string) (retCode int) { if authzString == "-" { authBytes, err := ioutil.ReadAll(os.Stdin) if err != nil { - c.Error(fmt.Errorf("No authorization string was provided and encountered the following error attempting to read it from stdin: %w", err).Error()) + c.PrintCliError(fmt.Errorf("No authorization string was provided and encountered the following error attempting to read it from stdin: %w", err)) return 3 } if len(authBytes) == 0 { - c.Error("No authorization data read from stdin") + c.PrintCliError(errors.New("No authorization data read from stdin")) return 3 } authzString = string(authBytes) } if authzString == "" { - c.Error("Authorization data was empty") + c.PrintCliError(errors.New("Authorization data was empty")) return 3 } @@ -367,7 +358,7 @@ func (c *Command) Run(args []string) (retCode int) { default: client, err := c.Client() if err != nil { - c.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err)) return 2 } targetClient := targets.NewClient(client) @@ -389,15 +380,10 @@ func (c *Command) Run(args []string) (retCode int) { sar, err := targetClient.AuthorizeSession(c.Context, c.flagTargetId, opts...) if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - switch c.outputJsonErrors { - case true: - c.Error(apiErr.ResponseBody().String()) - default: - c.Error(fmt.Sprintf("Error from controller when performing authorize-session against target: %s", base.PrintApiError(apiErr))) - } + c.PrintApiError(apiErr, "Error from controller when performing authorize-session action against given target") return 1 } - c.Error(fmt.Sprintf("Error trying to authorize a session against target: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to authorize a session against target: %w", err)) return 2 } authzString = sar.GetItem().(*targets.SessionAuthorization).AuthorizationToken @@ -405,22 +391,22 @@ func (c *Command) Run(args []string) (retCode int) { marshaled, err := base58.FastBase58Decoding(authzString) if err != nil { - c.Error(fmt.Errorf("Unable to base58-decode authorization data: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Unable to base58-decode authorization data: %w", err)) return 3 } if len(marshaled) == 0 { - c.Error("Zero length authorization information after decoding") + c.PrintCliError(errors.New("Zero length authorization information after decoding")) return 3 } c.sessionAuthzData = new(targetspb.SessionAuthorizationData) if err := proto.Unmarshal(marshaled, c.sessionAuthzData); err != nil { - c.Error(fmt.Errorf("Unable to proto-decode authorization data: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Unable to proto-decode authorization data: %w", err)) return 3 } if len(c.sessionAuthzData.GetWorkerInfo()) == 0 { - c.Error("No workers found in authorization string") + c.PrintCliError(errors.New("No workers found in authorization string")) return 3 } @@ -429,12 +415,12 @@ func (c *Command) Run(args []string) (retCode int) { parsedCert, err := x509.ParseCertificate(c.sessionAuthzData.Certificate) if err != nil { - c.Error(fmt.Errorf("Unable to decode mTLS certificate: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Unable to decode mTLS certificate: %w", err)) return 3 } if len(parsedCert.DNSNames) != 1 { - c.Error(fmt.Errorf("mTLS certificate has invalid parameters: %w", err).Error()) + c.PrintCliError(fmt.Errorf("mTLS certificate has invalid parameters: %w", err)) return 3 } @@ -474,7 +460,7 @@ func (c *Command) Run(args []string) (retCode int) { Port: c.flagListenPort, }) if err != nil { - c.Error(fmt.Errorf("Error starting listening port: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Error starting listening port: %w", err)) return 2 } @@ -482,7 +468,7 @@ func (c *Command) Run(args []string) (retCode int) { // Forces the for loop to exist instead of spinning on errors c.connectionsLeft.Store(0) if err := c.listener.Close(); err != nil { - c.Error(fmt.Errorf("Error closing listener on shutdown: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Error closing listener on shutdown: %w", err)) retCode = 2 } } @@ -510,7 +496,7 @@ func (c *Command) Run(args []string) (retCode int) { case "json": out, err := json.Marshal(&sessInfo) if err != nil { - c.Error(fmt.Errorf("error marshaling session information: %w", err).Error()) + c.PrintCliError(fmt.Errorf("error marshaling session information: %w", err)) return 2 } c.UI.Output(string(out)) @@ -536,7 +522,7 @@ func (c *Command) Run(args []string) (retCode int) { if c.connectionsLeft.Load() == 0 { return } - c.Error(fmt.Errorf("Error accepting connection: %w", err).Error()) + c.PrintCliError(fmt.Errorf("Error accepting connection: %w", err)) continue } } @@ -549,10 +535,10 @@ func (c *Command) Run(args []string) (retCode int) { workerAddr, transport) if err != nil { - c.Error(err.Error()) + c.PrintCliError(err) } else { if err := c.runTcpProxyV1(wsConn, listeningConn, tofuToken); err != nil { - c.Error(err.Error()) + c.PrintCliError(err) } } }() @@ -620,10 +606,10 @@ func (c *Command) Run(args []string) (retCode int) { ctx, cancel := context.WithTimeout(context.Background(), sessionCancelTimeout) wsConn, err := c.getWsConn(ctx, workerAddr, transport) if err != nil { - c.Error(fmt.Errorf("error fetching connection to send session teardown request to worker: %w", err).Error()) + c.PrintCliError(fmt.Errorf("error fetching connection to send session teardown request to worker: %w", err)) } else { if err := c.sendSessionTeardown(ctx, wsConn, tofuToken); err != nil { - c.Error(fmt.Errorf("error sending session teardown request to worker: %w", err).Error()) + c.PrintCliError(fmt.Errorf("error sending session teardown request to worker: %w", err)) } } cancel() @@ -636,7 +622,7 @@ func (c *Command) Run(args []string) (retCode int) { case "json": out, err := json.Marshal(&termInfo) if err != nil { - c.Error(fmt.Errorf("error marshaling termination information: %w", err).Error()) + c.PrintCliError(fmt.Errorf("error marshaling termination information: %w", err)) return 2 } c.UI.Output(string(out)) @@ -767,7 +753,7 @@ func (c *Command) updateConnsLeft(connsLeft int32) { case "json": out, err := json.Marshal(&connInfo) if err != nil { - c.Error(fmt.Errorf("error marshaling connection information: %w", err).Error()) + c.PrintCliError(fmt.Errorf("error marshaling connection information: %w", err)) } c.UI.Output(string(out)) } @@ -788,7 +774,7 @@ func (c *Command) handleExec(passthroughArgs []string) { case "http": httpArgs, err := c.httpFlags.buildArgs(c, port, ip, addr) if err != nil { - c.Error(fmt.Sprintf("Error parsing session args: %s", err)) + c.PrintCliError(fmt.Errorf("Error parsing session args: %w", err)) c.execCmdReturnValue.Store(int32(3)) return } @@ -806,7 +792,7 @@ func (c *Command) handleExec(passthroughArgs []string) { case "kube": kubeArgs, err := c.kubeFlags.buildArgs(c, port, ip, addr) if err != nil { - c.Error(fmt.Sprintf("Error parsing session args: %s", err)) + c.PrintCliError(fmt.Errorf("Error parsing session args: %w", err)) c.execCmdReturnValue.Store(int32(3)) return } @@ -860,18 +846,9 @@ func (c *Command) handleExec(passthroughArgs []string) { } } - c.Error(fmt.Sprintf("Failed to run command: %s", err)) + c.PrintCliError(fmt.Errorf("Failed to run command: %w", err)) c.execCmdReturnValue.Store(int32(exitCode)) return } c.execCmdReturnValue.Store(0) } - -func (c *Command) Error(err string) { - switch c.outputJsonErrors { - case true: - c.UI.Error(fmt.Sprintf(`{"error": %q}`, err)) - default: - c.UI.Error(err) - } -} diff --git a/internal/cmd/commands/groupscmd/groups.gen.go b/internal/cmd/commands/groupscmd/groups.gen.go index 8a6fd24d7b..674c356e7d 100644 --- a/internal/cmd/commands/groupscmd/groups.gen.go +++ b/internal/cmd/commands/groupscmd/groups.gen.go @@ -2,6 +2,7 @@ package groupscmd import ( + "errors" "fmt" "net/http" "sync" @@ -137,12 +138,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -153,13 +154,13 @@ func (c *Command) Run(args []string) int { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } @@ -168,7 +169,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } groupsClient := groups.NewClient(client) @@ -255,7 +256,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = groupsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -269,16 +270,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -315,12 +316,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -337,12 +337,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostcatalogscmd/hostcatalogs.gen.go b/internal/cmd/commands/hostcatalogscmd/hostcatalogs.gen.go index 478b861f0a..adce939165 100644 --- a/internal/cmd/commands/hostcatalogscmd/hostcatalogs.gen.go +++ b/internal/cmd/commands/hostcatalogscmd/hostcatalogs.gen.go @@ -2,6 +2,7 @@ package hostcatalogscmd import ( + "errors" "fmt" "net/http" "sync" @@ -129,12 +130,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -144,7 +145,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -152,7 +153,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostcatalogsClient := hostcatalogs.NewClient(client) @@ -181,7 +182,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = hostcatalogsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -195,16 +196,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -241,12 +242,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -263,12 +263,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostcatalogscmd/static_hostcatalogs.gen.go b/internal/cmd/commands/hostcatalogscmd/static_hostcatalogs.gen.go index 36802ea86a..8e9b33e1cc 100644 --- a/internal/cmd/commands/hostcatalogscmd/static_hostcatalogs.gen.go +++ b/internal/cmd/commands/hostcatalogscmd/static_hostcatalogs.gen.go @@ -2,6 +2,7 @@ package hostcatalogscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -112,12 +113,12 @@ func (c *StaticCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsStaticMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -127,7 +128,7 @@ func (c *StaticCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -135,7 +136,7 @@ func (c *StaticCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostcatalogsClient := hostcatalogs.NewClient(client) @@ -193,16 +194,16 @@ func (c *StaticCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomStaticActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -218,12 +219,7 @@ func (c *StaticCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostscmd/hosts.gen.go b/internal/cmd/commands/hostscmd/hosts.gen.go index 04270b7b53..111147ab18 100644 --- a/internal/cmd/commands/hostscmd/hosts.gen.go +++ b/internal/cmd/commands/hostscmd/hosts.gen.go @@ -2,6 +2,7 @@ package hostscmd import ( + "errors" "fmt" "net/http" "sync" @@ -129,12 +130,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -144,7 +145,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagHostCatalogId == "" { - c.UI.Error("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID") + c.PrintCliError(errors.New("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID")) return 1 } } @@ -152,7 +153,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostsClient := hosts.NewClient(client) @@ -192,7 +193,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = hostsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -206,16 +207,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -252,12 +253,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -274,12 +274,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostscmd/static_hosts.gen.go b/internal/cmd/commands/hostscmd/static_hosts.gen.go index 27d78a1f0a..68b4e2a265 100644 --- a/internal/cmd/commands/hostscmd/static_hosts.gen.go +++ b/internal/cmd/commands/hostscmd/static_hosts.gen.go @@ -2,6 +2,7 @@ package hostscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -114,12 +115,12 @@ func (c *StaticCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsStaticMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -129,7 +130,7 @@ func (c *StaticCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagHostCatalogId == "" { - c.UI.Error("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID") + c.PrintCliError(errors.New("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID")) return 1 } } @@ -137,7 +138,7 @@ func (c *StaticCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostsClient := hosts.NewClient(client) @@ -190,16 +191,16 @@ func (c *StaticCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomStaticActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -215,12 +216,7 @@ func (c *StaticCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostsetscmd/hostsets.gen.go b/internal/cmd/commands/hostsetscmd/hostsets.gen.go index 5ca359be98..ba9aa7328d 100644 --- a/internal/cmd/commands/hostsetscmd/hostsets.gen.go +++ b/internal/cmd/commands/hostsetscmd/hostsets.gen.go @@ -2,6 +2,7 @@ package hostsetscmd import ( + "errors" "fmt" "net/http" "sync" @@ -131,12 +132,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -146,7 +147,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagHostCatalogId == "" { - c.UI.Error("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID") + c.PrintCliError(errors.New("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID")) return 1 } } @@ -154,7 +155,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostsetsClient := hostsets.NewClient(client) @@ -222,7 +223,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = hostsetsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -236,16 +237,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -282,12 +283,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -304,12 +304,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/hostsetscmd/static_hostsets.gen.go b/internal/cmd/commands/hostsetscmd/static_hostsets.gen.go index 7f8aaea20d..a57a36cef5 100644 --- a/internal/cmd/commands/hostsetscmd/static_hostsets.gen.go +++ b/internal/cmd/commands/hostsetscmd/static_hostsets.gen.go @@ -2,6 +2,7 @@ package hostsetscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -112,12 +113,12 @@ func (c *StaticCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsStaticMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -127,7 +128,7 @@ func (c *StaticCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagHostCatalogId == "" { - c.UI.Error("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID") + c.PrintCliError(errors.New("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID")) return 1 } } @@ -135,7 +136,7 @@ func (c *StaticCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } hostsetsClient := hostsets.NewClient(client) @@ -188,16 +189,16 @@ func (c *StaticCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomStaticActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -213,12 +214,7 @@ func (c *StaticCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/rolescmd/roles.gen.go b/internal/cmd/commands/rolescmd/roles.gen.go index a18b43afad..df3a9d725e 100644 --- a/internal/cmd/commands/rolescmd/roles.gen.go +++ b/internal/cmd/commands/rolescmd/roles.gen.go @@ -2,6 +2,7 @@ package rolescmd import ( + "errors" "fmt" "net/http" "sync" @@ -137,12 +138,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -153,13 +154,13 @@ func (c *Command) Run(args []string) int { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } @@ -168,7 +169,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } rolesClient := roles.NewClient(client) @@ -279,7 +280,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = rolesClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -293,16 +294,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -339,12 +340,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -361,12 +361,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/scopescmd/scopes.gen.go b/internal/cmd/commands/scopescmd/scopes.gen.go index 848533822f..a955dc8514 100644 --- a/internal/cmd/commands/scopescmd/scopes.gen.go +++ b/internal/cmd/commands/scopescmd/scopes.gen.go @@ -2,6 +2,7 @@ package scopescmd import ( + "errors" "fmt" "net/http" "sync" @@ -137,12 +138,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -153,13 +154,13 @@ func (c *Command) Run(args []string) int { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } @@ -168,7 +169,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } scopesClient := scopes.NewClient(client) @@ -229,7 +230,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = scopesClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -243,16 +244,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -289,12 +290,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -311,12 +311,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/sessionscmd/sessions.gen.go b/internal/cmd/commands/sessionscmd/sessions.gen.go index bbcaa55a37..5cad72ae22 100644 --- a/internal/cmd/commands/sessionscmd/sessions.gen.go +++ b/internal/cmd/commands/sessionscmd/sessions.gen.go @@ -2,6 +2,7 @@ package sessionscmd import ( + "errors" "fmt" "sync" @@ -119,12 +120,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -134,7 +135,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -142,7 +143,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } sessionsClient := sessions.NewClient(client) @@ -186,16 +187,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -213,12 +214,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -234,12 +234,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/targetscmd/targets.gen.go b/internal/cmd/commands/targetscmd/targets.gen.go index 59fb26dd9f..302b1129e0 100644 --- a/internal/cmd/commands/targetscmd/targets.gen.go +++ b/internal/cmd/commands/targetscmd/targets.gen.go @@ -2,6 +2,7 @@ package targetscmd import ( + "errors" "fmt" "net/http" "os" @@ -137,7 +138,7 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } @@ -147,7 +148,7 @@ func (c *Command) Run(args []string) int { switch c.Func { case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -155,7 +156,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } targetsClient := targets.NewClient(client) @@ -228,7 +229,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = targetsClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -242,16 +243,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -288,12 +289,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -310,12 +310,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/targetscmd/tcp_targets.gen.go b/internal/cmd/commands/targetscmd/tcp_targets.gen.go index 8fd2417886..45e544862a 100644 --- a/internal/cmd/commands/targetscmd/tcp_targets.gen.go +++ b/internal/cmd/commands/targetscmd/tcp_targets.gen.go @@ -2,6 +2,7 @@ package targetscmd import ( + "errors" "fmt" "github.com/hashicorp/boundary/api" @@ -114,12 +115,12 @@ func (c *TcpCommand) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsTcpMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -129,7 +130,7 @@ func (c *TcpCommand) Run(args []string) int { switch c.Func { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } } @@ -137,7 +138,7 @@ func (c *TcpCommand) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } targetsClient := targets.NewClient(client) @@ -195,16 +196,16 @@ func (c *TcpCommand) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomTcpActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -220,12 +221,7 @@ func (c *TcpCommand) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/commands/userscmd/users.gen.go b/internal/cmd/commands/userscmd/users.gen.go index 49905b9552..485e5936f0 100644 --- a/internal/cmd/commands/userscmd/users.gen.go +++ b/internal/cmd/commands/userscmd/users.gen.go @@ -2,6 +2,7 @@ package userscmd import ( + "errors" "fmt" "net/http" "sync" @@ -137,12 +138,12 @@ func (c *Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } @@ -153,13 +154,13 @@ func (c *Command) Run(args []string) int { case "create": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } case "list": if c.FlagScopeId == "" { - c.UI.Error("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID") + c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID")) return 1 } @@ -168,7 +169,7 @@ func (c *Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } usersClient := users.NewClient(client) @@ -255,7 +256,7 @@ func (c *Command) Run(args []string) int { case "delete": _, err = usersClient.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -269,16 +270,16 @@ func (c *Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustomActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -315,12 +316,11 @@ func (c *Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -337,12 +337,7 @@ func (c *Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/cmd/gencli/templates.go b/internal/cmd/gencli/templates.go index 5ea6abd82e..09ab60526d 100644 --- a/internal/cmd/gencli/templates.go +++ b/internal/cmd/gencli/templates.go @@ -81,16 +81,15 @@ var cmdTemplate = template.Must(template.New("").Funcs( package {{ .Pkg }}cmd import ( + "errors" "fmt" "net/http" - "os" "sync" "github.com/hashicorp/boundary/api" "github.com/hashicorp/boundary/api/{{ .Pkg }}" "github.com/hashicorp/boundary/internal/cmd/base" "github.com/hashicorp/boundary/internal/cmd/common" - "github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/boundary/sdk/strutil" "github.com/mitchellh/cli" "github.com/posener/complete" @@ -231,13 +230,13 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { f := c.Flags() if err := f.Parse(args); err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } {{ if .HasId }} if strutil.StrListContains(flags{{ camelCase .SubActionPrefix }}Map[c.Func], "id") && c.FlagId == "" { - c.UI.Error("ID is required but not passed in via -id") + c.PrintCliError(errors.New("ID is required but not passed in via -id")) return 1 } {{ end }} @@ -249,14 +248,14 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { {{ if hasAction .StdActions "create" }} case "create": if c.Flag{{ .Container }}Id == "" { - c.UI.Error("{{ .Container }} ID must be passed in via -{{ kebabCase .Container }}-id or BOUNDARY_{{ envCase .Container }}_ID") + c.PrintCliError(errors.New("{{ .Container }} ID must be passed in via -{{ kebabCase .Container }}-id or BOUNDARY_{{ envCase .Container }}_ID")) return 1 } {{ end }} {{ if hasAction .StdActions "list" }} case "list": if c.Flag{{ .Container }}Id == "" { - c.UI.Error("{{ .Container }} ID must be passed in via -{{ kebabCase .Container }}-id or BOUNDARY_{{ envCase .Container }}_ID") + c.PrintCliError(errors.New("{{ .Container }} ID must be passed in via -{{ kebabCase .Container }}-id or BOUNDARY_{{ envCase .Container }}_ID")) return 1 } {{ end }} @@ -265,7 +264,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { client, err := c.Client() if err != nil { - c.UI.Error(fmt.Sprintf("Error creating API client: %s", err.Error())) + c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error())) return 2 } {{ .Pkg }}Client := {{ .Pkg }}.NewClient(client) @@ -349,7 +348,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { {{ if eq $action "delete" }} case "delete": _, err = {{ $input.Pkg}}Client.Delete(c.Context, c.FlagId, opts...) - if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound { + if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Response().StatusCode() == http.StatusNotFound { existed = false err = nil } @@ -365,16 +364,16 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { if err != nil { if apiErr := api.AsServerError(err); apiErr != nil { - c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, c.plural, base.PrintApiError(apiErr))) + c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural)) return 1 } - c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) + c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error())) return 2 } output, err := printCustom{{ camelCase .SubActionPrefix }}ActionOutput(c) if err != nil { - c.UI.Error(err.Error()) + c.PrintCliError(err) return 1 } if output { @@ -413,12 +412,11 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { c.UI.Output("null") default: - b, err := base.JsonFormatter{}.Format(listedItems) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 + items := make([]interface{}, len(listedItems)) + for i, v := range listedItems { + items[i] = v } - c.UI.Output(string(b)) + return c.PrintJsonItems(listResult, items) } case "table": @@ -436,12 +434,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { c.UI.Output(printItemTable(item)) case "json": - b, err := base.JsonFormatter{}.Format(item) - if err != nil { - c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) - return 1 - } - c.UI.Output(string(b)) + return c.PrintJsonItem(result, item) } return 0 diff --git a/internal/tests/api/accounts/account_test.go b/internal/tests/api/accounts/account_test.go index 600352aece..89ccb7a868 100644 --- a/internal/tests/api/accounts/account_test.go +++ b/internal/tests/api/accounts/account_test.go @@ -183,7 +183,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) // Create another resource with the same name. _, err = accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName("first")) @@ -195,17 +195,17 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = accountClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) _, err = accountClient.Update(tc.Context(), u.Item.Id, u.Item.Version) require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/authmethods/authenticate_test.go b/internal/tests/api/authmethods/authenticate_test.go index d5f73cdba9..3d7e98dec9 100644 --- a/internal/tests/api/authmethods/authenticate_test.go +++ b/internal/tests/api/authmethods/authenticate_test.go @@ -27,5 +27,5 @@ func TestAuthenticate(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValuesf(http.StatusUnauthorized, apiErr.ResponseStatus(), "Expected unauthorized, got %q", apiErr.Message) + assert.EqualValuesf(http.StatusUnauthorized, apiErr.Response().StatusCode(), "Expected unauthorized, got %q", apiErr.Message) } diff --git a/internal/tests/api/authtokens/authtoken_test.go b/internal/tests/api/authtokens/authtoken_test.go index 11af6c098b..c544f30cb7 100644 --- a/internal/tests/api/authtokens/authtoken_test.go +++ b/internal/tests/api/authtokens/authtoken_test.go @@ -143,11 +143,11 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = tokens.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/groups/group_test.go b/internal/tests/api/groups/group_test.go index 0043e0f7c4..b5621c390c 100644 --- a/internal/tests/api/groups/group_test.go +++ b/internal/tests/api/groups/group_test.go @@ -158,7 +158,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) }) } } @@ -200,7 +200,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) // Create another resource with the same name. _, err = groupClient.Create(tc.Context(), tt.scopeId, groups.WithName("first")) @@ -210,19 +210,19 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = groupClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) _, err = groupClient.Update(tc.Context(), g.Item.Id, g.Item.Version) require.Error(err) apiErr = api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) }) } } diff --git a/internal/tests/api/hostcatalogs/host_catalog_test.go b/internal/tests/api/hostcatalogs/host_catalog_test.go index 56ad435dd0..e37dbe13bf 100644 --- a/internal/tests/api/hostcatalogs/host_catalog_test.go +++ b/internal/tests/api/hostcatalogs/host_catalog_test.go @@ -116,7 +116,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } func TestErrors(t *testing.T) { @@ -141,7 +141,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = pc.Create(tc.Context(), "static", proj.GetPublicId(), hostcatalogs.WithName("foo")) require.Error(err) @@ -152,11 +152,11 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = pc.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/hosts/host_test.go b/internal/tests/api/hosts/host_test.go index a4ff9d6e21..85d8ac0b03 100644 --- a/internal/tests/api/hosts/host_test.go +++ b/internal/tests/api/hosts/host_test.go @@ -126,7 +126,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } func TestErrors(t *testing.T) { @@ -154,7 +154,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = hClient.Create(tc.Context(), hc.Item.Id, hosts.WithName("foo"), hosts.WithStaticHostAddress("someaddress")) require.Error(err) @@ -165,11 +165,11 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = hClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/hostsets/host_set_test.go b/internal/tests/api/hostsets/host_set_test.go index 0861b209ac..e445018392 100644 --- a/internal/tests/api/hostsets/host_set_test.go +++ b/internal/tests/api/hostsets/host_set_test.go @@ -163,7 +163,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) require.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } // TODO: Get better coverage for expected errors and error formats. @@ -192,7 +192,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) h, err = hClient.Create(tc.Context(), hc.Item.Id, hostsets.WithName("foo")) require.Error(err) @@ -204,11 +204,11 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = hClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/roles/role_test.go b/internal/tests/api/roles/role_test.go index f0902e4e6b..99074e5560 100644 --- a/internal/tests/api/roles/role_test.go +++ b/internal/tests/api/roles/role_test.go @@ -290,7 +290,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) // Create another resource with the same name. _, err = roleClient.Create(tc.Context(), tt.scopeId, roles.WithName("first")) @@ -302,19 +302,19 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = roleClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) _, err = roleClient.Update(tc.Context(), u.Item.Id, u.Item.Version) require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) }) } } diff --git a/internal/tests/api/scopes/scope_test.go b/internal/tests/api/scopes/scope_test.go index fc92c01d46..114bb5e1f1 100644 --- a/internal/tests/api/scopes/scope_test.go +++ b/internal/tests/api/scopes/scope_test.go @@ -105,7 +105,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } func TestErrors(t *testing.T) { @@ -129,17 +129,17 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = scps.Read(tc.Context(), "p_doesntexis") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = scps.Read(tc.Context(), "invalid id") assert.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/targets/target_test.go b/internal/tests/api/targets/target_test.go index 5c466dd891..ab668f7bf2 100644 --- a/internal/tests/api/targets/target_test.go +++ b/internal/tests/api/targets/target_test.go @@ -159,7 +159,7 @@ func TestCrud(t *testing.T) { assert.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } func TestSet_Errors(t *testing.T) { @@ -183,7 +183,7 @@ func TestSet_Errors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) tar, err = tarClient.Create(tc.Context(), "tcp", proj.GetPublicId(), targets.WithName("foo")) require.Error(err) @@ -195,11 +195,11 @@ func TestSet_Errors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = tarClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/api/users/user_test.go b/internal/tests/api/users/user_test.go index acd0a45cf8..9e2413e65c 100644 --- a/internal/tests/api/users/user_test.go +++ b/internal/tests/api/users/user_test.go @@ -155,7 +155,7 @@ func TestCrud(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) } func TestErrors(t *testing.T) { @@ -178,7 +178,7 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr := api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) // Create another resource with the same name. _, err = userClient.Create(tc.Context(), org.GetPublicId(), users.WithName("first")) @@ -190,17 +190,17 @@ func TestErrors(t *testing.T) { require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode()) _, err = userClient.Read(tc.Context(), "invalid id") require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) _, err = userClient.Update(tc.Context(), u.Item.Id, u.Item.Version) require.Error(err) apiErr = api.AsServerError(err) assert.NotNil(apiErr) - assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus()) + assert.EqualValues(http.StatusBadRequest, apiErr.Response().StatusCode()) } diff --git a/internal/tests/cli/boundary/_accounts.bash b/internal/tests/cli/boundary/_accounts.bash index 62875cf13a..7eb06ead88 100644 --- a/internal/tests/cli/boundary/_accounts.bash +++ b/internal/tests/cli/boundary/_accounts.bash @@ -16,5 +16,5 @@ function list_accounts() { function account_id() { local acct=$1 - strip $(list_accounts | jq -c ".[] | select(.attributes.login_name | contains(\"$acct\")) | .[\"id\"]") + strip $(list_accounts | jq -c ".items[] | select(.attributes.login_name | contains(\"$acct\")) | .[\"id\"]") } diff --git a/internal/tests/cli/boundary/_authorized_actions.bash b/internal/tests/cli/boundary/_authorized_actions.bash index 87201afbd7..7e5d4dd29c 100644 --- a/internal/tests/cli/boundary/_authorized_actions.bash +++ b/internal/tests/cli/boundary/_authorized_actions.bash @@ -4,5 +4,5 @@ function has_authorized_action() { # has_authorized_action $out authorize-session local out=$1 local action=$2 - echo $out | jq -c ".authorized_actions | contains([\"$action\"])" + echo $out | jq -c ".item.authorized_actions | contains([\"$action\"])" } diff --git a/internal/tests/cli/boundary/_groups.bash b/internal/tests/cli/boundary/_groups.bash index c50841f32e..ec7b721792 100644 --- a/internal/tests/cli/boundary/_groups.bash +++ b/internal/tests/cli/boundary/_groups.bash @@ -22,12 +22,12 @@ function assoc_group_acct() { function group_id() { local group=$1 - strip $(list_groups | jq -c ".[] | select(.name | contains(\"$group\")) | .[\"id\"]") + strip $(list_groups | jq -c ".items[] | select(.name | contains(\"$group\")) | .[\"id\"]") } function group_member_ids() { local gid=$1 - boundary groups read -id $gid -format json | jq '.["members"][]["id"]' + boundary groups read -id $gid -format json | jq '.item["members"][]["id"]' } function group_has_member_id() { diff --git a/internal/tests/cli/boundary/_host_catalogs.bash b/internal/tests/cli/boundary/_host_catalogs.bash index 39fac394ac..fdfe55a4cf 100644 --- a/internal/tests/cli/boundary/_host_catalogs.bash +++ b/internal/tests/cli/boundary/_host_catalogs.bash @@ -25,7 +25,7 @@ function list_host_catalogs() { function host_catalog_id() { local id=$1 local sid=$2 - strip $(list_host_catalogs $sid | jq -c ".[] | select(.name | contains(\"$id\")) | .[\"id\"]") + strip $(list_host_catalogs $sid | jq -c ".items[] | select(.name | contains(\"$id\")) | .[\"id\"]") } function has_default_host_catalog_actions() { diff --git a/internal/tests/cli/boundary/_host_sets.bash b/internal/tests/cli/boundary/_host_sets.bash index 00d2355e86..2dbc2e429a 100644 --- a/internal/tests/cli/boundary/_host_sets.bash +++ b/internal/tests/cli/boundary/_host_sets.bash @@ -28,12 +28,12 @@ function assoc_host_set_host() { function host_set_id() { local name=$1 local hcid=$2 - strip $(list_host_sets $hcid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]") + strip $(list_host_sets $hcid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]") } function host_set_host_ids() { local id=$1 - ids=$(read_host_set $id | jq '.["host_ids"]') + ids=$(read_host_set $id | jq '.item["host_ids"]') echo "ids $ids" } diff --git a/internal/tests/cli/boundary/_hosts.bash b/internal/tests/cli/boundary/_hosts.bash index d9e4ad736a..7be00c4ef9 100644 --- a/internal/tests/cli/boundary/_hosts.bash +++ b/internal/tests/cli/boundary/_hosts.bash @@ -27,7 +27,7 @@ function host_id() { local name=$1 local hcid=$2 - strip $(list_hosts $hcid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]") + strip $(list_hosts $hcid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]") } function has_default_host_actions() { diff --git a/internal/tests/cli/boundary/_roles.bash b/internal/tests/cli/boundary/_roles.bash index 04ce78eb18..55b026f112 100644 --- a/internal/tests/cli/boundary/_roles.bash +++ b/internal/tests/cli/boundary/_roles.bash @@ -55,12 +55,12 @@ function remove_role_principal() { function role_id() { local name=$1 local sid=$2 - strip $(list_roles $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]") + strip $(list_roles $sid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]") } function role_principal_ids() { local rid=$1 - strip $(read_role $rid | jq '.["principals"][]["id"]') + strip $(read_role $rid | jq '.item["principals"][]["id"]') } function role_has_principal_id() { @@ -77,7 +77,7 @@ function role_has_principal_id() { function role_grants() { local rid=$1 - read_role $rid | jq -rc '.grant_strings | @sh' + read_role $rid | jq -rc '.item.grant_strings | @sh' } function role_has_grant() { diff --git a/internal/tests/cli/boundary/_scopes.bash b/internal/tests/cli/boundary/_scopes.bash index 2d595a2e24..84032c3524 100644 --- a/internal/tests/cli/boundary/_scopes.bash +++ b/internal/tests/cli/boundary/_scopes.bash @@ -27,7 +27,7 @@ function scope_id() { local name=$1 local sid=$2 - strip $(list_scopes $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]") + strip $(list_scopes $sid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]") } function has_default_scope_actions() { diff --git a/internal/tests/cli/boundary/_sessions.bash b/internal/tests/cli/boundary/_sessions.bash index 1d1b7b7d47..176fc53ffd 100644 --- a/internal/tests/cli/boundary/_sessions.bash +++ b/internal/tests/cli/boundary/_sessions.bash @@ -5,7 +5,7 @@ function list_sessions() { } function count_sessions() { - list_sessions $1 | jq '. | length' + list_sessions $1 | jq '.items | length' } function cancel_session() { @@ -14,4 +14,4 @@ function cancel_session() { function read_session() { boundary sessions read -id $1 -} \ No newline at end of file +} diff --git a/internal/tests/cli/boundary/_targets.bash b/internal/tests/cli/boundary/_targets.bash index 05c5b1ca2a..a54f779b6e 100644 --- a/internal/tests/cli/boundary/_targets.bash +++ b/internal/tests/cli/boundary/_targets.bash @@ -34,12 +34,12 @@ function assoc_host_sets() { function target_id_from_name() { local sid=$1 local name=$2 - strip $(list_targets $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]") + strip $(list_targets $sid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]") } function target_host_set_ids() { local tid=$1 - boundary targets read -id $tid -format json | jq '.host_sets[].id' + boundary targets read -id $tid -format json | jq '.item.host_sets[].id' } function target_has_host_set_id() { diff --git a/internal/tests/cli/boundary/_users.bash b/internal/tests/cli/boundary/_users.bash index 7a29ec87ef..315bef4b9b 100644 --- a/internal/tests/cli/boundary/_users.bash +++ b/internal/tests/cli/boundary/_users.bash @@ -35,5 +35,5 @@ function has_default_user_actions() { function user_id() { local user=$1 - strip $(list_users | jq -c ".[] | select(.name | contains(\"$user\")) | .[\"id\"]") + strip $(list_users | jq -c ".items[] | select(.name | contains(\"$user\")) | .[\"id\"]") } diff --git a/internal/tests/cli/boundary/sessions.bats b/internal/tests/cli/boundary/sessions.bats index 24e2282c1e..ff8da93fbf 100644 --- a/internal/tests/cli/boundary/sessions.bats +++ b/internal/tests/cli/boundary/sessions.bats @@ -59,7 +59,7 @@ load _helpers [ "$status" -eq 0 ] run list_sessions $DEFAULT_P_ID [ "$status" -eq 0 ] - id=$(echo "$output" | jq -r '[.[]|select(.user_id == "u_1234567890")][0].id') + id=$(echo "$output" | jq -r '[.items[]|select(.user_id == "u_1234567890")][0].id') # Check unpriv cannot read or cancel an admin's session run login $DEFAULT_UNPRIVILEGED_LOGIN @@ -86,7 +86,7 @@ load _helpers [ "$status" -eq 0 ] run list_sessions $DEFAULT_P_ID [ "$status" -eq 0 ] - id=$(echo "$output" | jq -r '[.[]|select(.user_id == "u_0987654321")][0].id') + id=$(echo "$output" | jq -r '[.items[]|select(.user_id == "u_0987654321")][0].id') # Check unpriv can read and cancel their own session run login $DEFAULT_UNPRIVILEGED_LOGIN diff --git a/website/content/docs/getting-started/index.mdx b/website/content/docs/getting-started/index.mdx index 00c102a875..6121b22878 100644 --- a/website/content/docs/getting-started/index.mdx +++ b/website/content/docs/getting-started/index.mdx @@ -17,7 +17,7 @@ The examples in Getting Started all revolve around running in `dev mode`. There 1. A route to download the [Postgres Docker image](https://hub.docker.com/_/postgres) is available or a local image cache is available 1. A [Boundary binary](https://www.boundaryproject.io/downloads) in your `$PATH` 1. Optionally, an [installation of Boundary Desktop](/docs/api-clients/desktop#install-boundary-desktop) if you want to use the -desktop examples + desktop examples ## What is Dev Mode?