mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
29 lines
486 B
Go
29 lines
486 B
Go
|
package requestcontext
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
zerr "zotregistry.io/zot/errors"
|
||
|
)
|
||
|
|
||
|
func RepoIsUserAvailable(ctx context.Context, repoName string) (bool, error) {
|
||
|
authzCtxKey := GetContextKey()
|
||
|
|
||
|
if authCtx := ctx.Value(authzCtxKey); authCtx != nil {
|
||
|
acCtx, ok := authCtx.(AccessControlContext)
|
||
|
if !ok {
|
||
|
err := zerr.ErrBadCtxFormat
|
||
|
|
||
|
return false, err
|
||
|
}
|
||
|
|
||
|
if acCtx.IsAdmin || acCtx.CanReadRepo(repoName) {
|
||
|
return true, nil
|
||
|
}
|
||
|
|
||
|
return false, nil
|
||
|
}
|
||
|
|
||
|
return true, nil
|
||
|
}
|