* Create user handler stuff. * Fixing Not Found errors from DB. * Fixing param names. * Update the proto's go package generation. * Generate the user resource. * Adding SDK methods for users. * Fix the base type of Users and add tests. * Connect user service to the controller handler. * Attach the default org to the Test Controller's client. * Take into account the provided request paths when the client builds the org/project path prefix. * Adding comments to the API. * rename repo function to repoFn. * Fix typo in update mask errors. * Clean up tests. * Remove special checks for request url content in the api client and fix CORS test.
127 lines
3.2 KiB
Go
127 lines
3.2 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package scopes
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
"github.com/hashicorp/watchtower/api/hosts"
|
|
"github.com/hashicorp/watchtower/api/users"
|
|
)
|
|
|
|
func (s Organization) CreateProject(ctx context.Context, r *Project) (*Project, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in CreateProject request")
|
|
}
|
|
if s.Id == "" {
|
|
|
|
// Assume the client has been configured with organization already and
|
|
// move on
|
|
|
|
} else {
|
|
// If it's explicitly set here, override anything that might be in the
|
|
// client
|
|
|
|
ctx = context.WithValue(ctx, "org", s.Id)
|
|
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "POST", "projects", r)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating CreateProject request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during CreateProject call: %w", err)
|
|
}
|
|
|
|
target := new(Project)
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding CreateProject repsonse: %w", err)
|
|
}
|
|
|
|
target.Client = s.Client.Clone()
|
|
target.Client.SetProject(target.Id)
|
|
|
|
return target, apiErr, nil
|
|
}
|
|
|
|
func (s Organization) CreateUser(ctx context.Context, r *users.User) (*users.User, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in Createusers.User request")
|
|
}
|
|
if s.Id == "" {
|
|
|
|
// Assume the client has been configured with organization already and
|
|
// move on
|
|
|
|
} else {
|
|
// If it's explicitly set here, override anything that might be in the
|
|
// client
|
|
|
|
ctx = context.WithValue(ctx, "org", s.Id)
|
|
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "POST", "users", r)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating Createusers.User request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during Createusers.User call: %w", err)
|
|
}
|
|
|
|
target := new(users.User)
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding Createusers.User repsonse: %w", err)
|
|
}
|
|
|
|
target.Client = s.Client
|
|
|
|
return target, apiErr, nil
|
|
}
|
|
|
|
func (s Project) CreateHostCatalog(ctx context.Context, r *hosts.HostCatalog) (*hosts.HostCatalog, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in Createhosts.HostCatalog request")
|
|
}
|
|
if s.Id == "" {
|
|
|
|
// Assume the client has been configured with project already and move
|
|
// on
|
|
|
|
} else {
|
|
// If it's explicitly set here, override anything that might be in the
|
|
// client
|
|
|
|
ctx = context.WithValue(ctx, "project", s.Id)
|
|
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "POST", "host-catalogs", r)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error creating Createhosts.HostCatalog request: %w", err)
|
|
}
|
|
|
|
resp, err := s.Client.Do(req)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error performing client request during Createhosts.HostCatalog call: %w", err)
|
|
}
|
|
|
|
target := new(hosts.HostCatalog)
|
|
apiErr, err := resp.Decode(target)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("error decoding Createhosts.HostCatalog repsonse: %w", err)
|
|
}
|
|
|
|
target.Client = s.Client
|
|
|
|
return target, apiErr, nil
|
|
}
|