Documentation
¶
Overview ¶
Package api provides access to the HCP Packer Registry API.
Index ¶
- Constants
- Variables
- func CheckErrorCode(err error, code codes.Code) bool
- type Client
- func (client *Client) CreateBucket(ctx context.Context, bucketSlug, bucketDescription string, ...) (*packer_service.PackerServiceCreateBucketOK, error)
- func (client *Client) CreateBuild(ctx context.Context, ...) (*packer_service.PackerServiceCreateBuildOK, error)
- func (client *Client) CreateIteration(ctx context.Context, bucketSlug, fingerprint string, ...) (*packer_service.PackerServiceCreateIterationOK, error)
- func (client *Client) DeleteBucket(ctx context.Context, bucketSlug string) (*packer_service.PackerServiceDeleteBucketOK, error)
- func (client *Client) GetChannel(ctx context.Context, bucketSlug string, channelName string) (*models.HashicorpCloudPackerChannel, error)
- func (client *Client) GetIteration(ctx context.Context, bucketSlug string, opts ...GetIterationOption) (*models.HashicorpCloudPackerIteration, error)
- func (client *Client) ListBuilds(ctx context.Context, bucketSlug string, iterationID string) ([]*models.HashicorpCloudPackerBuild, error)
- func (client *Client) UpdateBuild(ctx context.Context, buildID, runUUID, cloudProvider, sourceImageID string, ...) (string, error)
- func (client *Client) UpsertBucket(ctx context.Context, bucketSlug, bucketDescription string, ...) error
- type ClientError
- type GetIterationOption
- type MockPackerClientService
- func (svc *MockPackerClientService) PackerServiceCreateBucket(params *packerSvc.PackerServiceCreateBucketParams, ...) (*packerSvc.PackerServiceCreateBucketOK, error)
- func (svc *MockPackerClientService) PackerServiceCreateBuild(params *packerSvc.PackerServiceCreateBuildParams, ...) (*packerSvc.PackerServiceCreateBuildOK, error)
- func (svc *MockPackerClientService) PackerServiceCreateIteration(params *packerSvc.PackerServiceCreateIterationParams, ...) (*packerSvc.PackerServiceCreateIterationOK, error)
- func (svc *MockPackerClientService) PackerServiceGetIteration(params *packerSvc.PackerServiceGetIterationParams, ...) (*packerSvc.PackerServiceGetIterationOK, error)
- func (svc *MockPackerClientService) PackerServiceListBuilds(params *packerSvc.PackerServiceListBuildsParams, ...) (*packerSvc.PackerServiceListBuildsOK, error)
- func (svc *MockPackerClientService) PackerServiceUpdateBucket(params *packerSvc.PackerServiceUpdateBucketParams, ...) (*packerSvc.PackerServiceUpdateBucketOK, error)
- func (svc *MockPackerClientService) PackerServiceUpdateBuild(params *packerSvc.PackerServiceUpdateBuildParams, ...) (*packerSvc.PackerServiceUpdateBuildOK, error)
Constants ¶
const (
InvalidClientConfig
)
Variables ¶
var ( GetIteration_byID = func(id string) GetIterationOption { return func(params *packer_service.PackerServiceGetIterationParams) { params.IterationID = &id } } GetIteration_byFingerprint = func(fingerprint string) GetIterationOption { return func(params *packer_service.PackerServiceGetIterationParams) { params.Fingerprint = &fingerprint } } )
Functions ¶
func CheckErrorCode ¶
CheckErrorCode checks the error string for err for some code and returns true if the code is found. Ideally this function should use status.FromError https://pkg.go.dev/google.golang.org/grpc/status#pkg-functions but that doesn't appear to work for all of the Cloud Packer Service response errors.
Types ¶
type Client ¶
type Client struct {
Packer packerSvc.ClientService
Organization organizationSvc.ClientService
Project projectSvc.ClientService
// OrganizationID is the organization unique identifier on HCP.
OrganizationID string
// ProjectID is the project unique identifier on HCP.
ProjectID string
}
Client is an HCP client capable of making requests on behalf of a service principal
func NewClient ¶
NewClient returns an authenticated client to a HCP Packer Registry. Client authentication requires the following environment variables be set HCP_CLIENT_ID and HCP_CLIENT_SECRET. Upon error a HCPClientError will be returned.
func (*Client) CreateBucket ¶
func (client *Client) CreateBucket( ctx context.Context, bucketSlug, bucketDescription string, bucketLabels map[string]string, ) (*packer_service.PackerServiceCreateBucketOK, error)
func (*Client) CreateBuild ¶
func (client *Client) CreateBuild( ctx context.Context, bucketSlug, runUUID, iterationID, fingerprint, componentType string, status models.HashicorpCloudPackerBuildStatus, ) (*packer_service.PackerServiceCreateBuildOK, error)
func (*Client) CreateIteration ¶
func (client *Client) CreateIteration( ctx context.Context, bucketSlug, fingerprint string, templateType models.HashicorpCloudPackerIterationTemplateType, ) (*packer_service.PackerServiceCreateIterationOK, error)
func (*Client) DeleteBucket ¶
func (client *Client) DeleteBucket( ctx context.Context, bucketSlug string, ) (*packer_service.PackerServiceDeleteBucketOK, error)
func (*Client) GetChannel ¶
func (client *Client) GetChannel(ctx context.Context, bucketSlug string, channelName string) (*models.HashicorpCloudPackerChannel, error)
GetChannel loads the named channel that is associated to the bucket slug . If the channel does not exist in HCP Packer, GetChannel returns an error.
func (*Client) GetIteration ¶
func (client *Client) GetIteration(ctx context.Context, bucketSlug string, opts ...GetIterationOption) (*models.HashicorpCloudPackerIteration, error)
func (*Client) ListBuilds ¶
func (client *Client) ListBuilds( ctx context.Context, bucketSlug string, iterationID string, ) ([]*models.HashicorpCloudPackerBuild, error)
ListBuilds queries an Iteration on HCP Packer registry for all of it's associated builds. Currently all builds are returned regardless of status.
func (*Client) UpdateBuild ¶
func (client *Client) UpdateBuild( ctx context.Context, buildID, runUUID, cloudProvider, sourceImageID string, sourceIterationID string, sourceChannelID string, labels map[string]string, status models.HashicorpCloudPackerBuildStatus, images []*models.HashicorpCloudPackerImageCreateBody, ) (string, error)
UpdateBuild updates a single iteration build entry with the incoming input data.
func (*Client) UpsertBucket ¶
func (client *Client) UpsertBucket( ctx context.Context, bucketSlug, bucketDescription string, bucketLabels map[string]string, ) error
UpsertBucket tries to create a bucket on a HCP Packer Registry. If the bucket exists it will handle the error and update the bucket with the provided details.
type ClientError ¶
ClientError represents a generic error for the Cloud Packer Service client.
func (*ClientError) Error ¶
func (c *ClientError) Error() string
Error returns the string message for some ClientError.
type GetIterationOption ¶
type GetIterationOption func(*packer_service.PackerServiceGetIterationParams)
type MockPackerClientService ¶
type MockPackerClientService struct {
CreateBucketCalled, UpdateBucketCalled, BucketAlreadyExist bool
CreateIterationCalled, GetIterationCalled, IterationAlreadyExist, IterationCompleted bool
CreateBuildCalled, UpdateBuildCalled, ListBuildsCalled, BuildAlreadyDone bool
TrackCalledServiceMethods bool
// Mock Creates
CreateBucketResp *models.HashicorpCloudPackerCreateBucketResponse
CreateIterationResp *models.HashicorpCloudPackerCreateIterationResponse
CreateBuildResp *models.HashicorpCloudPackerCreateBuildResponse
// Mock Gets
GetIterationResp *models.HashicorpCloudPackerGetIterationResponse
ExistingBuilds []string
ExistingBuildLabels map[string]string
packerSvc.ClientService
}
MockPackerClientService represents a basic mock of the Cloud Packer Service. Upon calling a service method a boolean is set to true to indicate that a method has been called. To skip the setting of these booleans set TrackCalledServiceMethods to false; defaults to true in NewMockPackerClientService().
func NewMockPackerClientService ¶
func NewMockPackerClientService() *MockPackerClientService
NewMockPackerClientService returns a basic mock of the Cloud Packer Service. Upon calling a service method a boolean is set to true to indicate that a method has been called. To skip the setting of these booleans set TrackCalledServiceMethods to false. By default it is true.
func (*MockPackerClientService) PackerServiceCreateBucket ¶
func (svc *MockPackerClientService) PackerServiceCreateBucket(params *packerSvc.PackerServiceCreateBucketParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceCreateBucketOK, error)
func (*MockPackerClientService) PackerServiceCreateBuild ¶
func (svc *MockPackerClientService) PackerServiceCreateBuild(params *packerSvc.PackerServiceCreateBuildParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceCreateBuildOK, error)
func (*MockPackerClientService) PackerServiceCreateIteration ¶
func (svc *MockPackerClientService) PackerServiceCreateIteration(params *packerSvc.PackerServiceCreateIterationParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceCreateIterationOK, error)
func (*MockPackerClientService) PackerServiceGetIteration ¶
func (svc *MockPackerClientService) PackerServiceGetIteration(params *packerSvc.PackerServiceGetIterationParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceGetIterationOK, error)
func (*MockPackerClientService) PackerServiceListBuilds ¶
func (svc *MockPackerClientService) PackerServiceListBuilds(params *packerSvc.PackerServiceListBuildsParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceListBuildsOK, error)
func (*MockPackerClientService) PackerServiceUpdateBucket ¶
func (svc *MockPackerClientService) PackerServiceUpdateBucket(params *packerSvc.PackerServiceUpdateBucketParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceUpdateBucketOK, error)
func (*MockPackerClientService) PackerServiceUpdateBuild ¶
func (svc *MockPackerClientService) PackerServiceUpdateBuild(params *packerSvc.PackerServiceUpdateBuildParams, _ runtime.ClientAuthInfoWriter, opts ...packer_service.ClientOption) (*packerSvc.PackerServiceUpdateBuildOK, error)