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

79 lines
2.0 KiB
Go
Raw Normal View History

// Code generated by "make api"; DO NOT EDIT.
package hosts
import (
"context"
"fmt"
"github.com/hashicorp/watchtower/api"
)
2020-06-05 13:02:58 -07:00
func (s HostCatalog) CreateHost(ctx context.Context, r *Host) (*Host, *api.Error, error) {
if s.Client == nil {
return nil, nil, fmt.Errorf("nil client in CreateHost request")
}
2020-05-05 14:13:08 -04:00
if s.Id == "" {
2020-05-12 17:35:48 -07:00
return nil, nil, fmt.Errorf("missing HostCatalog ID in CreateHost request")
} else {
// If it's explicitly set here, override anything that might be in the
// client
}
2020-06-05 13:02:58 -07:00
req, err := s.Client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/hosts", s.Id), r)
if err != nil {
return nil, nil, fmt.Errorf("error creating CreateHost request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during CreateHost call: %w", err)
}
target := new(Host)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding CreateHost repsonse: %w", err)
}
2020-05-12 17:35:48 -07:00
target.Client = s.Client
return target, apiErr, nil
}
2020-06-05 13:02:58 -07:00
func (s HostCatalog) CreateHostSet(ctx context.Context, r *HostSet) (*HostSet, *api.Error, error) {
if s.Client == nil {
return nil, nil, fmt.Errorf("nil client in CreateHostSet request")
}
2020-05-05 14:13:08 -04:00
if s.Id == "" {
2020-05-12 17:35:48 -07:00
return nil, nil, fmt.Errorf("missing HostCatalog ID in CreateHostSet request")
} else {
// If it's explicitly set here, override anything that might be in the
// client
}
2020-06-05 13:02:58 -07:00
req, err := s.Client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets", s.Id), r)
if err != nil {
return nil, nil, fmt.Errorf("error creating CreateHostSet request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during CreateHostSet call: %w", err)
}
target := new(HostSet)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding CreateHostSet repsonse: %w", err)
}
2020-05-12 17:35:48 -07:00
target.Client = s.Client
return target, apiErr, nil
}