api

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package api provides access to the HCP Packer Registry API.

Index

Constants

View Source
const (
	InvalidClientConfig
)

Variables

View Source
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

func CheckErrorCode(err error, code codes.Code) bool

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

func NewClient() (*Client, error)

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

type ClientError struct {
	StatusCode uint
	Err        error
}

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL