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

49 lines
1.3 KiB
Go
Raw Normal View History

2020-05-20 08:04:23 -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
// DeleteScope returns true iff the Scope existed when the delete attempt was made.
func (s Scope) DeleteScope(ctx context.Context, id string) (bool, *api.Error, error) {
if id == "" {
return false, nil, fmt.Errorf("empty id provided to DeleteScope request")
2020-06-09 11:20:59 -07:00
}
2020-06-05 13:02:58 -07:00
if s.Client == nil {
2020-07-22 00:14:28 -04:00
return false, nil, fmt.Errorf("nil client in DeleteScope request")
2020-06-05 13:02:58 -07:00
}
2020-07-22 00:14:28 -04:00
var opts []api.Option
if s.Scope.Id != "" {
2020-06-05 13:02:58 -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-22 00:14:28 -04:00
req, err := s.Client.NewRequest(ctx, "DELETE", fmt.Sprintf("%s/%s", "scopes", id), nil, opts...)
if err != nil {
2020-07-22 00:14:28 -04:00
return false, nil, fmt.Errorf("error creating DeleteScope request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
2020-07-22 00:14:28 -04:00
return false, nil, fmt.Errorf("error performing client request during DeleteScope call: %w", err)
}
type deleteResponse struct {
Existed bool
}
target := &deleteResponse{}
apiErr, err := resp.Decode(target)
if err != nil {
2020-07-22 00:14:28 -04:00
return false, nil, fmt.Errorf("error decoding DeleteScope repsonse: %w", err)
}
return target.Existed, apiErr, nil
}