Skip to content

Commit 53c737b

Browse files
refactor(notation): update options struct to be private
Signed-off-by: Jason <[email protected]>
1 parent 2014a32 commit 53c737b

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed

internal/oci/notation/notation.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const DefaultTrustPolicyKey = "trustpolicy.json"
4848

4949
// options is a struct that holds options for verifier.
5050
type options struct {
51-
RootCertificate []byte
52-
ROpt []remote.Option
53-
TrustPolicy *trustpolicy.Document
54-
Auth authn.Authenticator
55-
Keychain authn.Keychain
56-
Insecure bool
57-
Logger logr.Logger
51+
rootCertificate []byte
52+
rOpt []remote.Option
53+
trustPolicy *trustpolicy.Document
54+
auth authn.Authenticator
55+
keychain authn.Keychain
56+
insecure bool
57+
logger logr.Logger
5858
}
5959

6060
// Options is a function that configures the options applied to a Verifier.
@@ -63,14 +63,14 @@ type Options func(opts *options)
6363
// WithInsecureRegistry sets notation to verify against insecure registry.
6464
func WithInsecureRegistry(insecure bool) Options {
6565
return func(opts *options) {
66-
opts.Insecure = insecure
66+
opts.insecure = insecure
6767
}
6868
}
6969

7070
// WithTrustStore sets the trust store configuration.
7171
func WithTrustStore(trustStore *trustpolicy.Document) Options {
7272
return func(opts *options) {
73-
opts.TrustPolicy = trustStore
73+
opts.trustPolicy = trustStore
7474
}
7575
}
7676

@@ -81,39 +81,39 @@ func WithTrustStore(trustStore *trustpolicy.Document) Options {
8181
// in the notation options.
8282
func WithRootCertificate(data []byte) Options {
8383
return func(opts *options) {
84-
opts.RootCertificate = data
84+
opts.rootCertificate = data
8585
}
8686
}
8787

8888
// WithRemoteOptions is a functional option for overriding the default
8989
// remote options used by the verifier
9090
func WithRemoteOptions(opts ...remote.Option) Options {
9191
return func(o *options) {
92-
o.ROpt = opts
92+
o.rOpt = opts
9393
}
9494
}
9595

9696
// WithAuth is a functional option for overriding the default
9797
// remote options used by the verifier
9898
func WithAuth(auth authn.Authenticator) Options {
9999
return func(o *options) {
100-
o.Auth = auth
100+
o.auth = auth
101101
}
102102
}
103103

104104
// WithKeychain is a functional option for overriding the default
105105
// remote options used by the verifier
106106
func WithKeychain(key authn.Keychain) Options {
107107
return func(o *options) {
108-
o.Keychain = key
108+
o.keychain = key
109109
}
110110
}
111111

112112
// WithLogger is a function that returns an Options function to set the logger for the options.
113113
// The logger is used for logging purposes within the options.
114114
func WithLogger(logger logr.Logger) Options {
115115
return func(o *options) {
116-
o.Logger = logger
116+
o.logger = logger
117117
}
118118
}
119119

@@ -155,10 +155,10 @@ func NewNotationVerifier(opts ...Options) (*NotationVerifier, error) {
155155
}
156156

157157
store := &trustStore{
158-
cert: o.RootCertificate,
158+
cert: o.rootCertificate,
159159
}
160160

161-
trustpolicy := cleanTrustPolicy(o.TrustPolicy, o.Logger)
161+
trustpolicy := cleanTrustPolicy(o.trustPolicy, o.logger)
162162
if trustpolicy == nil {
163163
return nil, fmt.Errorf("trust policy cannot be empty")
164164
}
@@ -169,12 +169,12 @@ func NewNotationVerifier(opts ...Options) (*NotationVerifier, error) {
169169
}
170170

171171
return &NotationVerifier{
172-
auth: o.Auth,
173-
keychain: o.Keychain,
172+
auth: o.auth,
173+
keychain: o.keychain,
174174
verifier: &verifier,
175-
opts: o.ROpt,
176-
insecure: o.Insecure,
177-
logger: o.Logger,
175+
opts: o.rOpt,
176+
insecure: o.insecure,
177+
logger: o.logger,
178178
}, nil
179179
}
180180

