Files
threshold/api/authtokens/authtokens.gen.go
T
2020-08-12 17:34:56 -04:00

124 lines
3.5 KiB
Go

// Code generated by "make api"; DO NOT EDIT.
package authtokens
import (
"context"
"fmt"
"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 AuthTokensClient struct {
client *api.Client
}
func NewAuthTokensClient(c *api.Client) *AuthTokensClient {
return &AuthTokensClient{client: c}
}
func (c *AuthTokensClient) 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")
}
_, 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)
}
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)
}
return target, apiErr, nil
}
func (c *AuthTokensClient) 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")
}
_, 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)
}
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)
}
return target.Existed, apiErr, nil
}
func (c *AuthTokensClient) List(ctx context.Context, opt ...Option) ([]*AuthToken, *api.Error, error) {
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
_, 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)
}
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)
}
return target.Items, apiErr, nil
}