Skip to content

Commit

Permalink
Hide internal context functions
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Bulatov <[email protected]>
  • Loading branch information
Oleg Bulatov committed Mar 14, 2017
1 parent 782b869 commit 33fc599
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ func (ac *AccessController) Authorized(ctx context.Context, accessRecords ...reg
ctx = withDeferredErrors(ctx, possibleCrossMountErrors)
}
// Always add a marker to the context so we know auth was run
ctx = WithAuthPerformed(ctx)
ctx = withAuthPerformed(ctx)

return WithUserClient(ctx, osClient), nil
return withUserClient(ctx, osClient), nil
}

func getOpenShiftAPIToken(ctx context.Context, req *http.Request) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerregistry/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestAccessController(t *testing.T) {
t.Errorf("%s: expected auth context but got nil", k)
continue
}
if !AuthPerformed(authCtx) {
if !authPerformed(authCtx) {
t.Errorf("%s: expected AuthPerformed to be true", k)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerregistry/server/blobdescriptorservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (bs *blobDescriptorService) Stat(ctx context.Context, dgst digest.Digest) (
return desc, nil
}

if err == distribution.ErrBlobUnknown && RemoteBlobAccessCheckEnabledFrom(ctx) {
if err == distribution.ErrBlobUnknown && remoteBlobAccessCheckEnabledFrom(ctx) {
// Second attempt: looking for the blob on a remote server
desc, err = repo.remoteBlobGetter.Stat(ctx, dgst)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerregistry/server/blobdescriptorservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (f *fakeAccessController) Authorized(ctx context.Context, access ...registr
f.t.Logf("fake authorizer: authorizing access to %s:%s:%s", access.Resource.Type, access.Resource.Name, access.Action)
}

ctx = WithAuthPerformed(ctx)
ctx = withAuthPerformed(ctx)
return ctx, nil
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/dockerregistry/server/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ func repositoryFrom(ctx context.Context) (repo *repository, found bool) {
return
}

// WithRemoteBlobAccessCheckEnabled returns a new Context that allows
// withRemoteBlobAccessCheckEnabled returns a new Context that allows
// blobDescriptorService to stat remote blobs. It is useful only in case
// of manifest verification.
func WithRemoteBlobAccessCheckEnabled(parent context.Context, enable bool) context.Context {
func withRemoteBlobAccessCheckEnabled(parent context.Context, enable bool) context.Context {
return context.WithValue(parent, remoteBlobAccessCheckEnabledKey, enable)
}

// RemoteBlobAccessCheckEnabledFrom reports whether ctx allows
// remoteBlobAccessCheckEnabledFrom reports whether ctx allows
// blobDescriptorService to stat remote blobs.
func RemoteBlobAccessCheckEnabledFrom(ctx context.Context) bool {
func remoteBlobAccessCheckEnabledFrom(ctx context.Context) bool {
enabled, _ := ctx.Value(remoteBlobAccessCheckEnabledKey).(bool)
return enabled
}
Expand All @@ -61,33 +61,33 @@ func WithRegistryClient(ctx context.Context, client RegistryClient) context.Cont
return context.WithValue(ctx, registryClientKey, client)
}

// RegistryClientFrom returns the registry client stored in ctx, if present.
// RegistryClientFrom returns the registry client stored in ctx if present.
// It will panic otherwise.
func RegistryClientFrom(ctx context.Context) RegistryClient {
return ctx.Value(registryClientKey).(RegistryClient)
}

// WithUserClient returns a new Context with the origin's client.
// withUserClient returns a new Context with the origin's client.
// This client should have the current user's credentials
func WithUserClient(parent context.Context, userClient client.Interface) context.Context {
func withUserClient(parent context.Context, userClient client.Interface) context.Context {
return context.WithValue(parent, userClientKey, userClient)
}

// UserClientFrom returns the origin's client stored in ctx, if any.
func UserClientFrom(ctx context.Context) (client.Interface, bool) {
// userClientFrom returns the origin's client stored in ctx, if any.
func userClientFrom(ctx context.Context) (client.Interface, bool) {
userClient, ok := ctx.Value(userClientKey).(client.Interface)
return userClient, ok
}

// WithAuthPerformed returns a new Context with indication that authentication
// withAuthPerformed returns a new Context with indication that authentication
// was performed.
func WithAuthPerformed(parent context.Context) context.Context {
func withAuthPerformed(parent context.Context) context.Context {
return context.WithValue(parent, authPerformedKey, true)
}

// AuthPerformed reports whether ctx has indication that authentication was
// authPerformed reports whether ctx has indication that authentication was
// performed.
func AuthPerformed(ctx context.Context) bool {
func authPerformed(ctx context.Context) bool {
authPerformed, ok := ctx.Value(authPerformedKey).(bool)
return ok && authPerformed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerregistry/server/pullthroughmanifestservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ func (m *pullthroughManifestService) getRemoteRepositoryClient(ctx context.Conte
func (m *pullthroughManifestService) Put(ctx context.Context, manifest distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
context.GetLogger(ctx).Debugf("(*pullthroughManifestService).Put: enabling remote blob access check")
// manifest dependencies (layers and config) may not be stored locally, we need to be able to stat them in remote repositories
ctx = WithRemoteBlobAccessCheckEnabled(ctx, true)
ctx = withRemoteBlobAccessCheckEnabled(ctx, true)
return m.ManifestService.Put(ctx, manifest, options...)
}
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/repositorymiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (r *repository) createImageStream(ctx context.Context) (*imageapi.ImageStre
stream := imageapi.ImageStream{}
stream.Name = r.name

uclient, ok := UserClientFrom(ctx)
uclient, ok := userClientFrom(ctx)
if !ok {
errmsg := "error creating user client to auto provision image stream: user client to master API unavailable"
context.GetLogger(ctx).Errorf(errmsg)
Expand Down Expand Up @@ -469,7 +469,7 @@ func (r *repository) checkPendingErrors(ctx context.Context) error {
}

func checkPendingErrors(ctx context.Context, logger context.Logger, namespace, name string) error {
if !AuthPerformed(ctx) {
if !authPerformed(ctx) {
return fmt.Errorf("openshift.auth.completed missing from context")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/repositorymiddleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestRepositoryBlobStat(t *testing.T) {

ctx := context.Background()
if !tc.skipAuth {
ctx = WithAuthPerformed(ctx)
ctx = withAuthPerformed(ctx)
}
if tc.deferredErrors != nil {
ctx = withDeferredErrors(ctx, tc.deferredErrors)
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestRepositoryBlobStatCacheEviction(t *testing.T) {
const blobRepoCacheTTL = time.Millisecond * 500

quotaEnforcing = &quotaEnforcingConfig{}
ctx := WithAuthPerformed(context.Background())
ctx := withAuthPerformed(context.Background())

// this driver holds all the testing blobs in memory during the whole test run
driver := inmemory.New()
Expand Down
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/signaturedispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *signatureHandler) Put(w http.ResponseWriter, r *http.Request) {
return
}

client, ok := UserClientFrom(s.ctx)
client, ok := userClientFrom(s.ctx)
if !ok {
s.handleError(s.ctx, errcode.ErrorCodeUnknown.WithDetail("unable to get origin client"), w)
return
Expand Down Expand Up @@ -140,7 +140,7 @@ func (s *signatureHandler) Get(w http.ResponseWriter, req *http.Request) {
s.handleError(s.ctx, v2.ErrorCodeNameInvalid.WithDetail("missing image name or image ID"), w)
return
}
client, ok := UserClientFrom(s.ctx)
client, ok := userClientFrom(s.ctx)
if !ok {
s.handleError(s.ctx, errcode.ErrorCodeUnknown.WithDetail("unable to get origin client"), w)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/signaturedispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestSignatureGet(t *testing.T) {

ctx := context.Background()
ctx = WithRegistryClient(ctx, makeFakeRegistryClient(client, fake.NewSimpleClientset()))
ctx = WithUserClient(ctx, client)
ctx = withUserClient(ctx, client)
registryApp := handlers.NewApp(ctx, &configuration.Configuration{
Loglevel: "debug",
Auth: map[string]configuration.Parameters{
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestSignaturePut(t *testing.T) {

ctx := context.Background()
ctx = WithRegistryClient(ctx, makeFakeRegistryClient(client, fake.NewSimpleClientset()))
ctx = WithUserClient(ctx, client)
ctx = withUserClient(ctx, client)
registryApp := handlers.NewApp(ctx, &configuration.Configuration{
Loglevel: "debug",
Auth: map[string]configuration.Parameters{
Expand Down

0 comments on commit 33fc599

Please sign in to comment.