Files
threshold/api/scopes/list.gen.go
T

51 lines
1.1 KiB
Go
Raw Normal View History

2020-07-02 10:26:31 -07:00
// Code generated by "make api"; DO NOT EDIT.
package scopes
import (
"context"
"fmt"
"github.com/hashicorp/watchtower/api"
)
2020-07-22 00:14:28 -04:00
func (s Scope) ListScopes(ctx context.Context) ([]*Scope, *api.Error, error) {
2020-07-02 10:26:31 -07:00
if s.Client == nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("nil client in ListScope request")
2020-07-02 10:26:31 -07:00
}
2020-07-22 00:14:28 -04:00
var opts []api.Option
if s.Scope.Id != "" {
2020-07-02 10:26:31 -07:00
// If it's explicitly set here, override anything that might be in the
// client
2020-07-22 00:14:28 -04:00
opts = append(opts, api.WithScopeId(s.Scope.Id))
2020-07-02 10:26:31 -07:00
}
2020-07-22 00:14:28 -04:00
req, err := s.Client.NewRequest(ctx, "GET", "scopes", nil, opts...)
2020-07-02 10:26:31 -07:00
if err != nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("error creating ListScopes request: %w", err)
2020-07-02 10:26:31 -07:00
}
resp, err := s.Client.Do(req)
if err != nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("error performing client request during ListScopes call: %w", err)
2020-07-02 10:26:31 -07:00
}
type listResponse struct {
2020-07-22 00:14:28 -04:00
Items []*Scope
2020-07-02 10:26:31 -07:00
}
target := &listResponse{}
apiErr, err := resp.Decode(target)
if err != nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("error decoding ListScopes response: %w", err)
2020-07-02 10:26:31 -07:00
}
for _, t := range target.Items {
t.Client = s.Client.Clone()
2020-07-22 00:14:28 -04:00
t.Client.SetScopeId(t.Id)
2020-07-02 10:26:31 -07:00
}
return target.Items, apiErr, nil
}