50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package scopes
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
)
|
|
|
|
// 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")
|
|
}
|
|
|
|
if s.Client == nil {
|
|
return false, nil, fmt.Errorf("nil client in DeleteScope 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, "DELETE", fmt.Sprintf("%s/%s", "scopes", id), nil, opts...)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error creating DeleteScope request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
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 {
|
|
return false, nil, fmt.Errorf("error decoding DeleteScope repsonse: %w", err)
|
|
}
|
|
|
|
return target.Existed, apiErr, nil
|
|
}
|