internal/oci/notation/notation_test.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func TestOptions(t *testing.T) {
4242
name: "signature option",
4343
opts: []Options{WithRootCertificate([]byte("foo"))},
4444
want: &options{
45-
RootCertificate: []byte("foo"),
46-
ROpt: nil,
45+
rootCertificate: []byte("foo"),
46+
rOpt: nil,
4747
},
4848
},
4949
{
@@ -53,9 +53,9 @@ func TestOptions(t *testing.T) {
5353
WithKeychain(authn.DefaultKeychain),
5454
},
5555
want: &options{
56-
RootCertificate: nil,
57-
ROpt: []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)},
58-
Keychain: authn.DefaultKeychain,
56+
rootCertificate: nil,
57+
rOpt: []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)},
58+
keychain: authn.DefaultKeychain,
5959
},
6060
},
6161
{
@@ -69,13 +69,13 @@ func TestOptions(t *testing.T) {
6969
WithKeychain(authn.DefaultKeychain),
7070
},
7171
want: &options{
72-
RootCertificate: nil,
73-
ROpt: []remote.Option{
72+
rootCertificate: nil,
73+
rOpt: []remote.Option{
7474
remote.WithAuth(&authn.Basic{Username: "foo", Password: "bar"}),
7575
remote.WithAuthFromKeychain(authn.DefaultKeychain),
7676
},
77-
Auth: &authn.Basic{Username: "foo", Password: "bar"},
78-
Keychain: authn.DefaultKeychain,
77+
auth: &authn.Basic{Username: "foo", Password: "bar"},
78+
keychain: authn.DefaultKeychain,
7979
},
8080
},
8181
{
@@ -90,62 +90,62 @@ func TestOptions(t *testing.T) {
9090
WithKeychain(authn.DefaultKeychain),
9191
},
9292
want: &options{
93-
RootCertificate: nil,
94-
ROpt: []remote.Option{
93+
rootCertificate: nil,
94+
rOpt: []remote.Option{
9595
remote.WithAuth(&authn.Basic{Username: "foo", Password: "bar"}),
9696
remote.WithAuthFromKeychain(authn.DefaultKeychain),
9797
remote.WithTransport(http.DefaultTransport),
9898
},
99-
Auth: &authn.Basic{Username: "foo", Password: "bar"},
100-
Keychain: authn.DefaultKeychain,
99+
auth: &authn.Basic{Username: "foo", Password: "bar"},
100+
keychain: authn.DefaultKeychain,
101101
},
102102
},
103103
{
104104
name: "truststore, empty document",
105105
opts: []Options{WithTrustStore(&trustpolicy.Document{})},
106106
want: &options{
107-
RootCertificate: nil,
108-
ROpt: nil,
109-
TrustPolicy: &trustpolicy.Document{},
107+
rootCertificate: nil,
108+
rOpt: nil,
109+
trustPolicy: &trustpolicy.Document{},
110110
},
111111
},
112112
{
113113
name: "truststore, dummy document",
114114
opts: []Options{WithTrustStore(dummyPolicyDocument())},
115115
want: &options{
116-
RootCertificate: nil,
117-
ROpt: nil,
118-
TrustPolicy: dummyPolicyDocument(),
116+
rootCertificate: nil,
117+
rOpt: nil,
118+
trustPolicy: dummyPolicyDocument(),
119119
},
120120
},
121121
{
122122
name: "insecure, false",
123123
opts: []Options{WithInsecureRegistry(false)},
124124
want: &options{
125-
RootCertificate: nil,
126-
ROpt: nil,
127-
TrustPolicy: nil,
128-
Insecure: false,
125+
rootCertificate: nil,
126+
rOpt: nil,
127+
trustPolicy: nil,
128+
insecure: false,
129129
},
130130
},
131131
{
132132
name: "insecure, true",
133133
opts: []Options{WithInsecureRegistry(true)},
134134
want: &options{
135-
RootCertificate: nil,
136-
ROpt: nil,
137-
TrustPolicy: nil,
138-
Insecure: true,
135+
rootCertificate: nil,
136+
rOpt: nil,
137+
trustPolicy: nil,
138+
insecure: true,
139139
},
140140
},
141141
{
142142
name: "insecure, default",
143143
opts: []Options{},
144144
want: &options{
145-
RootCertificate: nil,
146-
ROpt: nil,
147-
TrustPolicy: nil,
148-
Insecure: false,
145+
rootCertificate: nil,
146+
rOpt: nil,
147+
trustPolicy: nil,
148+
insecure: false,
149149
},
150150
},
151151
}
@@ -157,24 +157,24 @@ func TestOptions(t *testing.T) {
157157
for _, opt := range tc.opts {
158158
opt(&o)
159159
}
160-
if !reflect.DeepEqual(o.RootCertificate, tc.want.RootCertificate) {
161-
t.Errorf("got %#v, want %#v", &o.RootCertificate, tc.want.RootCertificate)
160+
if !reflect.DeepEqual(o.rootCertificate, tc.want.rootCertificate) {
161+
t.Errorf("got %#v, want %#v", &o.rootCertificate, tc.want.rootCertificate)
162162
}
163163

164-
if !reflect.DeepEqual(o.TrustPolicy, tc.want.TrustPolicy) {
165-
t.Errorf("got %#v, want %#v", &o.TrustPolicy, tc.want.TrustPolicy)
164+
if !reflect.DeepEqual(o.trustPolicy, tc.want.trustPolicy) {
165+
t.Errorf("got %#v, want %#v", &o.trustPolicy, tc.want.trustPolicy)
166166
}
167167

168-
if tc.want.ROpt != nil {
169-
if len(o.ROpt) != len(tc.want.ROpt) {
170-
t.Errorf("got %d remote options, want %d", len(o.ROpt), len(tc.want.ROpt))
168+
if tc.want.rOpt != nil {
169+
if len(o.rOpt) != len(tc.want.rOpt) {
170+
t.Errorf("got %d remote options, want %d", len(o.rOpt), len(tc.want.rOpt))
171171
}
172172
return
173173
}
174174

175-
if tc.want.ROpt == nil {
176-
if len(o.ROpt) != 0 {
177-
t.Errorf("got %d remote options, want %d", len(o.ROpt), 0)
175+
if tc.want.rOpt == nil {
176+
if len(o.rOpt) != 0 {
177+
t.Errorf("got %d remote options, want %d", len(o.rOpt), 0)
178178
}
179179
}
180180
})

0 commit comments

Comments
 (0)