Skip to content

Commit bffde89

Browse files
authored
Merge pull request #381 from YangSen-qn/support-lifecycle
Support lifecycle
2 parents 67a7c93 + 9255e55 commit bffde89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+853
-150
lines changed

.DS_Store

-6 KB
Binary file not shown.

README.md

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -225,51 +225,53 @@ qshell 命令配置 > 账号配置 > 全局配置
225225
| user | 账号 | 列举账号信息,在各个账号之间切换, 删除账号 | [文档](docs/user.md) |
226226

227227
### 存储相关命令
228-
| 命令 | 类别 | 描述 | 详细 |
229-
|----------------| ------ |-----------------------------------------|------------------------------|
230-
| mkbucket | 创建 | 创建存储空间 | [文档](docs/mkbucket.md) |
231-
| bucket | 查看 | 查看存储空间信息 | [文档](docs/bucket.md) |
232-
| batchdelete | 删除 | 批量删除七牛空间中的文件,可以直接根据 `listbucket` 的结果来删除 | [文档](docs/batchdelete.md) |
233-
| delete | 删除 | 删除七牛空间中的一个文件 | [文档](docs/delete.md) |
234-
| batchchgm | 修改 | 批量修改七牛空间中文件的MimeType | [文档](docs/batchchgm.md) |
235-
| chgm | 修改 | 修改七牛空间中的一个文件的MimeType | [文档](docs/chgm.md) |
236-
| batchchtype | 修改 | 批量修改七牛空间中的文件的存储类型 | [文档](docs/batchchtype.md) |
237-
| chtype | 修改 | 修改七牛空间中的一个文件的存储类型 | [文档](docs/chtype.md) |
238-
| batchexpire | 修改 | 批量修改七牛空间中的文件的生存时间 | [文档](docs/batchexpire.md) |
239-
| expire | 修改 | 修改七牛空间中的一个文件的生存时间 | [文档](docs/expire.md) |
240-
| batchcopy | 拷贝 | 批量复制七牛空间中的文件到另一个空间 | [文档](docs/batchcopy.md) |
241-
| copy | 拷贝 | 复制七牛空间中的一个文件 | [文档](docs/copy.md) |
242-
| batchmove | 移动 | 批量移动七牛空间中的文件到另一个空间 | [文档](docs/batchmove.md) |
243-
| move | 移动 | 移动或重命名七牛空间中的一个文件 | [文档](docs/move.md) |
244-
| batchrename | 重命名 | 批量重命名七牛空间中的文件 | [文档](docs/batchrename.md) |
245-
| rename | 重命名 | 重命名七牛空间中的文件 | [文档](docs/rename.md) |
246-
| batchrestorear | 解冻 | 批量解冻七牛空间中的归档/深度归档存储类型文件 | [文档](docs/batchrestorear.md) |
247-
| restorear | 解冻 | 解冻七牛空间中的归档/深度归档存储类型文件 | [文档](docs/restorear.md) |
248-
| batchstat | 查询 | 批量查询七牛空间中文件的基本信息 | [文档](docs/batchstat.md) |
249-
| stat | 查询 | 查询七牛空间中一个文件的基本信息 | [文档](docs/stat.md) |
250-
| buckets | 查询 | 获取当前账号下所有的空间名称 | [文档](docs/buckets.md) |
251-
| domains | 查询 | 获取指定空间的所有关联域名 | [文档](docs/domains.md) |
252-
| listbucket | 列举 | 列举七牛空间里面的所有文件 | [文档](docs/listbucket.md) |
253-
| listbucket2 | 列举 | 列举七牛空间里面的所有文件 | [文档](docs/listbucket2.md) |
254-
| batchforbidden | 禁用 | 批量修改文件可访问状态 | [文档](docs/batchforbidden.md) |
255-
| forbidden | 禁用 | 修改文件可访问状态 | [文档](docs/forbidden.md) |
256-
| fput | 上传 | 以文件表单的方式上传一个文件 | [文档](docs/fput.md) |
257-
| rput | 上传 | 以分片上传的方式上传一个文件 | [文档](docs/rput.md) |
258-
| qupload | 上传 | 同步数据到七牛空间, 带同步进度信息,和数据上传完整性检查(配置式) | [文档](docs/qupload.md) |
259-
| qupload2 | 上传 | 同步数据到七牛空间, 带同步进度信息,和数据上传完整性检查(命令式) | [文档](docs/qupload2.md) |
260-
| qdownload | 下载 | 从七牛空间同步数据到本地,支持只同步某些前缀的文件,支持增量同步(配置式) | [文档](docs/qdownload.md) |
261-
| qdownload2 | 下载 | 从七牛空间同步数据到本地,支持只同步某些前缀的文件,支持增量同步(命令式) | [文档](docs/qdownload2.md) |
262-
| get | 下载 | 下载存储空间中的文件 | [文档](docs/get.md) |
263-
| fetch | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中 | [文档](docs/fetch.md) |
264-
| batchfetch | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中 | [文档](docs/batchfetch.md) |
265-
| sync | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中,适合大文件的场合 | [文档](docs/sync.md) |
266-
| abfetch | 抓取 | 异步抓取网络资源到七牛存储空间 | [文档](docs/abfetch.md) |
267-
| m3u8delete | m3u8 | 根据流媒体播放列表文件删除七牛空间中的流媒体切片 | [文档](docs/m3u8delete.md) |
268-
| m3u8replace | m3u8 | 修改流媒体播放列表文件中的切片引用域名 | [文档](docs/m3u8replace.md) |
269-
| batchsign | 其他 | 批量根据资源的公开外链生成资源的私有外链 | [文档](docs/batchsign.md) |
270-
| dircache | 其他 | 输出本地指定路径下所有的文件列表 | [文档](docs/dircache.md) |
271-
| prefetch | 其他 | 更新七牛空间中从源站镜像过来的文件 | [文档](docs/prefetch.md) |
272-
| privateurl | 其他 | 生成私有空间资源的访问外链 | [文档](docs/privateurl.md) |
228+
| 命令 | 类别 | 描述 | 详细 |
229+
|------------------|------|-----------------------------------------|-----------------------------|
230+
| mkbucket | 创建 | 创建存储空间 | [文档](docs/mkbucket.md) |
231+
| bucket | 查看 | 查看存储空间信息 | [文档](docs/bucket.md) |
232+
| batchdelete | 删除 | 批量删除七牛空间中的文件,可以直接根据 `listbucket` 的结果来删除 | [文档](docs/batchdelete.md) |
233+
| delete | 删除 | 删除七牛空间中的一个文件 | [文档](docs/delete.md) |
234+
| batchchgm | 修改 | 批量修改七牛空间中文件的MimeType | [文档](docs/batchchgm.md) |
235+
| chgm | 修改 | 修改七牛空间中的一个文件的MimeType | [文档](docs/chgm.md) |
236+
| batchchtype | 修改 | 批量修改七牛空间中的文件的存储类型 | [文档](docs/batchchtype.md) |
237+
| chtype | 修改 | 修改七牛空间中的一个文件的存储类型 | [文档](docs/chtype.md) |
238+
| batchexpire | 修改 | 批量修改七牛空间中的文件的生存时间 | [文档](docs/batchexpire.md) |
239+
| expire | 修改 | 修改七牛空间中的一个文件的生存时间 | [文档](docs/expire.md) |
240+
| batchcopy | 拷贝 | 批量复制七牛空间中的文件到另一个空间 | [文档](docs/batchcopy.md) |
241+
| copy | 拷贝 | 复制七牛空间中的一个文件 | [文档](docs/copy.md) |
242+
| batchmove | 移动 | 批量移动七牛空间中的文件到另一个空间 | [文档](docs/batchmove.md) |
243+
| move | 移动 | 移动或重命名七牛空间中的一个文件 | [文档](docs/move.md) |
244+
| batchrename | 重命名 | 批量重命名七牛空间中的文件 | [文档](docs/batchrename.md) |
245+
| rename | 重命名 | 重命名七牛空间中的文件 | [文档](docs/rename.md) |
246+
| batchrestorear | 解冻 | 批量解冻七牛空间中的归档/深度归档存储类型文件 | [文档](docs/batchrestorear.md) |
247+
| restorear | 解冻 | 解冻七牛空间中的归档/深度归档存储类型文件 | [文档](docs/restorear.md) |
248+
| batchstat | 查询 | 批量查询七牛空间中文件的基本信息 | [文档](docs/batchstat.md) |
249+
| stat | 查询 | 查询七牛空间中一个文件的基本信息 | [文档](docs/stat.md) |
250+
| chlifecycle | 修改 | 修改七牛空间中一个文件的生命周期 | [文档](docs/chlifecycle.md) |
251+
| batchchlifecycle | 修改 | 批量修改七牛空间中文件的生命周期 | [文档](docs/batchchlifecycle.md) |
252+
| buckets | 查询 | 获取当前账号下所有的空间名称 | [文档](docs/buckets.md) |
253+
| domains | 查询 | 获取指定空间的所有关联域名 | [文档](docs/domains.md) |
254+
| listbucket | 列举 | 列举七牛空间里面的所有文件 | [文档](docs/listbucket.md) |
255+
| listbucket2 | 列举 | 列举七牛空间里面的所有文件 | [文档](docs/listbucket2.md) |
256+
| batchforbidden | 禁用 | 批量修改文件可访问状态 | [文档](docs/batchforbidden.md) |
257+
| forbidden | 禁用 | 修改文件可访问状态 | [文档](docs/forbidden.md) |
258+
| fput | 上传 | 以文件表单的方式上传一个文件 | [文档](docs/fput.md) |
259+
| rput | 上传 | 以分片上传的方式上传一个文件 | [文档](docs/rput.md) |
260+
| qupload | 上传 | 同步数据到七牛空间, 带同步进度信息,和数据上传完整性检查(配置式) | [文档](docs/qupload.md) |
261+
| qupload2 | 上传 | 同步数据到七牛空间, 带同步进度信息,和数据上传完整性检查(命令式) | [文档](docs/qupload2.md) |
262+
| qdownload | 下载 | 从七牛空间同步数据到本地,支持只同步某些前缀的文件,支持增量同步(配置式) | [文档](docs/qdownload.md) |
263+
| qdownload2 | 下载 | 从七牛空间同步数据到本地,支持只同步某些前缀的文件,支持增量同步(命令式) | [文档](docs/qdownload2.md) |
264+
| get | 下载 | 下载存储空间中的文件 | [文档](docs/get.md) |
265+
| fetch | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中 | [文档](docs/fetch.md) |
266+
| batchfetch | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中 | [文档](docs/batchfetch.md) |
267+
| sync | 抓取 | 从Internet上抓取一个资源并存储到七牛空间中,适合大文件的场合 | [文档](docs/sync.md) |
268+
| abfetch | 抓取 | 异步抓取网络资源到七牛存储空间 | [文档](docs/abfetch.md) |
269+
| m3u8delete | m3u8 | 根据流媒体播放列表文件删除七牛空间中的流媒体切片 | [文档](docs/m3u8delete.md) |
270+
| m3u8replace | m3u8 | 修改流媒体播放列表文件中的切片引用域名 | [文档](docs/m3u8replace.md) |
271+
| batchsign | 其他 | 批量根据资源的公开外链生成资源的私有外链 | [文档](docs/batchsign.md) |
272+
| dircache | 其他 | 输出本地指定路径下所有的文件列表 | [文档](docs/dircache.md) |
273+
| prefetch | 其他 | 更新七牛空间中从源站镜像过来的文件 | [文档](docs/prefetch.md) |
274+
| privateurl | 其他 | 生成私有空间资源的访问外链 | [文档](docs/privateurl.md) |
273275

