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

87 lines
2.2 KiB
Go
Raw Normal View History

2020-05-12 17:35:48 -07:00
// Code generated by "make api"; DO NOT EDIT.
package scopes
import (
"context"
"fmt"
"github.com/hashicorp/watchtower/api"
2020-06-05 13:02:58 -07:00
"github.com/hashicorp/watchtower/api/hosts"
2020-05-12 17:35:48 -07:00
)
2020-06-05 13:02:58 -07:00
func (s Organization) CreateProject(ctx context.Context, r *Project) (*Project, *api.Error, error) {
2020-05-12 17:35:48 -07:00
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)
}
2020-06-05 13:02:58 -07:00
req, err := s.Client.NewRequest(ctx, "POST", "projects", r)
2020-05-12 17:35:48 -07:00
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
}
2020-06-05 13:02:58 -07:00
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
}