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

93 lines
2.4 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) ReadProject(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 ReadProject 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
if r.Id == "" {
return nil, nil, fmt.Errorf("empty Project ID field in ReadProject request")
2020-05-12 17:35:48 -07:00
}
2020-06-05 13:02:58 -07:00
req, err := s.Client.NewRequest(ctx, "GET", fmt.Sprintf("%s/%s", "projects", r.Id), r)
2020-05-12 17:35:48 -07:00
if err != nil {
return nil, nil, fmt.Errorf("error creating ReadProject request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during ReadProject call: %w", err)
}
target := new(Project)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding ReadProject 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) ReadHostCatalog(ctx context.Context, r *hosts.HostCatalog) (*hosts.HostCatalog, *api.Error, error) {
if s.Client == nil {
return nil, nil, fmt.Errorf("nil client in ReadHostCatalog 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)
}
if r.Id == "" {
return nil, nil, fmt.Errorf("empty hosts.HostCatalog ID field in ReadHostCatalog request")
}
req, err := s.Client.NewRequest(ctx, "GET", fmt.Sprintf("%s/%s", "host-catalogs", r.Id), r)
if err != nil {
return nil, nil, fmt.Errorf("error creating ReadHostCatalog request: %w", err)
}
resp, err := s.Client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during ReadHostCatalog call: %w", err)
}
target := new(hosts.HostCatalog)
apiErr, err := resp.Decode(target)
if err != nil {
return nil, nil, fmt.Errorf("error decoding ReadHostCatalog repsonse: %w", err)
}
target.Client = s.Client
return target, apiErr, nil
}