274276

275277
### CDN 相关的命令

cmd/rs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ var deleteCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
6666
return cmd
6767
}
6868

69+
var changeLifecycleCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
70+
var info = &operations.ChangeLifecycleInfo{}
71+
var cmd = &cobra.Command{
72+
Use: "chlifecycle <Bucket> <Key> [--to-ia-after-days <ToIAAfterDays>] [--to-archive-after-days <ToArchiveAfterDays>] [--to-deep-archive-after-days <ToDeepArchiveAfterDays>] [--delete-after-days <DeleteAfterDays>]",
73+
Short: "Set the lifecycle of a file.",
74+
Long: `Set the lifecycle of a file. Lifecycle value must great than or equal to -1, unit: day.
75+
* less than -1: there's no point and it won't trigger any effect
76+
* equal to -1: cancel lifecycle
77+
* equal to 0: there's no point and it won't trigger any effect
78+
* bigger than 0: set lifecycle`,
79+
Run: func(cmd *cobra.Command, args []string) {
80+
cfg.CmdCfg.CmdId = docs.ChangeLifecycle
81+
if len(args) > 0 {
82+
info.Bucket = args[0]
83+
}
84+
if len(args) > 1 {
85+
info.Key = args[1]
86+
}
87+
operations.ChangeLifecycle(cfg, info)
88+
},
89+
}
90+
cmd.Flags().IntVarP(&info.ToIAAfterDays, "to-ia-after-days", "", 0, "to IA storage after some days. the range is -1 or bigger than 0. -1 means cancel to IA storage")
91+
cmd.Flags().IntVarP(&info.ToArchiveAfterDays, "to-archive-after-days", "", 0, "to archive storage after some days. the range is -1 or bigger than 0. -1 means cancel to archive storage")
92+
cmd.Flags().IntVarP(&info.ToDeepArchiveAfterDays, "to-deep-archive-after-days", "", 0, "to deep archive storage after some days. the range is -1 or bigger than 0. -1 means cancel to deep archive storage")
93+
cmd.Flags().IntVarP(&info.DeleteAfterDays, "delete-after-days", "", 0, "delete after some days. the range is -1 or bigger than 0. -1 means cancel to delete")
94+
return cmd
95+
}
96+
6997
var deleteAfterCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
7098
var info = operations.DeleteAfterInfo{}
7199
var cmd = &cobra.Command{
@@ -368,6 +396,7 @@ func rsCmdLoader(superCmd *cobra.Command, cfg *iqshell.Config) {
368396
superCmd.AddCommand(
369397
statCmdBuilder(cfg),
370398
forbiddenCmdBuilder(cfg),
399+
changeLifecycleCmdBuilder(cfg),
371400
deleteCmdBuilder(cfg),
372401
deleteAfterCmdBuilder(cfg),
373402
moveCmdBuilder(cfg),

cmd/rsbatch.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,33 @@ var batchDeleteAfterCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
154154
return cmd
155155
}
156156

157+
var batchChangeLifecycleCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
158+
var info = operations.BatchChangeLifecycleInfo{}
159+
var cmd = &cobra.Command{
160+
Use: "batchchlifecycle <Bucket> [-i <KeyFile>] [--to-ia-after-days <ToIAAfterDays>] [--to-archive-after-days <ToArchiveAfterDays>] [--to-deep-archive-after-days <ToDeepArchiveAfterDays>] [--delete-after-days <DeleteAfterDays>]",
161+
Short: "Set the lifecycle of some file.",
162+
Long: `Set the lifecycle of some file. <KeyFile> contain all file keys that need to set. one key per line.
163+
Lifecycle value must great than or equal to -1, unit: day.
164+
* less than -1: there's no point and it won't trigger any effect
165+
* equal to -1: cancel lifecycle
166+
* equal to 0: there's no point and it won't trigger any effect
167+
* bigger than 0: set lifecycle`,
168+
Run: func(cmd *cobra.Command, args []string) {
169+
cfg.CmdCfg.CmdId = docs.BatchChangeLifecycle
170+
if len(args) > 0 {
171+
info.Bucket = args[0]
172+
}
173+
operations.BatchChangeLifecycle(cfg, info)
174+
},
175+
}
176+
cmd.Flags().IntVarP(&info.ToIAAfterDays, "to-ia-after-days", "", 0, "to IA storage after some days. the range is -1 or bigger than 0. -1 means cancel to IA storage")
177+
cmd.Flags().IntVarP(&info.ToArchiveAfterDays, "to-archive-after-days", "", 0, "to archive storage after some days. the range is -1 or bigger than 0. -1 means cancel to archive storage")
178+
cmd.Flags().IntVarP(&info.ToDeepArchiveAfterDays, "to-deep-archive-after-days", "", 0, "to deep archive storage after some days. the range is -1 or bigger than 0. -1 means cancel to deep archive storage")
179+
cmd.Flags().IntVarP(&info.DeleteAfterDays, "delete-after-days", "", 0, "delete after some days. the range is -1 or bigger than 0. -1 means cancel to delete")
180+
setBatchCmdDefaultFlags(cmd, &info.BatchInfo)
181+
return cmd
182+
}
183+
157184
var batchMoveCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
158185
var info = operations.BatchMoveInfo{}
159186
var cmd = &cobra.Command{
@@ -326,6 +353,7 @@ func rsBatchCmdLoader(superCmd *cobra.Command, cfg *iqshell.Config) {
326353
batchMoveCmdBuilder(cfg),
327354
batchRenameCmdBuilder(cfg),
328355
batchDeleteCmdBuilder(cfg),
356+
batchChangeLifecycleCmdBuilder(cfg),
329357
batchDeleteAfterCmdBuilder(cfg),
330358
batchChangeMimeCmdBuilder(cfg),
331359
batchChangeTypeCmdBuilder(cfg),

cmd_test/ali_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import (
1010

1111
func TestAliBucketListNoDataCenter(t *testing.T) {
1212
_, errs := test.RunCmdWithError("alilistbucket")
13-
if !strings.Contains(errs, "DataCenter can't empty") {
13+
if !strings.Contains(errs, "DataCenter can't be empty") {
1414
t.Fatal("empty DataCenter check error")
1515
}
1616
return
1717
}
1818

1919
func TestAliBucketListNoBucket(t *testing.T) {
2020
_, errs := test.RunCmdWithError("alilistbucket", "DataCenter")
21-
if !strings.Contains(errs, "Bucket can't empty") {
21+
if !strings.Contains(errs, "Bucket can't be empty") {
2222
t.Fatal("empty Bucket check error")
2323
}
2424
return
2525
}
2626

2727
func TestAliBucketListNoAccessKeyId(t *testing.T) {
2828
_, errs := test.RunCmdWithError("alilistbucket", "DataCenter", "Bucket")
29-
if !strings.Contains(errs, "AccessKeyId can't empty") {
29+
if !strings.Contains(errs, "AccessKeyId can't be empty") {
3030
t.Fatal("empty AccessKeyId check error")
3131
}
3232

@@ -35,7 +35,7 @@ func TestAliBucketListNoAccessKeyId(t *testing.T) {
3535

3636
func TestAliBucketListNoAccessKeySecret(t *testing.T) {
3737
_, errs := test.RunCmdWithError("alilistbucket", "DataCenter", "Bucket", "AccessKeyId")
38-
if !strings.Contains(errs, "AccessKeySecret can't empty") {
38+
if !strings.Contains(errs, "AccessKeySecret can't be empty") {
3939
t.Fatal("empty AccessKeySecret check error")
4040
}
4141
return

cmd_test/async_fetch_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ func TestAsyncFetch(t *testing.T) {
4444
test.RemoveFile(successLogPath)
4545
}()
4646
if !test.IsFileHasContent(successLogPath) {
47-
t.Fatal("success log can't empty")
47+
t.Fatal("success log can't be empty")
4848
}
4949

5050
if !test.IsFileHasContent(failLogPath) {
51-
t.Fatal("fail log can't empty")
51+
t.Fatal("fail log can't be empty")
5252
}
5353
}
5454

5555
func TestAsyncFetchNoBucket(t *testing.T) {
5656
_, err := test.RunCmdWithError("abfetch")
57-
if !strings.Contains(err, "Bucket can't empty") {
57+
if !strings.Contains(err, "Bucket can't be empty") {
5858
t.Fail()
5959
}
6060
}
@@ -73,14 +73,14 @@ func TestACheck(t *testing.T) {
7373

7474
func TestACheckNoId(t *testing.T) {
7575
_, err := test.RunCmdWithError("acheck", test.Bucket)
76-
if !strings.Contains(err, "Id can't empty") {
76+
if !strings.Contains(err, "Id can't be empty") {
7777
t.Fail()
7878
}
7979
}
8080

8181
func TestACheckNoBucket(t *testing.T) {
8282
_, err := test.RunCmdWithError("acheck")
83-
if !strings.Contains(err, "Bucket can't empty") {
83+
if !strings.Contains(err, "Bucket can't be empty") {
8484
t.Fail()
8585
}
8686
}

0 commit comments

Comments
 (0)