155 lines
4.0 KiB
Go
155 lines
4.0 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package authtokens
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
"github.com/hashicorp/boundary/api/scopes"
|
|
)
|
|
|
|
type AuthToken struct {
|
|
Id string `json:"id,omitempty"`
|
|
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
|
Token string `json:"token,omitempty"`
|
|
UserId string `json:"user_id,omitempty"`
|
|
AuthMethodId string `json:"auth_method_id,omitempty"`
|
|
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"`
|
|
}
|
|
|
|
type Client struct {
|
|
client *api.Client
|
|
}
|
|
|
|
func NewClient(c *api.Client) *Client {
|
|
return &Client{client: c}
|
|
}
|
|
|
|
func (c *Client) Read(ctx context.Context, authTokenId string, opt ...Option) (*AuthToken, *api.Error, error) {
|
|
if authTokenId == "" {
|
|
return nil, nil, fmt.Errorf("empty authTokenId value passed into Read request")
|
|
}
|
|
|
|
if c.client == nil {
|
|
return nil, nil, fmt.Errorf("nil client")
|
|
}
|
|
|
|
opts, apiOpts := getOpts(opt...)
|
|
|
|
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-tokens/%s", authTokenId), nil, apiOpts...)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
|
|
}
|
|
|
|
if len(opts.queryMap) > 0 {
|
|
q := url.Values{}
|
|
for k, v := range opts.queryMap {
|
|
q.Add(k, v)
|
|
}
|
|
req.URL.RawQuery = q.Encode()
|
|
}
|
|
|
|
resp, err := c.client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
|
|
}
|
|
|
|
target := new(AuthToken)
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding Read response: %w", err)
|
|
}
|
|
if apiErr != nil {
|
|
return nil, apiErr, nil
|
|
}
|
|
return target, apiErr, nil
|
|
}
|
|
|
|
func (c *Client) Delete(ctx context.Context, authTokenId string, opt ...Option) (bool, *api.Error, error) {
|
|
if authTokenId == "" {
|
|
return false, nil, fmt.Errorf("empty authTokenId value passed into Delete request")
|
|
}
|
|
|
|
if c.client == nil {
|
|
return false, nil, fmt.Errorf("nil client")
|
|
}
|
|
|
|
opts, apiOpts := getOpts(opt...)
|
|
|
|
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-tokens/%s", authTokenId), nil, apiOpts...)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
|
|
}
|
|
|
|
if len(opts.queryMap) > 0 {
|
|
q := url.Values{}
|
|
for k, v := range opts.queryMap {
|
|
q.Add(k, v)
|
|
}
|
|
req.URL.RawQuery = q.Encode()
|
|
}
|
|
|
|
resp, err := c.client.Do(req)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
|
|
}
|
|
|
|
type deleteResponse struct {
|
|
Existed bool
|
|
}
|
|
target := &deleteResponse{}
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error decoding Delete response: %w", err)
|
|
}
|
|
if apiErr != nil {
|
|
return false, apiErr, nil
|
|
}
|
|
return target.Existed, apiErr, nil
|
|
}
|
|
|
|
func (c *Client) List(ctx context.Context, opt ...Option) ([]*AuthToken, *api.Error, error) {
|
|
if c.client == nil {
|
|
return nil, nil, fmt.Errorf("nil client")
|
|
}
|
|
|
|
opts, apiOpts := getOpts(opt...)
|
|
|
|
req, err := c.client.NewRequest(ctx, "GET", "auth-tokens", nil, apiOpts...)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating List request: %w", err)
|
|
}
|
|
|
|
if len(opts.queryMap) > 0 {
|
|
q := url.Values{}
|
|
for k, v := range opts.queryMap {
|
|
q.Add(k, v)
|
|
}
|
|
req.URL.RawQuery = q.Encode()
|
|
}
|
|
|
|
resp, err := c.client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
|
|
}
|
|
|
|
type listResponse struct {
|
|
Items []*AuthToken
|
|
}
|
|
target := &listResponse{}
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding List response: %w", err)
|
|
}
|
|
if apiErr != nil {
|
|
return nil, apiErr, nil
|
|
}
|
|
return target.Items, apiErr, nil
|
|
}
|