github.com/hashicorp/packer@v1.14.3/internal/hcp/api/service_channel.go (about)

     1  package api
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	hcpPackerAPI "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/client/packer_service"
     8  	hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
     9  )
    10  
    11  // GetChannel loads the named channel that is associated to the bucket name. If the
    12  // channel does not exist in HCP Packer, GetChannel returns an error.
    13  func (c *Client) GetChannel(
    14  	ctx context.Context, bucketName, channelName string,
    15  ) (*hcpPackerModels.HashicorpCloudPacker20230101Channel, error) {
    16  	params := hcpPackerAPI.NewPackerServiceGetChannelParamsWithContext(ctx)
    17  	params.LocationOrganizationID = c.OrganizationID
    18  	params.LocationProjectID = c.ProjectID
    19  	params.BucketName = bucketName
    20  	params.ChannelName = channelName
    21  
    22  	resp, err := c.Packer.PackerServiceGetChannel(params, nil)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	if resp.Payload.Channel == nil {
    28  		return nil, fmt.Errorf(
    29  			"there is no channel with the name %s associated with the bucket %s",
    30  			channelName, bucketName,
    31  		)
    32  	}
    33  
    34  	return resp.Payload.Channel, nil
    35  }