Files
s3/weed/shell/command_s3tables_namespace.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
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.
2026-06-18 23:41:25 -07:00

132 lines
4.2 KiB
Go

package shell
import (
"flag"
"fmt"
"io"
"strings"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
)
func init() {
Commands = append(Commands, &commandS3TablesNamespace{})
}
type commandS3TablesNamespace struct{}
func (c *commandS3TablesNamespace) Name() string {
return "s3tables.namespace"
}
func (c *commandS3TablesNamespace) Help() string {
return `manage s3tables namespaces
# create a namespace
s3tables.namespace -create -bucket <bucket> -account <account_id> -name <namespace>
# list namespaces
s3tables.namespace -list -bucket <bucket> -account <account_id> [-prefix <prefix>] [-limit <n>] [-continuation <token>]
# get namespace details
s3tables.namespace -get -bucket <bucket> -account <account_id> -name <namespace>
# delete namespace
s3tables.namespace -delete -bucket <bucket> -account <account_id> -name <namespace>
`
}
func (c *commandS3TablesNamespace) HasTag(CommandTag) bool {
return false
}
func (c *commandS3TablesNamespace) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
cmd := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
create := cmd.Bool("create", false, "create namespace")
list := cmd.Bool("list", false, "list namespaces")
get := cmd.Bool("get", false, "get namespace")
deleteNamespace := cmd.Bool("delete", false, "delete namespace")
bucketName := cmd.String("bucket", "", "table bucket name")
account := cmd.String("account", "", "owner account id")
name := cmd.String("name", "", "namespace name")
prefix := cmd.String("prefix", "", "namespace prefix")
limit := cmd.Int("limit", 100, "max namespaces to return")
continuation := cmd.String("continuation", "", "continuation token")
if err := cmd.Parse(args); err != nil {
return err
}
actions := []*bool{create, list, get, deleteNamespace}
count := 0
for _, action := range actions {
if *action {
count++
}
}
if count != 1 {
return fmt.Errorf("exactly one action must be specified")
}
if *bucketName == "" {
return fmt.Errorf("-bucket is required")
}
if *account == "" {
return fmt.Errorf("-account is required")
}
bucketArn, err := buildS3TablesBucketARN(*bucketName, *account)
if err != nil {
return err
}
namespace := strings.TrimSpace(*name)
if (namespace == "" || namespace == "-") && (*create || *get || *deleteNamespace) {
return fmt.Errorf("-name is required")
}
switch {
case *create:
req := &s3tables.CreateNamespaceRequest{TableBucketARN: bucketArn, Namespace: []string{namespace}}
var resp s3tables.CreateNamespaceResponse
if err := executeS3Tables(commandEnv, "CreateNamespace", req, &resp, *account); err != nil {
return parseS3TablesError(err)
}
fmt.Fprintf(writer, "Namespace: %s\n", strings.Join(resp.Namespace, "/"))
case *list:
req := &s3tables.ListNamespacesRequest{TableBucketARN: bucketArn, Prefix: *prefix, ContinuationToken: *continuation, MaxNamespaces: *limit}
var resp s3tables.ListNamespacesResponse
if err := executeS3Tables(commandEnv, "ListNamespaces", req, &resp, *account); err != nil {
return parseS3TablesError(err)
}
if len(resp.Namespaces) == 0 {
fmt.Fprintln(writer, "No namespaces found")
return nil
}
for _, ns := range resp.Namespaces {
fmt.Fprintf(writer, "Namespace: %s\n", strings.Join(ns.Namespace, "/"))
fmt.Fprintf(writer, "CreatedAt: %s\n", ns.CreatedAt.Format(timeFormat))
fmt.Fprintln(writer, "---")
}
if resp.ContinuationToken != "" {
fmt.Fprintf(writer, "ContinuationToken: %s\n", resp.ContinuationToken)
}
case *get:
req := &s3tables.GetNamespaceRequest{TableBucketARN: bucketArn, Namespace: []string{namespace}}
var resp s3tables.GetNamespaceResponse
if err := executeS3Tables(commandEnv, "GetNamespace", req, &resp, *account); err != nil {
return parseS3TablesError(err)
}
fmt.Fprintf(writer, "Namespace: %s\n", strings.Join(resp.Namespace, "/"))
fmt.Fprintf(writer, "OwnerAccountID: %s\n", resp.OwnerAccountID)
fmt.Fprintf(writer, "CreatedAt: %s\n", resp.CreatedAt.Format(timeFormat))
case *deleteNamespace:
req := &s3tables.DeleteNamespaceRequest{TableBucketARN: bucketArn, Namespace: []string{namespace}}
if err := executeS3Tables(commandEnv, "DeleteNamespace", req, nil, *account); err != nil {
return parseS3TablesError(err)
}
fmt.Fprintln(writer, "Namespace deleted")
}
return nil
}