1 /* 2 Copyright The Helm Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package uploader 17 18 import ( 19 "fmt" 20 "io" 21 "net/url" 22 23 "github.com/pkg/errors" 24 25 "helm.sh/helm/v3/pkg/pusher" 26 "helm.sh/helm/v3/pkg/registry" 27 ) 28 29 // ChartUploader handles uploading a chart. 30 type ChartUploader struct { 31 // Out is the location to write warning and info messages. 32 Out io.Writer 33 // Pusher collection for the operation 34 Pushers pusher.Providers 35 // Options provide parameters to be passed along to the Pusher being initialized. 36 Options []pusher.Option 37 // RegistryClient is a client for interacting with registries. 38 RegistryClient *registry.Client 39 } 40 41 // UploadTo uploads a chart. Depending on the settings, it may also upload a provenance file. 42 func (c *ChartUploader) UploadTo(ref, remote string) error { 43 u, err := url.Parse(remote) 44 if err != nil { 45 return errors.Errorf("invalid chart URL format: %s", remote) 46 } 47 48 if u.Scheme == "" { 49 return fmt.Errorf("scheme prefix missing from remote (e.g. \"%s://\")", registry.OCIScheme) 50 } 51 52 p, err := c.Pushers.ByScheme(u.Scheme) 53 if err != nil { 54 return err 55 } 56 57 return p.Push(ref, u.String(), c.Options...) 58 } 59