Skip to content

Commit

Permalink
[FIX] - Terrenetes Download (#1589)
Browse files Browse the repository at this point in the history
Attempting to fix up the issue related to artifactory download in the tnctl create revision command
  • Loading branch information
gambol99 authored Jan 16, 2025
1 parent 6517b04 commit 1e86ef8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
18 changes: 16 additions & 2 deletions pkg/cmd/tnctl/create/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type RevisionCommand struct {
File string
// Provider is the name of the provider to use
Provider string
// DeleteDownload indicates we should retain the download
DeleteDownload bool
}

var revisionCommandDesc = `
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewRevisionCommand(factory cmd.Factory) *cobra.Command {

flags := c.Flags()
flags.BoolVar(&o.EnableDefaultVariables, "enable-default-variables", true, "Indicates if include variables which have defaults from the terraform module")
flags.BoolVar(&o.DeleteDownload, "delete-download", true, "Indicates if we should delete the download after the command has completed")
flags.StringVar(&o.Description, "description", "", "A human readable description of the revision and what is provides")
flags.StringVarP(&o.Name, "name", "n", "", "This name of the revision")
flags.StringVarP(&o.Revision, "revision", "r", "", "The semvar version of this revision")
Expand All @@ -128,7 +131,14 @@ func (o *RevisionCommand) Run(ctx context.Context) (err error) {
}
defer func() {
if delete {
err = os.RemoveAll(path)
retain := err

if o.DeleteDownload {
err = os.RemoveAll(path)
}
if retain != nil {
err = retain
}
}
}()
o.Println("%s Successfully downloaded module to: %s", cmd.IconGood, path)
Expand All @@ -139,7 +149,6 @@ func (o *RevisionCommand) Run(ctx context.Context) (err error) {
return fmt.Errorf("failed to load terraform module: %w", diag.Err())
}

// @step: ask the user about using the current kubeconfig to retrieve any contexts
if err := o.retrieveConfiguration(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -315,6 +324,11 @@ func (o *RevisionCommand) retrieveInputs(module *tfconfig.Module) error {
}
}

// @step: if we have nothing to select from, we can skip
if len(required) == 0 && len(optional) == 0 {
return nil
}

var selected []string
if err := survey.AskOne(&survey.MultiSelect{
Message: "What variables should be exposed to the developers?",
Expand Down
29 changes: 16 additions & 13 deletions pkg/utils/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,28 @@ func Download(ctx context.Context, source, destination string) error {
return err
}

if strings.HasPrefix(source, "http") {
source = strings.TrimPrefix(source, "http://")
source = strings.TrimPrefix(source, "https://")
// @step: just to keep the same behaviour as the previous version
if strings.HasPrefix(source, "https://github.com") {
source = strings.Replace(source, "https://github.com", "git::https://github.com", 2)
}

client := &getter.Client{
Ctx: ctx,
Dst: destination,
Detectors: []getter.Detector{
new(getter.GitHubDetector),
new(getter.GitLabDetector),
new(getter.GitDetector),
new(getter.BitBucketDetector),
new(getter.GCSDetector),
new(getter.S3Detector),
new(getter.FileDetector),
Options: []getter.ClientOption{
getter.WithMode(getter.ClientModeAny),
getter.WithDecompressors(getter.LimitedDecompressors(0, 0)),
getter.WithContext(ctx),
getter.WithDetectors([]getter.Detector{
new(getter.GitHubDetector),
new(getter.GitLabDetector),
new(getter.GitDetector),
new(getter.BitBucketDetector),
new(getter.GCSDetector),
new(getter.S3Detector),
new(getter.FileDetector),
}),
},
Mode: getter.ClientModeAny,
Options: []getter.ClientOption{},
Pwd: pwd,
Src: source,
}
Expand Down

0 comments on commit 1e86ef8

Please sign in to comment.