mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
141 lines
4.7 KiB
Go
141 lines
4.7 KiB
Go
package s3api
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
|
)
|
|
|
|
// PutObjectRetentionHandler Put object Retention
|
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectRetention.html
|
|
func (s3a *S3ApiServer) PutObjectRetentionHandler(w http.ResponseWriter, r *http.Request) {
|
|
bucket, object := s3_constants.GetBucketAndObject(r)
|
|
glog.V(3).Infof("PutObjectRetentionHandler %s %s", bucket, object)
|
|
|
|
// Check if Object Lock is available for this bucket (requires versioning)
|
|
if !s3a.handleObjectLockAvailabilityCheck(w, r, bucket, "PutObjectRetentionHandler") {
|
|
return
|
|
}
|
|
|
|
// Get version ID from query parameters
|
|
versionId := r.URL.Query().Get("versionId")
|
|
|
|
// Evaluate governance bypass request (header + permission validation)
|
|
governanceBypassAllowed := s3a.evaluateGovernanceBypassRequest(r, bucket, object)
|
|
|
|
// Parse retention configuration from request body
|
|
retention, err := parseObjectRetention(r)
|
|
if err != nil {
|
|
glog.Errorf("PutObjectRetentionHandler: failed to parse retention config: %v", err)
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
|
|
return
|
|
}
|
|
|
|
// Validate retention configuration
|
|
if err := ValidateRetention(retention); err != nil {
|
|
glog.Errorf("PutObjectRetentionHandler: invalid retention config: %v", err)
|
|
s3err.WriteErrorResponse(w, r, mapValidationErrorToS3Error(err))
|
|
return
|
|
}
|
|
|
|
// Set retention on the object
|
|
if err := s3a.setObjectRetention(bucket, object, versionId, retention, governanceBypassAllowed); err != nil {
|
|
glog.Errorf("PutObjectRetentionHandler: failed to set retention: %v", err)
|
|
|
|
// Handle specific error cases
|
|
if errors.Is(err, ErrObjectNotFound) || errors.Is(err, ErrVersionNotFound) || errors.Is(err, ErrLatestVersionNotFound) {
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
|
return
|
|
}
|
|
|
|
if errors.Is(err, ErrComplianceModeActive) || errors.Is(err, ErrGovernanceModeActive) {
|
|
// Return 403 Forbidden for retention mode changes without proper permissions
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrAccessDenied)
|
|
return
|
|
}
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
return
|
|
}
|
|
|
|
// Add VersionId to response headers if available (expected by s3-tests)
|
|
if versionId != "" {
|
|
w.Header().Set("x-amz-version-id", versionId)
|
|
}
|
|
|
|
// Record metrics
|
|
stats_collect.RecordBucketActiveTime(bucket)
|
|
|
|
// Return success (HTTP 200 with no body)
|
|
w.WriteHeader(http.StatusOK)
|
|
glog.V(3).Infof("PutObjectRetentionHandler: successfully set retention for %s/%s", bucket, object)
|
|
}
|
|
|
|
// GetObjectRetentionHandler Get object Retention
|
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectRetention.html
|
|
func (s3a *S3ApiServer) GetObjectRetentionHandler(w http.ResponseWriter, r *http.Request) {
|
|
bucket, object := s3_constants.GetBucketAndObject(r)
|
|
glog.V(3).Infof("GetObjectRetentionHandler %s %s", bucket, object)
|
|
|
|
// Check if Object Lock is available for this bucket (requires versioning)
|
|
if !s3a.handleObjectLockAvailabilityCheck(w, r, bucket, "GetObjectRetentionHandler") {
|
|
return
|
|
}
|
|
|
|
// Get version ID from query parameters
|
|
versionId := r.URL.Query().Get("versionId")
|
|
|
|
// Get retention configuration for the object
|
|
retention, err := s3a.getObjectRetention(bucket, object, versionId)
|
|
if err != nil {
|
|
glog.Errorf("GetObjectRetentionHandler: failed to get retention: %v", err)
|
|
|
|
// Handle specific error cases
|
|
if errors.Is(err, ErrObjectNotFound) || errors.Is(err, ErrVersionNotFound) {
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
|
return
|
|
}
|
|
|
|
if errors.Is(err, ErrNoRetentionConfiguration) {
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrObjectLockConfigurationNotFoundError)
|
|
return
|
|
}
|
|
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
return
|
|
}
|
|
|
|
// Marshal retention configuration to XML
|
|
retentionXML, err := xml.Marshal(retention)
|
|
if err != nil {
|
|
glog.Errorf("GetObjectRetentionHandler: failed to marshal retention: %v", err)
|
|
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
|
return
|
|
}
|
|
|
|
// Set response headers
|
|
w.Header().Set("Content-Type", "application/xml")
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
// Write XML response
|
|
if _, err := w.Write([]byte(xml.Header)); err != nil {
|
|
glog.Errorf("GetObjectRetentionHandler: failed to write XML header: %v", err)
|
|
return
|
|
}
|
|
|
|
if _, err := w.Write(retentionXML); err != nil {
|
|
glog.Errorf("GetObjectRetentionHandler: failed to write retention XML: %v", err)
|
|
return
|
|
}
|
|
|
|
// Record metrics
|
|
stats_collect.RecordBucketActiveTime(bucket)
|
|
|
|
glog.V(3).Infof("GetObjectRetentionHandler: successfully retrieved retention for %s/%s", bucket, object)
|
|
}
|