|
|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/preview/2021-04-30/client/packer_service"
|
|
|
|
|
"github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/preview/2021-04-30/models"
|
|
|
|
|
@ -110,12 +111,7 @@ var (
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (client *Client) GetIteration(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
bucketSlug string,
|
|
|
|
|
opts ...GetIterationOption,
|
|
|
|
|
) (*packer_service.PackerServiceGetIterationOK, error) {
|
|
|
|
|
|
|
|
|
|
func (client *Client) GetIteration(ctx context.Context, bucketSlug string, opts ...GetIterationOption) (*models.HashicorpCloudPackerIteration, error) {
|
|
|
|
|
getItParams := packer_service.NewPackerServiceGetIterationParams()
|
|
|
|
|
getItParams.LocationOrganizationID = client.OrganizationID
|
|
|
|
|
getItParams.LocationProjectID = client.ProjectID
|
|
|
|
|
@ -125,7 +121,22 @@ func (client *Client) GetIteration(
|
|
|
|
|
opt(getItParams)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return client.Packer.PackerServiceGetIteration(getItParams, nil)
|
|
|
|
|
resp, err := client.Packer.PackerServiceGetIteration(getItParams, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if resp.Payload.Iteration != nil {
|
|
|
|
|
if !time.Time(resp.Payload.Iteration.RevokeAt).IsZero() {
|
|
|
|
|
// If RevokeAt is not a zero date, it means this iteration is revoked and should not be used
|
|
|
|
|
// to build new images.
|
|
|
|
|
return nil, fmt.Errorf("the iteration %s is revoked and can not be used on Packer builds",
|
|
|
|
|
resp.Payload.Iteration.ID)
|
|
|
|
|
}
|
|
|
|
|
return resp.Payload.Iteration, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("something went wrong retrieving the iteration for bucket %s", bucketSlug)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (client *Client) CreateBuild(
|
|
|
|
|
@ -222,7 +233,7 @@ func (client *Client) UpdateBuild(
|
|
|
|
|
return resp.Payload.Build.ID, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetChannel loads the iterationId associated with a current channel. If the
|
|
|
|
|
// GetIterationFromChannel loads the iterationId associated with a current channel. If the
|
|
|
|
|
// channel does not exist in HCP Packer, GetChannel returns an error.
|
|
|
|
|
func (client *Client) GetIterationFromChannel(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
@ -242,10 +253,14 @@ func (client *Client) GetIterationFromChannel(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if resp.Payload.Channel != nil {
|
|
|
|
|
if resp.Payload.Channel.Pointer != nil {
|
|
|
|
|
// The channel payload contains a pointer, which points to the
|
|
|
|
|
// iteration. Reach into the pointer to get the desired iteration.
|
|
|
|
|
return resp.Payload.Channel.Pointer.Iteration, nil
|
|
|
|
|
if resp.Payload.Channel.Iteration != nil {
|
|
|
|
|
if !time.Time(resp.Payload.Channel.Iteration.RevokeAt).IsZero() {
|
|
|
|
|
// If RevokeAt is not a zero date, it means this iteration is revoked and should not be used
|
|
|
|
|
// to build new images.
|
|
|
|
|
return nil, fmt.Errorf("the iteration associated with the channel %s is revoked and can not be used on Packer builds",
|
|
|
|
|
channelName)
|
|
|
|
|
}
|
|
|
|
|
return resp.Payload.Channel.Iteration, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("there is no iteration associated with the channel %s",
|
|
|
|
|
channelName)
|
|
|
|
|
|