64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package hosts
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/watchtower/api"
|
|
)
|
|
|
|
func (s HostCatalog) CreateHost(ctx context.Context, host *Host) (*Host, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in CreateHost request")
|
|
}
|
|
if s.Id == "" {
|
|
return nil, nil, fmt.Errorf("missing catalog ID in CreateHost request")
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "PUT", fmt.Sprintf("host-catalogs/%s/hosts", s.Id), host)
|
|
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)
|
|
}
|
|
|
|
return target, apiErr, nil
|
|
}
|
|
|
|
func (s HostCatalog) CreateHostSet(ctx context.Context, hostset *HostSet) (*HostSet, *api.Error, error) {
|
|
if s.Client == nil {
|
|
return nil, nil, fmt.Errorf("nil client in CreateHostSet request")
|
|
}
|
|
if s.Id == "" {
|
|
return nil, nil, fmt.Errorf("missing catalog ID in CreateHostSet request")
|
|
}
|
|
|
|
req, err := s.Client.NewRequest(ctx, "PUT", fmt.Sprintf("host-catalogs/%s/host-sets", s.Id), hostset)
|
|
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)
|
|
}
|
|
|
|
return target, apiErr, nil
|
|
}
|