...

Source file src/oras.land/oras-go/pkg/auth/client_opts.go

Documentation: oras.land/oras-go/pkg/auth

     1  /*
     2  Copyright The ORAS 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 auth
    17  
    18  import (
    19  	"context"
    20  	"net/http"
    21  )
    22  
    23  type (
    24  	// LoginOption allows specifying various settings on login.
    25  	LoginOption func(*LoginSettings)
    26  
    27  	// LoginSettings represent all the various settings on login.
    28  	LoginSettings struct {
    29  		Context   context.Context
    30  		Hostname  string
    31  		Username  string
    32  		Secret    string
    33  		CertFile  string
    34  		KeyFile   string
    35  		CAFile    string
    36  		Insecure  bool
    37  		UserAgent string
    38  	}
    39  )
    40  
    41  // WithLoginContext returns a function that sets the Context setting on login.
    42  func WithLoginContext(context context.Context) LoginOption {
    43  	return func(settings *LoginSettings) {
    44  		settings.Context = context
    45  	}
    46  }
    47  
    48  // WithLoginHostname returns a function that sets the Hostname setting on login.
    49  func WithLoginHostname(hostname string) LoginOption {
    50  	return func(settings *LoginSettings) {
    51  		settings.Hostname = hostname
    52  	}
    53  }
    54  
    55  // WithLoginUsername returns a function that sets the Username setting on login.
    56  func WithLoginUsername(username string) LoginOption {
    57  	return func(settings *LoginSettings) {
    58  		settings.Username = username
    59  	}
    60  }
    61  
    62  // WithLoginSecret returns a function that sets the Secret setting on login.
    63  func WithLoginSecret(secret string) LoginOption {
    64  	return func(settings *LoginSettings) {
    65  		settings.Secret = secret
    66  	}
    67  }
    68  
    69  // WithLoginInsecure returns a function that sets the Insecure setting to true on login.
    70  func WithLoginInsecure() LoginOption {
    71  	return func(settings *LoginSettings) {
    72  		settings.Insecure = true
    73  	}
    74  }
    75  
    76  // WithLoginTLS returns a function that sets the tls settings on login.
    77  func WithLoginTLS(certFile, keyFile, caFile string) LoginOption {
    78  	return func(settings *LoginSettings) {
    79  		settings.CertFile = certFile
    80  		settings.KeyFile = keyFile
    81  		settings.CAFile = caFile
    82  	}
    83  }
    84  
    85  // WithLoginUserAgent returns a function that sets the UserAgent setting on login.
    86  func WithLoginUserAgent(userAgent string) LoginOption {
    87  	return func(settings *LoginSettings) {
    88  		settings.UserAgent = userAgent
    89  	}
    90  }
    91  
    92  type (
    93  	// ResolverOption allows specifying various settings on the resolver.
    94  	ResolverOption func(*ResolverSettings)
    95  
    96  	// ResolverSettings represent all the various settings on a resolver.
    97  	ResolverSettings struct {
    98  		Client    *http.Client
    99  		PlainHTTP bool
   100  		Headers   http.Header
   101  	}
   102  )
   103  
   104  // WithResolverClient returns a function that sets the Client setting on resolver.
   105  func WithResolverClient(client *http.Client) ResolverOption {
   106  	return func(settings *ResolverSettings) {
   107  		settings.Client = client
   108  	}
   109  }
   110  
   111  // WithResolverPlainHTTP returns a function that sets the PlainHTTP setting to true on resolver.
   112  func WithResolverPlainHTTP() ResolverOption {
   113  	return func(settings *ResolverSettings) {
   114  		settings.PlainHTTP = true
   115  	}
   116  }
   117  
   118  // WithResolverHeaders returns a function that sets the Headers setting on resolver.
   119  func WithResolverHeaders(headers http.Header) ResolverOption {
   120  	return func(settings *ResolverSettings) {
   121  		settings.Headers = headers
   122  	}
   123  }
   124  

View as plain text