43 lines
1018 B
Go
43 lines
1018 B
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package users
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
)
|
|
|
|
func (s User) CreateUser(ctx context.Context, r *User) (*User, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in CreateUser 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, "POST", "users", r, opts...)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating CreateUser request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during CreateUser call: %w", err)
|
|
}
|
|
|
|
target := new(User)
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding CreateUser repsonse: %w", err)
|
|
}
|
|
|
|
target.Client = s.Client
|
|
|
|
return target, apiErr, nil
|
|
}
|