mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 20:07:55 +08:00
refactor(test): add lint rule for messages starting with the component (#2045)
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
+27
-25
@@ -86,7 +86,7 @@ func (amw *AuthnMiddleware) sessionAuthn(ctlr *Controller, userAc *reqCtx.UserAc
|
||||
|
||||
groups, err := ctlr.MetaDB.GetUserGroups(request.Context())
|
||||
if err != nil {
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("can not get user profile in DB")
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("failed to get user profile in DB")
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
|
||||
// we have already populated the request context with userAc
|
||||
if err := ctlr.MetaDB.SetUserGroups(request.Context(), groups); err != nil {
|
||||
ctlr.Log.Error().Err(err).Str("identity", identity).Msg("couldn't update user profile")
|
||||
ctlr.Log.Error().Err(err).Str("identity", identity).Msg("failed to update user profile")
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
|
||||
// we have already populated the request context with userAc
|
||||
if err := ctlr.MetaDB.SetUserGroups(request.Context(), groups); err != nil {
|
||||
ctlr.Log.Error().Err(err).Str("identity", identity).Msg("couldn't update user profile")
|
||||
ctlr.Log.Error().Err(err).Str("identity", identity).Msg("failed to update user profile")
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
apiKey := passphrase
|
||||
|
||||
if !strings.HasPrefix(apiKey, constants.APIKeysPrefix) {
|
||||
ctlr.Log.Error().Msg("api token has invalid format")
|
||||
ctlr.Log.Error().Msg("invalid api token format")
|
||||
|
||||
return false, nil
|
||||
}
|
||||
@@ -198,12 +198,12 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
storedIdentity, err := ctlr.MetaDB.GetUserAPIKeyInfo(hashedKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrUserAPIKeyNotFound) {
|
||||
ctlr.Log.Info().Err(err).Msgf("can not find any user info for hashed key %s in DB", hashedKey)
|
||||
ctlr.Log.Info().Err(err).Msgf("failed to find any user info for hashed key %s in DB", hashedKey)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
ctlr.Log.Error().Err(err).Msgf("can not get user info for hashed key %s in DB", hashedKey)
|
||||
ctlr.Log.Error().Err(err).Msgf("failed to get user info for hashed key %s in DB", hashedKey)
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
// check if api key expired
|
||||
isExpired, err := ctlr.MetaDB.IsAPIKeyExpired(request.Context(), hashedKey)
|
||||
if err != nil {
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("can not verify if api key expired")
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("failed to verify if api key expired")
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -226,14 +226,14 @@ func (amw *AuthnMiddleware) basicAuthn(ctlr *Controller, userAc *reqCtx.UserAcce
|
||||
|
||||
err = ctlr.MetaDB.UpdateUserAPIKeyLastUsed(request.Context(), hashedKey)
|
||||
if err != nil {
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("can not update user profile in DB")
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("failed to update user profile in DB")
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
||||
groups, err := ctlr.MetaDB.GetUserGroups(request.Context())
|
||||
if err != nil {
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("can not get user's groups in DB")
|
||||
ctlr.Log.Err(err).Str("identity", identity).Msg("failed to get user's groups in DB")
|
||||
|
||||
return false, err
|
||||
}
|
||||
@@ -376,7 +376,7 @@ func (amw *AuthnMiddleware) tryAuthnHandlers(ctlr *Controller) mux.MiddlewareFun
|
||||
authenticated, err := amw.sessionAuthn(ctlr, userAc, response, request)
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrUserDataNotFound) {
|
||||
ctlr.Log.Err(err).Msg("can not find user profile in DB")
|
||||
ctlr.Log.Err(err).Msg("failed to find user profile in DB")
|
||||
|
||||
authFail(response, request, ctlr.Config.HTTP.Realm, delay)
|
||||
}
|
||||
@@ -419,7 +419,7 @@ func bearerAuthHandler(ctlr *Controller) mux.MiddlewareFunc {
|
||||
EmptyDefaultNamespace: true,
|
||||
})
|
||||
if err != nil {
|
||||
ctlr.Log.Panic().Err(err).Msg("error creating bearer authorizer")
|
||||
ctlr.Log.Panic().Err(err).Msg("failed to create bearer authorizer")
|
||||
}
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
@@ -452,7 +452,7 @@ func bearerAuthHandler(ctlr *Controller) mux.MiddlewareFunc {
|
||||
|
||||
permissions, err := authorizer.Authorize(header, action, name)
|
||||
if err != nil {
|
||||
ctlr.Log.Error().Err(err).Msg("issue parsing Authorization header")
|
||||
ctlr.Log.Error().Err(err).Msg("failed to parse Authorization header")
|
||||
response.Header().Set("Content-Type", "application/json")
|
||||
zcommon.WriteJSON(response, http.StatusInternalServerError, apiErr.NewError(apiErr.UNSUPPORTED))
|
||||
|
||||
@@ -523,7 +523,7 @@ func (rh *RouteHandler) AuthURLHandler() http.HandlerFunc {
|
||||
|
||||
client, ok := rh.c.RelyingParties[provider]
|
||||
if !ok {
|
||||
rh.c.Log.Error().Msg("unrecognized openid provider")
|
||||
rh.c.Log.Error().Msg("failed to authenticate due to unrecognized openid provider")
|
||||
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
@@ -547,7 +547,7 @@ func (rh *RouteHandler) AuthURLHandler() http.HandlerFunc {
|
||||
// let the session set its own id
|
||||
err := session.Save(r, w)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Msg("unable to save http session")
|
||||
rh.c.Log.Error().Err(err).Msg("failed to save http session")
|
||||
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
@@ -720,7 +720,7 @@ func GetGithubUserInfo(ctx context.Context, client *github.Client, log log.Logge
|
||||
|
||||
userEmails, _, err := client.Users.ListEmails(ctx, nil)
|
||||
if err != nil {
|
||||
log.Error().Msg("couldn't set user record for empty email value")
|
||||
log.Error().Msg("failed to set user record for empty email value")
|
||||
|
||||
return "", []string{}, err
|
||||
}
|
||||
@@ -737,7 +737,7 @@ func GetGithubUserInfo(ctx context.Context, client *github.Client, log log.Logge
|
||||
|
||||
orgs, _, err := client.Organizations.List(ctx, "", nil)
|
||||
if err != nil {
|
||||
log.Error().Msg("couldn't set user record for empty email value")
|
||||
log.Error().Msg("failed to set user record for empty email value")
|
||||
|
||||
return "", []string{}, err
|
||||
}
|
||||
@@ -764,7 +764,7 @@ func saveUserLoggedSession(cookieStore sessions.Store, response http.ResponseWri
|
||||
// let the session set its own id
|
||||
err := session.Save(request, response)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("identity", identity).Msg("unable to save http session")
|
||||
log.Error().Err(err).Str("identity", identity).Msg("failed to save http session")
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -790,13 +790,15 @@ func OAuth2Callback(ctlr *Controller, w http.ResponseWriter, r *http.Request, st
|
||||
|
||||
stateOrigin, ok := stateCookie.Values["state"].(string)
|
||||
if !ok {
|
||||
ctlr.Log.Error().Err(zerr.ErrInvalidStateCookie).Msg("openID: unable to get 'state' cookie from request")
|
||||
ctlr.Log.Error().Err(zerr.ErrInvalidStateCookie).Str("component", "openID").
|
||||
Msg(": failed to get 'state' cookie from request")
|
||||
|
||||
return "", zerr.ErrInvalidStateCookie
|
||||
}
|
||||
|
||||
if stateOrigin != state {
|
||||
ctlr.Log.Error().Err(zerr.ErrInvalidStateCookie).Msg("openID: 'state' cookie differs from the actual one")
|
||||
ctlr.Log.Error().Err(zerr.ErrInvalidStateCookie).Str("component", "openID").
|
||||
Msg(": 'state' cookie differs from the actual one")
|
||||
|
||||
return "", zerr.ErrInvalidStateCookie
|
||||
}
|
||||
@@ -813,7 +815,7 @@ func OAuth2Callback(ctlr *Controller, w http.ResponseWriter, r *http.Request, st
|
||||
}
|
||||
|
||||
if err := ctlr.MetaDB.SetUserGroups(r.Context(), groups); err != nil {
|
||||
ctlr.Log.Error().Err(err).Str("identity", email).Msg("couldn't update the user profile")
|
||||
ctlr.Log.Error().Err(err).Str("identity", email).Msg("failed to update the user profile")
|
||||
|
||||
return "", err
|
||||
}
|
||||
@@ -841,7 +843,7 @@ func GetAuthUserFromRequestSession(cookieStore sessions.Store, request *http.Req
|
||||
) (string, bool) {
|
||||
session, err := cookieStore.Get(request, "session")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("can not decode existing session")
|
||||
log.Error().Err(err).Msg("failed to decode existing session")
|
||||
// expired cookie, no need to return err
|
||||
return "", false
|
||||
}
|
||||
@@ -854,14 +856,14 @@ func GetAuthUserFromRequestSession(cookieStore sessions.Store, request *http.Req
|
||||
|
||||
authenticated := session.Values["authStatus"]
|
||||
if authenticated != true {
|
||||
log.Error().Msg("can not get `user` session value")
|
||||
log.Error().Msg("failed to get `user` session value")
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
identity, ok := session.Values["user"].(string)
|
||||
if !ok {
|
||||
log.Error().Msg("can not get `user` session value")
|
||||
log.Error().Msg("failed to get `user` session value")
|
||||
|
||||
return "", false
|
||||
}
|
||||
@@ -873,7 +875,7 @@ func GenerateAPIKey(uuidGenerator guuid.Generator, log log.Logger,
|
||||
) (string, string, error) {
|
||||
apiKeyBase, err := uuidGenerator.NewV4()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("unable to generate uuid for api key base")
|
||||
log.Error().Err(err).Msg("failed to generate uuid for api key base")
|
||||
|
||||
return "", "", err
|
||||
}
|
||||
@@ -883,7 +885,7 @@ func GenerateAPIKey(uuidGenerator guuid.Generator, log log.Logger,
|
||||
// will be used for identifying a specific api key
|
||||
apiKeyID, err := uuidGenerator.NewV4()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("unable to generate uuid for api key id")
|
||||
log.Error().Err(err).Msg("failed to generate uuid for api key id")
|
||||
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func TestAPIKeys(t *testing.T) {
|
||||
conf.Extensions.UI.Enable = &defaultVal
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("Random seed for username & password")
|
||||
dir := t.TempDir()
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
@@ -438,7 +438,7 @@ func (c *Controller) StartBackgroundTasks(reloadCtx context.Context) {
|
||||
//nolint: contextcheck
|
||||
syncOnDemand, err := ext.EnableSyncExtension(c.Config, c.MetaDB, c.StoreController, c.taskScheduler, c.Log)
|
||||
if err != nil {
|
||||
c.Log.Error().Err(err).Msg("unable to start sync extension")
|
||||
c.Log.Error().Err(err).Msg("failed to start sync extension")
|
||||
}
|
||||
|
||||
c.SyncOnDemand = syncOnDemand
|
||||
|
||||
@@ -8950,7 +8950,7 @@ func TestPeriodicGC(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(string(data), ShouldContainSubstring,
|
||||
"\"GC\":true,\"Commit\":false,\"GCDelay\":1000000000,\"GCInterval\":3600000000000")
|
||||
So(string(data), ShouldContainSubstring, "failure walking storage root-dir") //nolint:lll
|
||||
So(string(data), ShouldContainSubstring, "failed to walk storage root-dir") //nolint:lll
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -49,7 +49,7 @@ func (lc *LDAPClient) Connect() error {
|
||||
if !lc.UseSSL {
|
||||
l, err = ldap.Dial("tcp", address)
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("non-TLS connection failed")
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("failed to establish a TCP connection")
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (lc *LDAPClient) Connect() error {
|
||||
err = l.StartTLS(config)
|
||||
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("TLS connection failed")
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("failed to establish a TLS connection")
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (lc *LDAPClient) Connect() error {
|
||||
}
|
||||
l, err = ldap.DialTLS("tcp", address, config)
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("TLS connection failed")
|
||||
lc.Log.Error().Err(err).Str("address", address).Msg("failed to establish a TLS connection")
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
if lc.BindPassword != "" {
|
||||
err := lc.Conn.Bind(lc.BindDN, lc.BindPassword)
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Msg("bind failed")
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Msg("failed to bind")
|
||||
// clean up the cached conn, so we can retry
|
||||
lc.Conn.Close()
|
||||
lc.Conn = nil
|
||||
@@ -153,7 +153,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
} else {
|
||||
err := lc.Conn.UnauthenticatedBind(lc.BindDN)
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Msg("bind failed")
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Msg("failed to bind")
|
||||
// clean up the cached conn, so we can retry
|
||||
lc.Conn.Close()
|
||||
lc.Conn = nil
|
||||
@@ -167,7 +167,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
|
||||
// exhausted all retries?
|
||||
if !connected {
|
||||
lc.Log.Error().Err(errors.ErrLDAPBadConn).Msg("exhausted all retries")
|
||||
lc.Log.Error().Err(errors.ErrLDAPBadConn).Msg("failed to authenticate, exhausted all retries")
|
||||
|
||||
return false, nil, nil, errors.ErrLDAPBadConn
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
if err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Str("username", username).
|
||||
Str("baseDN", lc.Base).Msg("search failed")
|
||||
Str("baseDN", lc.Base).Msg("failed to perform a search request")
|
||||
|
||||
return false, nil, nil, err
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
if len(search.Entries) < 1 {
|
||||
err := errors.ErrBadUser
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Str("username", username).
|
||||
Str("baseDN", lc.Base).Msg("entries not found")
|
||||
Str("baseDN", lc.Base).Msg("failed to find entry")
|
||||
|
||||
return false, nil, nil, err
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
if len(search.Entries) > 1 {
|
||||
err := errors.ErrEntriesExceeded
|
||||
lc.Log.Error().Err(err).Str("bindDN", lc.BindDN).Str("username", username).
|
||||
Str("baseDN", lc.Base).Msg("too many entries")
|
||||
Str("baseDN", lc.Base).Msg("failed to retrieve due to an excessive amount of entries")
|
||||
|
||||
return false, nil, nil, err
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]
|
||||
// Bind as the user to verify their password
|
||||
err = lc.Conn.Bind(userDN, password)
|
||||
if err != nil {
|
||||
lc.Log.Error().Err(err).Str("bindDN", userDN).Msg("user bind failed")
|
||||
lc.Log.Error().Err(err).Str("bindDN", userDN).Msg("failed to bind user")
|
||||
|
||||
return false, user, userGroups, err
|
||||
}
|
||||
|
||||
+29
-28
@@ -549,7 +549,7 @@ func getReferrers(ctx context.Context, routeHandler *RouteHandler,
|
||||
if errSync := routeHandler.c.SyncOnDemand.SyncReference(ctx, name, digest.String(),
|
||||
syncConstants.OCI); errSync != nil {
|
||||
routeHandler.c.Log.Err(errSync).Str("repository", name).Str("reference", digest.String()).
|
||||
Msg("error encounter while syncing OCI reference for image")
|
||||
Msg("failed to sync OCI reference for image")
|
||||
}
|
||||
|
||||
refs, err = imgStore.GetReferrers(name, digest, artifactTypes)
|
||||
@@ -604,10 +604,12 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
|
||||
referrers, err := getReferrers(request.Context(), rh, imgStore, name, digest, artifactTypes)
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrManifestNotFound) || errors.Is(err, zerr.ErrRepoNotFound) {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("manifest not found")
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).
|
||||
Msg("failed to get manifest")
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
} else {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("unable to get references")
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).
|
||||
Msg("failed to get references")
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -616,7 +618,7 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
|
||||
|
||||
out, err := json.Marshal(referrers)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("unable to marshal json")
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("failed to marshal json")
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
@@ -706,7 +708,7 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
|
||||
zcommon.WriteJSON(response, http.StatusBadRequest, apiErr.NewErrorList(e))
|
||||
} else {
|
||||
// could be syscall.EMFILE (Err:0x18 too many opened files), etc
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error: performing cleanup")
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error, performing cleanup")
|
||||
|
||||
if err = imgStore.DeleteImageManifest(name, reference, false); err != nil {
|
||||
// deletion of image manifest is important, but not critical for image repo consistency
|
||||
@@ -1223,8 +1225,6 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
|
||||
return
|
||||
}
|
||||
|
||||
rh.c.Log.Info().Int64("r.ContentLength", request.ContentLength).Msg("DEBUG")
|
||||
|
||||
digestStr := digests[0]
|
||||
|
||||
digest := godigest.Digest(digestStr)
|
||||
@@ -1249,7 +1249,8 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
|
||||
|
||||
sessionID, size, err := imgStore.FullBlobUpload(name, request.Body, digest)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Int64("actual", size).Int64("expected", contentLength).Msg("failed full upload")
|
||||
rh.c.Log.Error().Err(err).Int64("actual", size).Int64("expected", contentLength).
|
||||
Msg("failed to full blob upload")
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
@@ -1430,7 +1431,7 @@ func (rh *RouteHandler) PatchBlobUpload(response http.ResponseWriter, request *h
|
||||
zcommon.WriteJSON(response, http.StatusNotFound, apiErr.NewErrorList(e))
|
||||
} else {
|
||||
// could be io.ErrUnexpectedEOF, syscall.EMFILE (Err:0x18 too many opened files), etc
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error: removing .uploads/ files")
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error, removing .uploads/ files")
|
||||
|
||||
if err = imgStore.DeleteBlobUpload(name, sessionID); err != nil {
|
||||
rh.c.Log.Error().Err(err).Str("blobUpload", sessionID).Str("repository", name).
|
||||
@@ -1496,8 +1497,6 @@ func (rh *RouteHandler) UpdateBlobUpload(response http.ResponseWriter, request *
|
||||
return
|
||||
}
|
||||
|
||||
rh.c.Log.Info().Int64("r.ContentLength", request.ContentLength).Msg("DEBUG")
|
||||
|
||||
contentPresent := true
|
||||
|
||||
contentLen, err := strconv.ParseInt(request.Header.Get("Content-Length"), 10, 64)
|
||||
@@ -1554,11 +1553,11 @@ func (rh *RouteHandler) UpdateBlobUpload(response http.ResponseWriter, request *
|
||||
zcommon.WriteJSON(response, http.StatusNotFound, apiErr.NewErrorList(e))
|
||||
} else {
|
||||
// could be io.ErrUnexpectedEOF, syscall.EMFILE (Err:0x18 too many opened files), etc
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error: removing .uploads/ files")
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error, removing .uploads/ files")
|
||||
|
||||
if err = imgStore.DeleteBlobUpload(name, sessionID); err != nil {
|
||||
rh.c.Log.Error().Err(err).Str("blobUpload", sessionID).Str("repository", name).
|
||||
Msg("couldn't remove blobUpload in repo")
|
||||
Msg("failed to remove blobUpload in repo")
|
||||
}
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
@@ -1589,11 +1588,11 @@ finish:
|
||||
zcommon.WriteJSON(response, http.StatusNotFound, apiErr.NewErrorList(e))
|
||||
} else {
|
||||
// could be io.ErrUnexpectedEOF, syscall.EMFILE (Err:0x18 too many opened files), etc
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error: removing .uploads/ files")
|
||||
rh.c.Log.Error().Err(err).Msg("unexpected error, removing .uploads/ files")
|
||||
|
||||
if err = imgStore.DeleteBlobUpload(name, sessionID); err != nil {
|
||||
rh.c.Log.Error().Err(err).Str("blobUpload", sessionID).Str("repository", name).
|
||||
Msg("couldn't remove blobUpload in repo")
|
||||
Msg("failed to remove blobUpload in repo")
|
||||
}
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
@@ -1813,7 +1812,7 @@ func (rh *RouteHandler) OpenIDCodeExchangeCallback() rp.CodeExchangeUserinfoCall
|
||||
) {
|
||||
email := info.GetEmail()
|
||||
if email == "" {
|
||||
rh.c.Log.Error().Msg("couldn't set user record for empty email value")
|
||||
rh.c.Log.Error().Msg("failed to set user record for empty email value")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
return
|
||||
@@ -1823,7 +1822,7 @@ func (rh *RouteHandler) OpenIDCodeExchangeCallback() rp.CodeExchangeUserinfoCall
|
||||
|
||||
val, ok := info.GetClaim("groups").([]interface{})
|
||||
if !ok {
|
||||
rh.c.Log.Info().Msgf("couldn't find any 'groups' claim for user %s", email)
|
||||
rh.c.Log.Info().Msgf("failed to find any 'groups' claim for user %s", email)
|
||||
}
|
||||
|
||||
for _, group := range val {
|
||||
@@ -1887,7 +1886,7 @@ func WriteDataFromReader(response http.ResponseWriter, status int, length int64,
|
||||
break
|
||||
} else if err != nil {
|
||||
// other kinds of intermittent errors can occur, e.g, io.ErrShortWrite
|
||||
logger.Error().Err(err).Msg("copying data into http response")
|
||||
logger.Error().Err(err).Msg("failed to copy data into http response")
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1920,7 +1919,7 @@ func getImageManifest(ctx context.Context, routeHandler *RouteHandler, imgStore
|
||||
|
||||
if errSync := routeHandler.c.SyncOnDemand.SyncImage(ctx, name, reference); errSync != nil {
|
||||
routeHandler.c.Log.Err(errSync).Str("repository", name).Str("reference", reference).
|
||||
Msg("error encounter while syncing image")
|
||||
Msg("failed to sync image")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1941,7 +1940,7 @@ func getOrasReferrers(ctx context.Context, routeHandler *RouteHandler,
|
||||
if errSync := routeHandler.c.SyncOnDemand.SyncReference(ctx, name, digest.String(),
|
||||
syncConstants.Oras); errSync != nil {
|
||||
routeHandler.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).
|
||||
Msg("unable to get references")
|
||||
Msg("failed to get references")
|
||||
}
|
||||
|
||||
refs, err = imgStore.GetOrasReferrers(name, digest, artifactType)
|
||||
@@ -2008,10 +2007,12 @@ func (rh *RouteHandler) GetOrasReferrers(response http.ResponseWriter, request *
|
||||
refs, err := getOrasReferrers(request.Context(), rh, imgStore, name, digest, artifactType) //nolint:contextcheck
|
||||
if err != nil {
|
||||
if errors.Is(err, zerr.ErrManifestNotFound) || errors.Is(err, zerr.ErrRepoNotFound) {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("manifest not found")
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).
|
||||
Msg("failed to get manifest")
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
} else {
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).Msg("unable to get references")
|
||||
rh.c.Log.Error().Err(err).Str("name", name).Str("digest", digest.String()).
|
||||
Msg("failed to get references")
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -2041,7 +2042,7 @@ type APIKeyPayload struct { //nolint:revive
|
||||
func (rh *RouteHandler) GetAPIKeys(resp http.ResponseWriter, req *http.Request) {
|
||||
apiKeys, err := rh.c.MetaDB.GetUserAPIKeys(req.Context())
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Msg("error getting list of API keys for user")
|
||||
rh.c.Log.Error().Err(err).Msg("failed to get list of api keys for user")
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
@@ -2057,7 +2058,7 @@ func (rh *RouteHandler) GetAPIKeys(resp http.ResponseWriter, req *http.Request)
|
||||
|
||||
data, err := json.Marshal(apiKeyResponse)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Msg("unable to marshal api key response")
|
||||
rh.c.Log.Error().Err(err).Msg("failed to marshal api key response")
|
||||
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
@@ -2085,7 +2086,7 @@ func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request
|
||||
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Msg("unable to read request body")
|
||||
rh.c.Log.Error().Msg("failed to read request body")
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
@@ -2141,7 +2142,7 @@ func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request
|
||||
|
||||
err = rh.c.MetaDB.AddUserAPIKey(req.Context(), hashedAPIKey, apiKeyDetails)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Msg("error storing API key")
|
||||
rh.c.Log.Error().Err(err).Msg("failed to store api key")
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
@@ -2159,7 +2160,7 @@ func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request
|
||||
|
||||
data, err := json.Marshal(apiKeyResponse)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Msg("unable to marshal api key response")
|
||||
rh.c.Log.Error().Err(err).Msg("failed to marshal api key response")
|
||||
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
@@ -2194,7 +2195,7 @@ func (rh *RouteHandler) RevokeAPIKey(resp http.ResponseWriter, req *http.Request
|
||||
|
||||
err := rh.c.MetaDB.DeleteUserAPIKey(req.Context(), keyID)
|
||||
if err != nil {
|
||||
rh.c.Log.Error().Err(err).Str("keyID", keyID).Msg("error deleting API key")
|
||||
rh.c.Log.Error().Err(err).Str("keyID", keyID).Msg("failed to delete api key")
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
|
||||
+3
-1
@@ -121,7 +121,8 @@ func SessionLogger(ctlr *Controller) mux.MiddlewareFunc {
|
||||
monitoring.ObserveHTTPMethodLatency(ctlr.Metrics, method, latency) // histogram
|
||||
}
|
||||
|
||||
log.Str("clientIP", clientIP).
|
||||
log.Str("component", "session").
|
||||
Str("clientIP", clientIP).
|
||||
Str("method", method).
|
||||
Str("path", path).
|
||||
Int("statusCode", statusCode).
|
||||
@@ -172,6 +173,7 @@ func SessionAuditLogger(audit *log.Logger) mux.MiddlewareFunc {
|
||||
method == http.MethodPatch || method == http.MethodDelete) &&
|
||||
(statusCode == http.StatusOK || statusCode == http.StatusCreated || statusCode == http.StatusAccepted) {
|
||||
audit.Info().
|
||||
Str("component", "session").
|
||||
Str("clientIP", clientIP).
|
||||
Str("subject", username).
|
||||
Str("action", method).
|
||||
|
||||
Reference in New Issue
Block a user