Files
Packer-Cn/internal/hcp/api/service_channel.go
3fa637c608 Migrate HCP Packer to API V2 and new nomenclature changes (#12794)
* add hcp packer new nomenclature updates

* Update docs with nomenclature changes

* Update navigation bar links

* Bump github.com/hashicorp/hcp-sdk-go from 0.81.0 to 0.82.0

* fix acceptance test template

---------

Co-authored-by: sylviamoss <[email protected]>
Co-authored-by: Wilken Rivera <[email protected]>
2024-01-24 13:17:35 -05:00

36 lines
1.1 KiB
Go

package api
import (
"context"
"fmt"
hcpPackerAPI "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/client/packer_service"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
)
// GetChannel loads the named channel that is associated to the bucket name. If the
// channel does not exist in HCP Packer, GetChannel returns an error.
func (c *Client) GetChannel(
ctx context.Context, bucketName, channelName string,
) (*hcpPackerModels.HashicorpCloudPacker20230101Channel, error) {
params := hcpPackerAPI.NewPackerServiceGetChannelParamsWithContext(ctx)
params.LocationOrganizationID = c.OrganizationID
params.LocationProjectID = c.ProjectID
params.BucketName = bucketName
params.ChannelName = channelName
resp, err := c.Packer.PackerServiceGetChannel(params, nil)
if err != nil {
return nil, err
}
if resp.Payload.Channel == nil {
return nil, fmt.Errorf(
"there is no channel with the name %s associated with the bucket %s",
channelName, bucketName,
)
}
return resp.Payload.Channel, nil
}