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

53 lines
1.2 KiB
Go
Raw Normal View History

2020-05-19 12:10:39 -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) UpdateScope(ctx context.Context, r *Scope) (*Scope, *api.Error, error) {
if r == nil {
2020-05-19 12:10:39 -07:00
}
2020-07-22 00:14:28 -04:00
if r.Id == "" {
return nil, nil, fmt.Errorf("empty Scope ID field in CreateScope request")
2020-05-19 12:10:39 -07:00
}
2020-06-15 15:22:41 -07:00
if s.Client == nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("nil client in CreateScope request")
2020-06-15 15:22:41 -07:00
}
2020-07-22 00:14:28 -04:00
var opts []api.Option
if s.Scope.Id != "" {
2020-06-15 15:22:41 -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-06-15 15:22:41 -07:00
}
id := r.Id
r.Id = ""
2020-07-22 00:14:28 -04:00
req, err := s.Client.NewRequest(ctx, "PATCH", fmt.Sprintf("%s/%s", "scopes", id), r, opts...)
2020-06-15 15:22:41 -07:00
if err != nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("error creating CreateScope request: %w", err)
2020-06-15 15:22:41 -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 UpdateScope call: %w", err)
2020-06-15 15:22:41 -07:00
}
2020-07-22 00:14:28 -04:00
target := new(Scope)
2020-06-15 15:22:41 -07:00
apiErr, err := resp.Decode(target)
if err != nil {
2020-07-22 00:14:28 -04:00
return nil, nil, fmt.Errorf("error decoding UpdateScope repsonse: %w", err)
2020-06-15 15:22:41 -07:00
}
2020-07-22 00:14:28 -04:00
target.Client = s.Client.Clone()
target.Client.SetScopeId(target.Id)
return target, apiErr, nil
}