github.com/nikkelma/oras-project_oras-go@v1.1.1-0.20220201001104-a75f6a419090/pkg/auth/client_opts.go (about) 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 Insecure bool 34 UserAgent string 35 } 36 ) 37 38 // WithLoginContext returns a function that sets the Context setting on login. 39 func WithLoginContext(context context.Context) LoginOption { 40 return func(settings *LoginSettings) { 41 settings.Context = context 42 } 43 } 44 45 // WithLoginHostname returns a function that sets the Hostname setting on login. 46 func WithLoginHostname(hostname string) LoginOption { 47 return func(settings *LoginSettings) { 48 settings.Hostname = hostname 49 } 50 } 51 52 // WithLoginUsername returns a function that sets the Username setting on login. 53 func WithLoginUsername(username string) LoginOption { 54 return func(settings *LoginSettings) { 55 settings.Username = username 56 } 57 } 58 59 // WithLoginSecret returns a function that sets the Secret setting on login. 60 func WithLoginSecret(secret string) LoginOption { 61 return func(settings *LoginSettings) { 62 settings.Secret = secret 63 } 64 } 65 66 // WithLoginInsecure returns a function that sets the Insecure setting to true on login. 67 func WithLoginInsecure() LoginOption { 68 return func(settings *LoginSettings) { 69 settings.Insecure = true 70 } 71 } 72 73 // WithLoginUserAgent returns a function that sets the UserAgent setting on login. 74 func WithLoginUserAgent(userAgent string) LoginOption { 75 return func(settings *LoginSettings) { 76 settings.UserAgent = userAgent 77 } 78 } 79 80 type ( 81 // ResolverOption allows specifying various settings on the resolver. 82 ResolverOption func(*ResolverSettings) 83 84 // ResolverSettings represent all the various settings on a resolver. 85 ResolverSettings struct { 86 Client *http.Client 87 PlainHTTP bool 88 Headers http.Header 89 } 90 ) 91 92 // WithResolverClient returns a function that sets the Client setting on resolver. 93 func WithResolverClient(client *http.Client) ResolverOption { 94 return func(settings *ResolverSettings) { 95 settings.Client = client 96 } 97 } 98 99 // WithResolverPlainHTTP returns a function that sets the PlainHTTP setting to true on resolver. 100 func WithResolverPlainHTTP() ResolverOption { 101 return func(settings *ResolverSettings) { 102 settings.PlainHTTP = true 103 } 104 } 105 106 // WithResolverHeaders returns a function that sets the Headers setting on resolver. 107 func WithResolverHeaders(headers http.Header) ResolverOption { 108 return func(settings *ResolverSettings) { 109 settings.Headers = headers 110 } 111 }