2020-08-07 12:55:02 -04:00
|
|
|
// Code generated by "make api"; DO NOT EDIT.
|
|
|
|
|
package authtokens
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
2020-08-26 23:27:25 -04:00
|
|
|
"net/url"
|
2020-08-07 12:55:02 -04:00
|
|
|
"time"
|
|
|
|
|
|
2020-08-10 17:15:02 -04:00
|
|
|
"github.com/hashicorp/boundary/api"
|
|
|
|
|
"github.com/hashicorp/boundary/api/scopes"
|
2020-08-07 12:55:02 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type AuthToken struct {
|
|
|
|
|
Id string `json:"id,omitempty"`
|
2020-09-02 19:43:41 -07:00
|
|
|
ScopeId string `json:"scope_id,omitempty"`
|
2020-08-07 12:55:02 -04:00
|
|
|
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
|
|
|
|
Token string `json:"token,omitempty"`
|
|
|
|
|
UserId string `json:"user_id,omitempty"`
|
|
|
|
|
AuthMethodId string `json:"auth_method_id,omitempty"`
|
2020-09-15 14:33:38 -07:00
|
|
|
AccountId string `json:"account_id,omitempty"`
|
2020-08-07 12:55:02 -04:00
|
|
|
CreatedTime time.Time `json:"created_time,omitempty"`
|
|
|
|
|
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
|
|
|
|
ApproximateLastUsedTime time.Time `json:"approximate_last_used_time,omitempty"`
|
|
|
|
|
ExpirationTime time.Time `json:"expiration_time,omitempty"`
|
2021-01-20 10:53:01 -05:00
|
|
|
AuthorizedActions []string `json:"authorized_actions,omitempty"`
|
2020-09-11 00:51:55 -04:00
|
|
|
|
2020-12-07 14:25:16 -07:00
|
|
|
response *api.Response
|
2020-09-11 00:51:55 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 01:08:21 -04:00
|
|
|
type AuthTokenReadResult struct {
|
2020-12-07 14:25:16 -07:00
|
|
|
Item *AuthToken
|
|
|
|
|
response *api.Response
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n AuthTokenReadResult) GetItem() interface{} {
|
|
|
|
|
return n.Item
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 12:39:51 -05:00
|
|
|
func (n AuthTokenReadResult) GetResponse() *api.Response {
|
|
|
|
|
return n.response
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-07 10:02:32 -05:00
|
|
|
type (
|
|
|
|
|
AuthTokenCreateResult = AuthTokenReadResult
|
|
|
|
|
AuthTokenUpdateResult = AuthTokenReadResult
|
|
|
|
|
)
|
2020-09-15 01:08:21 -04:00
|
|
|
|
|
|
|
|
type AuthTokenDeleteResult struct {
|
2020-12-07 14:25:16 -07:00
|
|
|
response *api.Response
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:38:55 -05:00
|
|
|
// GetItem will always be nil for AuthTokenDeleteResult
|
|
|
|
|
func (n AuthTokenDeleteResult) GetItem() interface{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 12:39:51 -05:00
|
|
|
func (n AuthTokenDeleteResult) GetResponse() *api.Response {
|
|
|
|
|
return n.response
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AuthTokenListResult struct {
|
2020-12-07 14:25:16 -07:00
|
|
|
Items []*AuthToken
|
|
|
|
|
response *api.Response
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n AuthTokenListResult) GetItems() interface{} {
|
|
|
|
|
return n.Items
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 12:39:51 -05:00
|
|
|
func (n AuthTokenListResult) GetResponse() *api.Response {
|
|
|
|
|
return n.response
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-08 13:27:51 -07:00
|
|
|
// Client is a client for this collection
|
2020-08-27 20:43:33 -04:00
|
|
|
type Client struct {
|
2020-08-07 12:55:02 -04:00
|
|
|
client *api.Client
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 13:27:51 -07:00
|
|
|
// Creates a new client for this collection. The submitted API client is cloned;
|
|
|
|
|
// modifications to it after generating this client will not have effect. If you
|
|
|
|
|
// need to make changes to the underlying API client, use ApiClient() to access
|
|
|
|
|
// it.
|
2020-08-27 20:43:33 -04:00
|
|
|
func NewClient(c *api.Client) *Client {
|
2020-09-08 13:27:51 -07:00
|
|
|
return &Client{client: c.Clone()}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ApiClient returns the underlying API client
|
|
|
|
|
func (c *Client) ApiClient() *api.Client {
|
|
|
|
|
return c.client
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
func (c *Client) Read(ctx context.Context, id string, opt ...Option) (*AuthTokenReadResult, error) {
|
|
|
|
|
if id == "" {
|
|
|
|
|
return nil, fmt.Errorf("empty id value passed into Read request")
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
if c.client == nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("nil client")
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
opts, apiOpts := getOpts(opt...)
|
2020-08-07 12:55:02 -04:00
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-tokens/%s", id), nil, apiOpts...)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error creating Read request: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
if len(opts.queryMap) > 0 {
|
|
|
|
|
q := url.Values{}
|
|
|
|
|
for k, v := range opts.queryMap {
|
|
|
|
|
q.Add(k, v)
|
|
|
|
|
}
|
|
|
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-08 17:30:41 -05:00
|
|
|
resp, err := c.client.Do(req, apiOpts...)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error performing client request during Read call: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 01:08:21 -04:00
|
|
|
target := new(AuthTokenReadResult)
|
|
|
|
|
target.Item = new(AuthToken)
|
|
|
|
|
apiErr, err := resp.Decode(target.Item)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error decoding Read response: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
2020-08-20 17:31:38 -04:00
|
|
|
if apiErr != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, apiErr
|
2020-08-20 17:31:38 -04:00
|
|
|
}
|
2020-12-07 14:25:16 -07:00
|
|
|
target.response = resp
|
2020-09-24 14:34:58 -07:00
|
|
|
return target, nil
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
func (c *Client) Delete(ctx context.Context, id string, opt ...Option) (*AuthTokenDeleteResult, error) {
|
|
|
|
|
if id == "" {
|
|
|
|
|
return nil, fmt.Errorf("empty id value passed into Delete request")
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
if c.client == nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("nil client")
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
opts, apiOpts := getOpts(opt...)
|
2020-08-07 12:55:02 -04:00
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-tokens/%s", id), nil, apiOpts...)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error creating Delete request: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
if len(opts.queryMap) > 0 {
|
|
|
|
|
q := url.Values{}
|
|
|
|
|
for k, v := range opts.queryMap {
|
|
|
|
|
q.Add(k, v)
|
|
|
|
|
}
|
|
|
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 12:55:02 -04:00
|
|
|
resp, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error performing client request during Delete call: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-08 23:57:26 -04:00
|
|
|
apiErr, err := resp.Decode(nil)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error decoding Delete response: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
2020-08-20 17:31:38 -04:00
|
|
|
if apiErr != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, apiErr
|
2020-08-20 17:31:38 -04:00
|
|
|
}
|
2020-09-15 01:08:21 -04:00
|
|
|
|
|
|
|
|
target := &AuthTokenDeleteResult{
|
2020-12-07 14:25:16 -07:00
|
|
|
response: resp,
|
2020-09-15 01:08:21 -04:00
|
|
|
}
|
2020-09-24 14:34:58 -07:00
|
|
|
return target, nil
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-24 14:34:58 -07:00
|
|
|
func (c *Client) List(ctx context.Context, scopeId string, opt ...Option) (*AuthTokenListResult, error) {
|
2020-09-08 13:27:51 -07:00
|
|
|
if scopeId == "" {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("empty scopeId value passed into List request")
|
2020-09-08 13:27:51 -07:00
|
|
|
}
|
2020-08-07 12:55:02 -04:00
|
|
|
if c.client == nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("nil client")
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
opts, apiOpts := getOpts(opt...)
|
2020-09-08 13:27:51 -07:00
|
|
|
opts.queryMap["scope_id"] = scopeId
|
2020-08-07 12:55:02 -04:00
|
|
|
|
2020-08-07 17:56:55 -04:00
|
|
|
req, err := c.client.NewRequest(ctx, "GET", "auth-tokens", nil, apiOpts...)
|
2020-08-07 12:55:02 -04:00
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error creating List request: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-26 23:27:25 -04:00
|
|
|
if len(opts.queryMap) > 0 {
|
|
|
|
|
q := url.Values{}
|
|
|
|
|
for k, v := range opts.queryMap {
|
|
|
|
|
q.Add(k, v)
|
|
|
|
|
}
|
|
|
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 12:55:02 -04:00
|
|
|
resp, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error performing client request during List call: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 01:08:21 -04:00
|
|
|
target := new(AuthTokenListResult)
|
2020-08-07 12:55:02 -04:00
|
|
|
apiErr, err := resp.Decode(target)
|
|
|
|
|
if err != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, fmt.Errorf("error decoding List response: %w", err)
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|
2020-08-20 17:31:38 -04:00
|
|
|
if apiErr != nil {
|
2020-09-24 14:34:58 -07:00
|
|
|
return nil, apiErr
|
2020-08-20 17:31:38 -04:00
|
|
|
}
|
2020-12-07 14:25:16 -07:00
|
|
|
target.response = resp
|
2020-09-24 14:34:58 -07:00
|
|
|
return target, nil
|
2020-08-07 12:55:02 -04:00
|
|
|
}
|