Skip to content

Commit

Permalink
Use HCP Packer metadata model
Browse files Browse the repository at this point in the history
  • Loading branch information
devashish-patel committed Mar 26, 2024
1 parent 9672d74 commit 00d3847
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions internal/hcp/api/service_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Client) UpdateBuild(
buildLabels map[string]string,
buildStatus hcpPackerModels.HashicorpCloudPacker20230101BuildStatus,
artifacts []*hcpPackerModels.HashicorpCloudPacker20230101ArtifactCreateBody,
metadata map[string]interface{},
metadata *hcpPackerModels.HashicorpCloudPacker20230101BuildMetadata,
) (string, error) {

params := hcpPackerAPI.NewPackerServiceUpdateBuildParamsWithContext(ctx)
Expand All @@ -77,12 +77,7 @@ func (c *Client) UpdateBuild(
Platform: platform,
SourceExternalIdentifier: sourceExternalIdentifier,
Status: &buildStatus,
}

if metadata != nil {
params.Body.Metadata = &hcpPackerModels.HashicorpCloudPacker20230101BuildMetadata{
Packer: metadata,
}
Metadata: metadata,
}

resp, err := c.Packer.PackerServiceUpdateBuild(params, nil)
Expand Down
12 changes: 6 additions & 6 deletions internal/hcp/registry/types.bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (bucket *Bucket) UpdateBuildStatus(
nil,
status,
nil,
buildToUpdate.Metadata,
&buildToUpdate.Metadata,
)
if err != nil {
return err
Expand Down Expand Up @@ -287,7 +287,7 @@ func (bucket *Bucket) markBuildComplete(ctx context.Context, name string) error
buildToUpdate.Labels,
status,
artifacts,
buildToUpdate.Metadata,
&buildToUpdate.Metadata,
)
if err != nil {
return err
Expand Down Expand Up @@ -612,8 +612,8 @@ func (bucket *Bucket) AddMetadataToBuild(
return err
}

preparedMetadata := make(map[string]interface{})
preparedMetadata["version"] = metadata.PackerVersion
packerMetadata := make(map[string]interface{})
packerMetadata["version"] = metadata.PackerVersion

var pluginsMetadata []map[string]interface{}
for _, plugin := range metadata.Plugins {
Expand All @@ -623,9 +623,9 @@ func (bucket *Bucket) AddMetadataToBuild(
}
pluginsMetadata = append(pluginsMetadata, pluginMetadata)
}
preparedMetadata["plugins"] = pluginsMetadata
packerMetadata["plugins"] = pluginsMetadata

buildToUpdate.Metadata = preparedMetadata
buildToUpdate.Metadata.Packer = packerMetadata
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/hcp/registry/types.builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Build struct {
Labels map[string]string
Artifacts map[string]packerSDKRegistry.Image
Status hcpPackerModels.HashicorpCloudPacker20230101BuildStatus
Metadata map[string]interface{}
Metadata hcpPackerModels.HashicorpCloudPacker20230101BuildMetadata
}

// NewBuildFromCloudPackerBuild converts a HashicorpCloudPackerBuild to a local build that can be tracked and
Expand Down

0 comments on commit 00d3847

Please sign in to comment.