@ -12,6 +12,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License .
limitations under the License .
"helm.sh/helm/v3/internal/tlsutil"
* /
* /
package registry // import "helm.sh/helm/v3/pkg/registry"
package registry // import "helm.sh/helm/v3/pkg/registry"
@ -22,9 +23,11 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net"
"net/http"
"net/http"
"sort"
"sort"
"strings"
"strings"
"time"
"github.com/Masterminds/semver/v3"
"github.com/Masterminds/semver/v3"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes"
@ -38,6 +41,7 @@ import (
registryremote "oras.land/oras-go/pkg/registry/remote"
registryremote "oras.land/oras-go/pkg/registry/remote"
registryauth "oras.land/oras-go/pkg/registry/remote/auth"
registryauth "oras.land/oras-go/pkg/registry/remote/auth"
"helm.sh/helm/v3/internal/tlsutil"
"helm.sh/helm/v3/internal/version"
"helm.sh/helm/v3/internal/version"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/helmpath"
"helm.sh/helm/v3/pkg/helmpath"
@ -61,6 +65,9 @@ type (
authorizer auth . Client
authorizer auth . Client
registryAuthorizer * registryauth . Client
registryAuthorizer * registryauth . Client
resolver remotes . Resolver
resolver remotes . Resolver
tlsEnabled bool
chartRef string
utilOpts tlsutil . Options
}
}
// ClientOption allows specifying various settings configurable by the user for overriding the defaults
// ClientOption allows specifying various settings configurable by the user for overriding the defaults
@ -87,6 +94,31 @@ func NewClient(options ...ClientOption) (*Client, error) {
client . authorizer = authClient
client . authorizer = authClient
}
}
if client . resolver == nil {
if client . resolver == nil {
if client . tlsEnabled {
cfgtls , err := tlsutil . ClientConfig ( client . utilOpts )
if err != nil {
fmt . Printf ( "error :%v\n" , err )
}
var rt http . RoundTripper = & http . Transport {
Dial : ( & net . Dialer {
Timeout : 30 * time . Second ,
KeepAlive : 30 * time . Second ,
} ) . Dial ,
TLSHandshakeTimeout : 30 * time . Second ,
TLSClientConfig : cfgtls ,
ResponseHeaderTimeout : time . Duration ( 30 * time . Second ) ,
DisableKeepAlives : true ,
}
sClient := http . Client { Transport : rt , Timeout : 30 * time . Second }
headers := http . Header { }
headers . Set ( "User-Agent" , version . GetUserAgent ( ) )
opts := [ ] auth . ResolverOption { auth . WithResolverHeaders ( headers ) , auth . WithResolverClient ( & sClient ) }
resolver , err := client . authorizer . ResolverWithOpts ( opts ... )
if err != nil {
return nil , err
}
client . resolver = resolver
} else {
headers := http . Header { }
headers := http . Header { }
headers . Set ( "User-Agent" , version . GetUserAgent ( ) )
headers . Set ( "User-Agent" , version . GetUserAgent ( ) )
opts := [ ] auth . ResolverOption { auth . WithResolverHeaders ( headers ) }
opts := [ ] auth . ResolverOption { auth . WithResolverHeaders ( headers ) }
@ -96,6 +128,7 @@ func NewClient(options ...ClientOption) (*Client, error) {
}
}
client . resolver = resolver
client . resolver = resolver
}
}
}
// allocate a cache if option is set
// allocate a cache if option is set
var cache registryauth . Cache
var cache registryauth . Cache
@ -145,6 +178,12 @@ func ClientOptDebug(debug bool) ClientOption {
}
}
}
}
func ClientOptChartRef ( chartRef string ) ClientOption {
return func ( client * Client ) {
client . chartRef = chartRef
}
}
// ClientOptEnableCache returns a function that sets the enableCache setting on a client options set
// ClientOptEnableCache returns a function that sets the enableCache setting on a client options set
func ClientOptEnableCache ( enableCache bool ) ClientOption {
func ClientOptEnableCache ( enableCache bool ) ClientOption {
return func ( client * Client ) {
return func ( client * Client ) {
@ -166,6 +205,20 @@ func ClientOptCredentialsFile(credentialsFile string) ClientOption {
}
}
}
}
//ClientOptTwoWayTLSEnable returns a function that sets the client certificate when two-way tls authentication enable
func ClientOptTwoWayTLSEnable ( tlsEnabled bool ) ClientOption {
return func ( client * Client ) {
client . tlsEnabled = tlsEnabled
}
}
//ClientOptTwoWayTLSEnable returns a function that sets the client certificate when two-way tls authentication enable
func ClientOptWithTLSOpts ( tlsOpts tlsutil . Options ) ClientOption {
return func ( client * Client ) {
client . utilOpts = tlsOpts
}
}
type (
type (
// LoginOption allows specifying various settings on login
// LoginOption allows specifying various settings on login
LoginOption func ( * loginOperation )
LoginOption func ( * loginOperation )