# s3c

S3 兼容存储的命令行工具，支持 AWS S3、MinIO、Ceph 等。基于 `boto3` 封装，提供友好的终端交互体验。

## 安装

```bash
# 从源码安装
git clone https://github.com/yourname/s3c.git
cd s3c
uv sync
uv pip install -e .
```

## 配置

创建配置文件 `~/.config/s3c/credentials.json`：

```json
[
  {
    "name": "prod",
    "description": "生产环境 AWS S3",
    "endpoint_url": "https://s3.amazonaws.com",
    "access_key": "YOUR_ACCESS_KEY",
    "secret_key": "YOUR_SECRET_KEY",
    "region": "us-east-1"
  },
  {
    "name": "local",
    "description": "本地 MinIO 测试环境",
    "endpoint_url": "http://localhost:9000",
    "access_key": "minioadmin",
    "secret_key": "minioadmin",
    "region": "us-east-1"
  }
]
```

数组中第一个配置为默认配置，通过 `-c` 参数可指定其他配置。

## 使用

### 全局选项

```bash
s3c [-c <cluster>] <group> <command> [options]
```

### 查看配置

```bash
s3c clusters list
```

### Bucket 操作

```bash
# 基础操作
s3c bucket list
s3c bucket create my-bucket --region us-east-1
s3c bucket delete my-bucket --force   # --force 清空后删除
s3c bucket head my-bucket

# 版本控制
s3c bucket versioning-enable my-bucket
s3c bucket versioning-suspend my-bucket
s3c bucket versioning-get my-bucket

# 标签
s3c bucket tagging-put my-bucket "env=prod,team=ops"
s3c bucket tagging-get my-bucket
s3c bucket tagging-delete my-bucket

# ACL
s3c bucket acl-get my-bucket
s3c bucket acl-put my-bucket private

# 加密
s3c bucket encryption-put my-bucket --algorithm AES256
s3c bucket encryption-get my-bucket
s3c bucket encryption-delete my-bucket

# 生命周期
s3c bucket lifecycle-put my-bucket rules.json
s3c bucket lifecycle-get my-bucket
s3c bucket lifecycle-delete my-bucket

# CORS
s3c bucket cors-put my-bucket cors.json
s3c bucket cors-get my-bucket
s3c bucket cors-delete my-bucket

# Bucket Policy
s3c bucket policy-put my-bucket policy.json
s3c bucket policy-get my-bucket
s3c bucket policy-delete my-bucket

# 静态网站托管
s3c bucket website-put my-bucket --index index.html --error error.html
s3c bucket website-get my-bucket
s3c bucket website-delete my-bucket

# 访问日志
s3c bucket logging-put my-bucket my-logs-bucket --prefix access-logs/
s3c bucket logging-get my-bucket

# 公共访问阻止
s3c bucket public-access-put my-bucket
s3c bucket public-access-get my-bucket

# 跨区域复制
s3c bucket replication-put my-bucket replication.json
s3c bucket replication-get my-bucket
s3c bucket replication-delete my-bucket

# 事件通知
s3c bucket notification-put my-bucket notification.json
s3c bucket notification-get my-bucket

# 传输加速
s3c bucket accelerate-put my-bucket
s3c bucket accelerate-get my-bucket

# 请求支付
s3c bucket request-payment-put my-bucket --requester
s3c bucket request-payment-get my-bucket
```

### Object 操作

```bash
# 基础操作
s3c object list my-bucket
s3c object list my-bucket --prefix folder/ --delimiter /
s3c object put ./file.pdf my-bucket --key docs/file.pdf
s3c object get my-bucket docs/file.pdf --output /tmp/file.pdf
s3c object delete my-bucket docs/file.pdf
s3c object head my-bucket docs/file.pdf

# 复制与移动
s3c object copy src-bucket old/file.txt dst-bucket new/file.txt
s3c object move src-bucket old/file.txt dst-bucket new/file.txt

# 批量删除
s3c object delete-many my-bucket folder/ --dry-run  # 预览
s3c object delete-many my-bucket folder/

# 预签名 URL
s3c object presign my-bucket docs/file.pdf --expires 3600
s3c object presign my-bucket upload.txt --method put

# 版本管理
s3c object versions my-bucket docs/file.pdf
s3c object delete my-bucket docs/file.pdf --version-id <id>

# 标签
s3c object tagging-put my-bucket docs/file.pdf "type=doc,owner=alice"
s3c object tagging-get my-bucket docs/file.pdf
s3c object tagging-delete my-bucket docs/file.pdf

# ACL
s3c object acl-get my-bucket docs/file.pdf
s3c object acl-put my-bucket docs/file.pdf public-read

# 归档恢复（Glacier）
s3c object restore my-bucket archive/old.zip --days 7 --tier Standard

# 分片上传管理
s3c object multipart-list my-bucket
s3c object multipart-abort my-bucket large.zip <upload-id>
```

### 多配置切换

```bash
s3c -c prod bucket list
s3c --cluster dev object list my-bucket
```

## 开发

```bash
# 安装依赖
uv sync

# 安装到当前环境（editable）
make install

# 运行测试（需要启动 MinIO）
docker compose up -d
make test

# 构建发布包
make build
```

## 依赖

- [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) — AWS SDK
- [fire](https://github.com/google/python-fire) — CLI 框架
- [rich](https://rich.readthedocs.io/) — 终端美化输出
