mirror of
https://github.com/versity/versitygw.git
synced 2026-07-02 16:54:25 +00:00
4d391cabc8
Fixes #2180 Fixes #2181 Migrate the gateway from Fiber v2 to Fiber v3.3.0 and update the affected server, middleware, handler, controller, and test code for the new APIs. Replace the deprecated Fiber filesystem middleware used by the WebUI with the Fiber v3 static middleware, serving the embedded WebUI assets from an fs.Sub filesystem. Fix the request header limit handling regression by adding a temporary handler for Fiber v3/fasthttp small-buffer errors so oversized request headers return the expected regulated S3 error response. Fix the debuglogger panic by reworking the boxed key/value formatter used for debug request and response dumps. The formatter now handles long header keys and values without producing invalid wrap widths, negative padding, or out-of-range string slices.
150 lines
3.4 KiB
Go
150 lines
3.4 KiB
Go
// Copyright 2023 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package s3log
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
type AuditLogger interface {
|
|
Log(ctx fiber.Ctx, err error, body []byte, meta LogMeta)
|
|
HangUp() error
|
|
Shutdown() error
|
|
}
|
|
|
|
type LogMeta struct {
|
|
BucketOwner string
|
|
ObjectSize int64
|
|
Action string
|
|
HttpStatus int
|
|
}
|
|
|
|
type LogConfig struct {
|
|
LogFile string
|
|
WebhookURL string
|
|
AdminLogFile string
|
|
}
|
|
|
|
type LogFields struct {
|
|
BucketOwner string
|
|
Bucket string
|
|
Time time.Time
|
|
RemoteIP string
|
|
Requester string
|
|
RequestID string
|
|
Operation string
|
|
Key string
|
|
RequestURI string
|
|
HttpStatus int
|
|
ErrorCode string
|
|
BytesSent int
|
|
ObjectSize int64
|
|
TotalTime int64
|
|
TurnAroundTime int64
|
|
Referer string
|
|
UserAgent string
|
|
VersionID string
|
|
HostID string
|
|
SignatureVersion string
|
|
CipherSuite string
|
|
AuthenticationType string
|
|
HostHeader string
|
|
TLSVersion string
|
|
AccessPointARN string
|
|
AclRequired string
|
|
}
|
|
|
|
type AdminLogFields struct {
|
|
Time time.Time
|
|
RemoteIP string
|
|
Requester string
|
|
RequestID string
|
|
HostID string
|
|
Operation string
|
|
RequestURI string
|
|
HttpStatus int
|
|
ErrorCode string
|
|
BytesSent int
|
|
TotalTime int64
|
|
TurnAroundTime int64
|
|
Referer string
|
|
UserAgent string
|
|
SignatureVersion string
|
|
CipherSuite string
|
|
AuthenticationType string
|
|
TLSVersion string
|
|
}
|
|
|
|
type Loggers struct {
|
|
S3Logger AuditLogger
|
|
AdminLogger AuditLogger
|
|
}
|
|
|
|
func InitLogger(cfg *LogConfig) (*Loggers, error) {
|
|
if cfg.WebhookURL != "" && cfg.LogFile != "" {
|
|
return nil, fmt.Errorf("there should be specified one of the following: file, webhook")
|
|
}
|
|
loggers := new(Loggers)
|
|
|
|
switch {
|
|
case cfg.WebhookURL != "":
|
|
fmt.Printf("initializing S3 access logs with '%v' webhook url\n", cfg.WebhookURL)
|
|
l, err := InitWebhookLogger(cfg.WebhookURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
loggers.S3Logger = l
|
|
case cfg.LogFile != "":
|
|
fmt.Printf("initializing S3 access logs with '%v' file\n", cfg.LogFile)
|
|
l, err := InitFileLogger(cfg.LogFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
loggers.S3Logger = l
|
|
}
|
|
|
|
if cfg.AdminLogFile != "" {
|
|
fmt.Printf("initializing admin access logs with '%v' file\n", cfg.AdminLogFile)
|
|
l, err := InitAdminFileLogger(cfg.AdminLogFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
loggers.AdminLogger = l
|
|
}
|
|
|
|
return loggers, nil
|
|
}
|
|
|
|
func getTLSVersionName(version uint16) string {
|
|
switch version {
|
|
case tls.VersionTLS10:
|
|
return "TLSv1.0"
|
|
case tls.VersionTLS11:
|
|
return "TLSv1.1"
|
|
case tls.VersionTLS12:
|
|
return "TLSv1.2"
|
|
case tls.VersionTLS13:
|
|
return "TLSv1.3"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|