50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package roles
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
)
|
|
|
|
// DeleteRole returns true iff the Role existed when the delete attempt was made.
|
|
func (s Role) DeleteRole(ctx context.Context, id string) (bool, *api.Error, error) {
|
|
if id == "" {
|
|
return false, nil, fmt.Errorf("empty id provided to DeleteRole request")
|
|
}
|
|
|
|
if s.Client == nil {
|
|
return false, nil, fmt.Errorf("nil client in DeleteRole 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", "roles", id), nil, opts...)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error creating DeleteRole request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return false, nil, fmt.Errorf("error performing client request during DeleteRole 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 DeleteRole repsonse: %w", err)
|
|
}
|
|
|
|
return target.Existed, apiErr, nil
|
|
}
|