diff --git a/api/ocm/plugin/plugin.go b/api/ocm/plugin/plugin.go index e946fd25b..a3190d304 100644 --- a/api/ocm/plugin/plugin.go +++ b/api/ocm/plugin/plugin.go @@ -126,7 +126,7 @@ func (p *pluginImpl) Exec(r io.Reader, w io.Writer, args ...string) (result []by if strings.Contains(arg, "credentials") { if strings.Contains(arg, "=") { logargs[i] = "***" - } else if i < len(args)-1 { + } else if i+1 < len(args)-1 { logargs[i+1] = "***" } } diff --git a/api/ocm/plugin/ppi/cmds/upload/put/cmd.go b/api/ocm/plugin/ppi/cmds/upload/put/cmd.go index a94420a72..bcb013ab1 100644 --- a/api/ocm/plugin/ppi/cmds/upload/put/cmd.go +++ b/api/ocm/plugin/ppi/cmds/upload/put/cmd.go @@ -90,7 +90,7 @@ func Command(p ppi.Plugin, cmd *cobra.Command, opts *Options) error { fi, err := os.Stdin.Stat() if err != nil { - fmt.Println("failed to stat stdin", err) + return fmt.Errorf("failed to stat stdin: %w", err) } if size := fi.Size(); size == 0 { return fmt.Errorf("stdin is empty, and nothing can be uploaded") diff --git a/cmds/jfrogplugin/main.go b/cmds/jfrogplugin/main.go index 109561f07..5bc535fdb 100644 --- a/cmds/jfrogplugin/main.go +++ b/cmds/jfrogplugin/main.go @@ -24,7 +24,7 @@ func main() { p.SetShort(NAME + " plugin") p.SetLong(`ALPHA GRADE plugin providing custom functions related to interacting with JFrog Repositories (e.g. Artifactory). -This plugin is solely for interacting with JFrog Servers and should not be used for generic repository interactions. +This plugin is solely for interacting with JFrog Servers and cannot be used for generic repository types. Thus, you should only consider this plugin if - You need to use a JFrog specific API - You cannot use any of the generic (non-jfrog) implementations. @@ -52,6 +52,7 @@ You can configure the JFrog plugin as an Uploader in an ocm config file with: } err := cmds.NewPluginCommand(p).Execute(os.Args[1:]) if err != nil { + fmt.Fprintf(os.Stderr, "error while running plugin: %v\n", err) os.Exit(1) } } diff --git a/cmds/jfrogplugin/uploaders/helm/helm.go b/cmds/jfrogplugin/uploaders/helm/helm.go index eceea81cf..6c08a931c 100644 --- a/cmds/jfrogplugin/uploaders/helm/helm.go +++ b/cmds/jfrogplugin/uploaders/helm/helm.go @@ -48,24 +48,28 @@ type JFrogHelmUploaderSpec struct { // Required for correct reference to Artifactory. Repository string `json:"repository"` - // ChartName is the desired name of the chart in the repository. - // OPTIONAL: If not set, defaulted from the passed Hint. - ChartName string `json:"name"` - // Version is the desired version of the chart - // OPTIONAL: If not set, defaulted from the passed Hint. - ChartVersion string `json:"version"` + JFrogHelmChart `json:",inline"` // Timeout is the maximum duration the upload of the chart can take // before aborting and failing. // OPTIONAL: If not set, set to the internal DEFAULT_TIMEOUT. - Timeout time.Duration `json:"timeout"` + Timeout *time.Duration `json:"timeout,omitempty"` +} + +type JFrogHelmChart struct { + // ChartName is the desired name of the chart in the repository. + // OPTIONAL: If not set, defaulted from the passed Hint. + Name string `json:"name,omitempty"` + // Version is the desired version of the chart + // OPTIONAL: If not set, defaulted from the passed Hint. + Version string `json:"version,omitempty"` } func (s *JFrogHelmUploaderSpec) GetTimeout() time.Duration { - if s.Timeout > 0 { - return s.Timeout + if s.Timeout == nil { + return DEFAULT_TIMEOUT } - return DEFAULT_TIMEOUT + return *s.Timeout } var types ppi.UploadFormats @@ -183,17 +187,17 @@ func EnsureSpecWithHelpFromHint(spec *JFrogHelmUploaderSpec, hint string) error if refFromHint.Digest() != "" && refFromHint.Object == "" { return fmt.Errorf("the hint contained a valid reference but it was a digest, so it cannot be used to deduce a version of the helm chart: %s", refFromHint) } - if spec.ChartName == "" { - spec.ChartVersion = refFromHint.Object + if spec.Version == "" { + spec.Version = refFromHint.Object } - if spec.ChartName == "" { - spec.ChartName = path.Base(refFromHint.Locator) + if spec.Name == "" { + spec.Name = path.Base(refFromHint.Locator) } } - if spec.ChartName == "" { + if spec.Name == "" { return fmt.Errorf("the chart name could not be deduced from the hint (%s) or the config (%s)", hint, spec) } - if spec.ChartVersion == "" { + if spec.Version == "" { return fmt.Errorf("the chart version could not be deduced from the hint (%s) or the config (%s)", hint, spec) } return nil @@ -217,7 +221,7 @@ func EnsureSpecWithHelpFromHint(spec *JFrogHelmUploaderSpec, hint string) error // // url.URL => https://demo.jfrog.ocm.software/artifactory/my-charts/podinfo-0.0.1.tgz func ConvertTargetSpecToHelmUploadURL(spec *JFrogHelmUploaderSpec) (*url.URL, error) { - requestURL := path.Join(spec.URL, "artifactory", spec.Repository, fmt.Sprintf("%s-%s.tgz", spec.ChartName, spec.ChartVersion)) + requestURL := path.Join(spec.URL, "artifactory", spec.Repository, fmt.Sprintf("%s-%s.tgz", spec.Name, spec.Version)) requestURLParsed, err := parseURLAllowNoScheme(requestURL) if err != nil { return nil, fmt.Errorf("failed to parse full request URL: %w", err)