Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 4eb7855

Browse files
committed
Adds more comments to pkg for context and cleans up some funcs
Signed-off-by: JoshVanL <[email protected]>
1 parent 65d7080 commit 4eb7855

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

cmd/app/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func buildRunCommand(stopCh <-chan struct{}, opts *options.Options) *cobra.Comma
110110

111111
<-waitCh
112112

113-
if err := p.RunShutdownHooks(); err != nil {
113+
if err := p.RunPreShutdownHooks(); err != nil {
114114
return err
115115
}
116116

pkg/proxy/audit/audit.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@ import (
1414
)
1515

1616
type Audit struct {
17-
options *options.AuditOptions
17+
opts *options.AuditOptions
1818
serverConfig *server.CompletedConfig
1919
}
2020

21-
func New(options *options.AuditOptions, externalAddress string, secureServingInfo *server.SecureServingInfo) (*Audit, error) {
21+
// New creates a new Audit struct to handle auditing for proxy requests. This
22+
// is mostly a wrapper for the apiserver auditing handlers to combine them with
23+
// the proxy.
24+
func New(opts *options.AuditOptions, externalAddress string, secureServingInfo *server.SecureServingInfo) (*Audit, error) {
2225
serverConfig := &server.Config{
2326
ExternalAddress: externalAddress,
2427
SecureServing: secureServingInfo,
2528

26-
// Default to treating watch as a long-running operation
27-
// Generic API servers have no inherent long-running subresources
29+
// Default to treating watch as a long-running operation.
30+
// Generic API servers have no inherent long-running subresources.
31+
// This is so watch requests are handled correctly in the audit log.
2832
LongRunningFunc: genericfilters.BasicLongRunningRequestCheck(
2933
sets.NewString("watch"), sets.NewString()),
3034
}
3135

3236
// We do not support dynamic auditing, so leave nil
33-
if err := options.ApplyTo(serverConfig, nil, nil, nil, nil); err != nil {
37+
if err := opts.ApplyTo(serverConfig, nil, nil, nil, nil); err != nil {
3438
return nil, err
3539
}
3640

3741
completed := serverConfig.Complete(nil)
3842

3943
return &Audit{
40-
options: options,
44+
opts: opts,
4145
serverConfig: &completed,
4246
}, nil
4347
}
4448

49+
// Run will run the audit backend if configured.
4550
func (a *Audit) Run(stopCh <-chan struct{}) error {
4651
if a.serverConfig.AuditBackend != nil {
4752
if err := a.serverConfig.AuditBackend.Run(stopCh); err != nil {
@@ -52,6 +57,7 @@ func (a *Audit) Run(stopCh <-chan struct{}) error {
5257
return nil
5358
}
5459

60+
// Shutdown will shutdown the audit backend if configured.
5561
func (a *Audit) Shutdown() error {
5662
if a.serverConfig.AuditBackend != nil {
5763
a.serverConfig.AuditBackend.Shutdown()
@@ -60,11 +66,16 @@ func (a *Audit) Shutdown() error {
6066
return nil
6167
}
6268

69+
// WithRequest will wrap the given handler to inject the request information
70+
// into the context which is then used by the wrapped audit handler.
6371
func (a *Audit) WithRequest(handler http.Handler) http.Handler {
6472
handler = genericapifilters.WithAudit(handler, a.serverConfig.AuditBackend, a.serverConfig.AuditPolicyChecker, a.serverConfig.LongRunningFunc)
6573
return genericapifilters.WithRequestInfo(handler, a.serverConfig.RequestInfoResolver)
6674
}
6775

76+
// WithUnauthorized will wrap the given handler to inject the request
77+
// information into the context which is then used by the wrapped audit
78+
// handler.
6879
func (a *Audit) WithUnauthorized(handler http.Handler) http.Handler {
6980
handler = genericapifilters.WithFailedAuthenticationAudit(handler, a.serverConfig.AuditBackend, a.serverConfig.AuditPolicyChecker)
7081
return genericapifilters.WithRequestInfo(handler, a.serverConfig.RequestInfoResolver)

pkg/proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,6 @@ func (p *Proxy) OIDCTokenAuthenticator() authenticator.Token {
261261
return p.tokenAuther
262262
}
263263

264-
func (p *Proxy) RunShutdownHooks() error {
264+
func (p *Proxy) RunPreShutdownHooks() error {
265265
return p.hooks.RunPreShutdownHooks()
266266
}

pkg/proxy/proxy_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func TestHasImpersonation(t *testing.T) {
254254
}
255255
}
256256

257-
func newTestProxy(t *testing.T) (*fakeProxy, error) {
257+
func newTestProxy(t *testing.T) *fakeProxy {
258258
ctrl := gomock.NewController(t)
259259
fakeToken := mocks.NewMockToken(ctrl)
260260
fakeRT := &fakeRT{t: t}
@@ -274,13 +274,13 @@ func newTestProxy(t *testing.T) (*fakeProxy, error) {
274274

275275
auditor, err := audit.New(new(options.AuditOptions), "0.0.0.0:1234", new(server.SecureServingInfo))
276276
if err != nil {
277-
return nil, err
277+
t.Fatalf("failed to create auditor: %s", err)
278278
}
279279
p.auditor = auditor
280280

281281
p.handleError = p.newErrorHandler()
282282

283-
return p, nil
283+
return p
284284
}
285285

286286
func TestHandlers(t *testing.T) {
@@ -537,11 +537,7 @@ func TestHandlers(t *testing.T) {
537537

538538
for name, test := range tests {
539539
t.Run(name, func(t *testing.T) {
540-
p, err := newTestProxy(t)
541-
if err != nil {
542-
t.Errorf("unexpected error: %s", err)
543-
t.FailNow()
544-
}
540+
p := newTestProxy(t)
545541

546542
w := httptest.NewRecorder()
547543

@@ -649,11 +645,7 @@ func TestHeadersConfig(t *testing.T) {
649645

650646
for name, test := range tests {
651647
t.Run(name, func(t *testing.T) {
652-
p, err := newTestProxy(t)
653-
if err != nil {
654-
t.Errorf("unexpected error: %s", err)
655-
t.FailNow()
656-
}
648+
p := newTestProxy(t)
657649

658650
p.config = test.config
659651
w := httptest.NewRecorder()

0 commit comments

Comments
 (0)