Skip to content

Commit

Permalink
chore: pr review
Browse files Browse the repository at this point in the history
Co-authored-by: Gergely Brautigam <182850+skarlso@users.noreply.github.com>
  • Loading branch information
jakobmoellerdev and Skarlso committed Dec 18, 2024
1 parent d1f879a commit 6b2b379
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/ocm/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "***"
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/ocm/plugin/ppi/cmds/upload/put/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmds/jfrogplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
Expand Down
38 changes: 21 additions & 17 deletions cmds/jfrogplugin/uploaders/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6b2b379

Please sign in to comment.