51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package authtokens
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
)
|
|
|
|
func (s AuthToken) ListAuthTokens(ctx context.Context) ([]*AuthToken, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in ListAuthToken request")
|
|
}
|
|
|
|
var opts []api.Option
|
|
if s.Scope.Id != "" {
|
|
// If it's explicitly set here, override anything that might be in the
|
|
// client
|
|
opts = append(opts, api.WithScopeId(s.Scope.Id))
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "GET", "auth-tokens", nil, opts...)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating ListAuthTokens request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during ListAuthTokens 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 ListAuthTokens response: %w", err)
|
|
}
|
|
|
|
for _, t := range target.Items {
|
|
|
|
t.Client = s.Client
|
|
|
|
}
|
|
|
|
return target.Items, apiErr, nil
|
|
}
|