Skip to content

Commit

Permalink
Add --pca-file flag to allow attaching a PCA file during asset attach…
Browse files Browse the repository at this point in the history
… and creating new versions

Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
Pete Wall authored and petewall committed Jun 13, 2022
1 parent 56096f7 commit 54de646
Show file tree
Hide file tree
Showing 3 changed files with 309 additions and 2 deletions.
44 changes: 44 additions & 0 deletions cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
AttachVMFile string

AttachInstructions string

AttachPCAFile string
)

func init() {
Expand All @@ -45,6 +47,7 @@ func init() {
AttachChartCmd.Flags().StringVar(&AttachInstructions, "instructions", "", "Chart deployment instructions (required)")
_ = AttachChartCmd.MarkFlagRequired("instructions")
AttachChartCmd.Flags().BoolVar(&AttachCreateVersion, "create-version", false, "Create the product version, if it doesn't already exist")
AttachChartCmd.Flags().StringVar(&AttachPCAFile, "pca-file", "", "Path to a PCA file to upload")

AttachContainerImageCmd.Flags().StringVarP(&AttachProductSlug, "product", "p", "", "Product slug (required)")
_ = AttachContainerImageCmd.MarkFlagRequired("product")
Expand All @@ -59,13 +62,15 @@ func init() {
AttachContainerImageCmd.Flags().StringVarP(&AttachInstructions, "instructions", "i", "", "Image deployment instructions (required)")
_ = AttachContainerImageCmd.MarkFlagRequired("instructions")
AttachContainerImageCmd.Flags().BoolVar(&AttachCreateVersion, "create-version", false, "Create the product version, if it doesn't already exist")
AttachContainerImageCmd.Flags().StringVar(&AttachPCAFile, "pca-file", "", "Path to a PCA file to upload")

AttachVMCmd.Flags().StringVarP(&AttachProductSlug, "product", "p", "", "Product slug (required)")
_ = AttachVMCmd.MarkFlagRequired("product")
AttachVMCmd.Flags().StringVarP(&AttachProductVersion, "product-version", "v", "", "Product version (default to latest version)")
AttachVMCmd.Flags().StringVar(&AttachVMFile, "file", "", "Virtual machine file to upload (required)")
_ = AttachVMCmd.MarkFlagRequired("file")
AttachVMCmd.Flags().BoolVar(&AttachCreateVersion, "create-version", false, "Create the product version, if it doesn't already exist")
AttachVMCmd.Flags().StringVar(&AttachPCAFile, "pca-file", "", "Path to a PCA file to upload")
}

var AttachCmd = &cobra.Command{
Expand Down Expand Up @@ -94,6 +99,19 @@ var AttachChartCmd = &cobra.Command{
}
}

if AttachPCAFile != "" {
uploader, err := Marketplace.GetUploader(product.PublisherDetails.OrgId)
if err != nil {
return err
}
_, pcaUrl, err := uploader.UploadMediaFile(AttachPCAFile)
if err != nil {
return err
}

product.SetPCAFile(version.Number, pcaUrl)
}

chartURL, err := url.Parse(AttachChartURL)
if err != nil {
return fmt.Errorf("failed to parse chart URL: %w", err)
Expand Down Expand Up @@ -144,6 +162,19 @@ var AttachContainerImageCmd = &cobra.Command{
}
}

if AttachPCAFile != "" {
uploader, err := Marketplace.GetUploader(product.PublisherDetails.OrgId)
if err != nil {
return err
}
_, pcaUrl, err := uploader.UploadMediaFile(AttachPCAFile)
if err != nil {
return err
}

product.SetPCAFile(version.Number, pcaUrl)
}

var updatedProduct *models.Product
if AttachContainerImageFile != "" {
updatedProduct, err = Marketplace.AttachLocalContainerImage(AttachContainerImageFile, AttachContainerImage, AttachContainerImageTag, AttachContainerImageTagType, AttachInstructions, product, version)
Expand Down Expand Up @@ -178,6 +209,19 @@ var AttachVMCmd = &cobra.Command{
}
}

if AttachPCAFile != "" {
uploader, err := Marketplace.GetUploader(product.PublisherDetails.OrgId)
if err != nil {
return err
}
_, pcaUrl, err := uploader.UploadMediaFile(AttachPCAFile)
if err != nil {
return err
}

product.SetPCAFile(version.Number, pcaUrl)
}

updatedProduct, err := Marketplace.UploadVM(AttachVMFile, product, version)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 54de646

Please sign in to comment.