...

Source file src/helm.sh/helm/v3/pkg/pusher/pusher.go

Documentation: helm.sh/helm/v3/pkg/pusher

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package pusher
    18  
    19  import (
    20  	"github.com/pkg/errors"
    21  
    22  	"helm.sh/helm/v3/pkg/cli"
    23  	"helm.sh/helm/v3/pkg/registry"
    24  )
    25  
    26  // options are generic parameters to be provided to the pusher during instantiation.
    27  //
    28  // Pushers may or may not ignore these parameters as they are passed in.
    29  type options struct {
    30  	registryClient        *registry.Client
    31  	certFile              string
    32  	keyFile               string
    33  	caFile                string
    34  	insecureSkipTLSverify bool
    35  	plainHTTP             bool
    36  }
    37  
    38  // Option allows specifying various settings configurable by the user for overriding the defaults
    39  // used when performing Push operations with the Pusher.
    40  type Option func(*options)
    41  
    42  // WithRegistryClient sets the registryClient option.
    43  func WithRegistryClient(client *registry.Client) Option {
    44  	return func(opts *options) {
    45  		opts.registryClient = client
    46  	}
    47  }
    48  
    49  // WithTLSClientConfig sets the client auth with the provided credentials.
    50  func WithTLSClientConfig(certFile, keyFile, caFile string) Option {
    51  	return func(opts *options) {
    52  		opts.certFile = certFile
    53  		opts.keyFile = keyFile
    54  		opts.caFile = caFile
    55  	}
    56  }
    57  
    58  // WithInsecureSkipTLSVerify determines if a TLS Certificate will be checked
    59  func WithInsecureSkipTLSVerify(insecureSkipTLSVerify bool) Option {
    60  	return func(opts *options) {
    61  		opts.insecureSkipTLSverify = insecureSkipTLSVerify
    62  	}
    63  }
    64  
    65  func WithPlainHTTP(plainHTTP bool) Option {
    66  	return func(opts *options) {
    67  		opts.plainHTTP = plainHTTP
    68  	}
    69  }
    70  
    71  // Pusher is an interface to support upload to the specified URL.
    72  type Pusher interface {
    73  	// Push file content by url string
    74  	Push(chartRef, url string, options ...Option) error
    75  }
    76  
    77  // Constructor is the function for every pusher which creates a specific instance
    78  // according to the configuration
    79  type Constructor func(options ...Option) (Pusher, error)
    80  
    81  // Provider represents any pusher and the schemes that it supports.
    82  type Provider struct {
    83  	Schemes []string
    84  	New     Constructor
    85  }
    86  
    87  // Provides returns true if the given scheme is supported by this Provider.
    88  func (p Provider) Provides(scheme string) bool {
    89  	for _, i := range p.Schemes {
    90  		if i == scheme {
    91  			return true
    92  		}
    93  	}
    94  	return false
    95  }
    96  
    97  // Providers is a collection of Provider objects.
    98  type Providers []Provider
    99  
   100  // ByScheme returns a Provider that handles the given scheme.
   101  //
   102  // If no provider handles this scheme, this will return an error.
   103  func (p Providers) ByScheme(scheme string) (Pusher, error) {
   104  	for _, pp := range p {
   105  		if pp.Provides(scheme) {
   106  			return pp.New()
   107  		}
   108  	}
   109  	return nil, errors.Errorf("scheme %q not supported", scheme)
   110  }
   111  
   112  var ociProvider = Provider{
   113  	Schemes: []string{registry.OCIScheme},
   114  	New:     NewOCIPusher,
   115  }
   116  
   117  // All finds all of the registered pushers as a list of Provider instances.
   118  // Currently, just the built-in pushers are collected.
   119  func All(_ *cli.EnvSettings) Providers {
   120  	result := Providers{ociProvider}
   121  	return result
   122  }
   123  

View as plain text