oss-client 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +1 -0
- data/README.md +64 -0
- data/VERSION +1 -0
- data/bin/oss-client +113 -0
- data/oss-client.gemspec +22 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ebd5ecf2cb9580dcb77ac960b443d851a3fd358
|
4
|
+
data.tar.gz: fba6852827b976406a7a4274f5943ccc3861b7ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61841e701790248f0d5eb2d9243fd017eb48d64e97b54a158128ef5434d42819c36869f2eaee5ae304360ddaaa37c008422f5cb78b1fdaedb5ebbf4bd600e103
|
7
|
+
data.tar.gz: 4c390407650d3c700fe395ff68a72dc5f99c1d9486cf24177de38f87b06264c92568480f940cc0bdea73afec85e2543da924efb430612a4cfcd158df9791e3d2
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
## Aliyun oss client for [Fluent-plugin-oss](https://github.com/jicong/fluent-plugin-oss)
|
2
|
+
|
3
|
+
## Install
|
4
|
+
```
|
5
|
+
gem install oss-client
|
6
|
+
```
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
### Basic
|
10
|
+
Set oss account by arguments.
|
11
|
+
|
12
|
+
```
|
13
|
+
oss-client --endpoint xxx --access_key_id xxx --access_key_secret xxx --bucket xxx oss-client command
|
14
|
+
```
|
15
|
+
|
16
|
+
You can also use enviroment variables.
|
17
|
+
|
18
|
+
```
|
19
|
+
ENDPOINT=xxx ACCESS_KEY_ID=xxx ACCESS_KEY_SECRET=xxx BUCKET=xxx oss-client command
|
20
|
+
```
|
21
|
+
|
22
|
+
### List
|
23
|
+
Get objects list from oss with a specific prefix.
|
24
|
+
|
25
|
+
```
|
26
|
+
oss-client list -p xxx #The prefix argument works in all commands
|
27
|
+
```
|
28
|
+
|
29
|
+
### Summary
|
30
|
+
Get objects count in all vitual directories.
|
31
|
+
|
32
|
+
```
|
33
|
+
oss-client summary
|
34
|
+
```
|
35
|
+
|
36
|
+
Specify the delimiter(default: '/').
|
37
|
+
|
38
|
+
```
|
39
|
+
oss-client summary -d -
|
40
|
+
```
|
41
|
+
|
42
|
+
Count sub-directories.
|
43
|
+
|
44
|
+
```
|
45
|
+
oss-client summary --max-depth=2
|
46
|
+
```
|
47
|
+
|
48
|
+
### Delete
|
49
|
+
Remove objects in oss.
|
50
|
+
|
51
|
+
```
|
52
|
+
oss-client delete
|
53
|
+
```
|
54
|
+
|
55
|
+
Then type 'Y' to confirm.
|
56
|
+
|
57
|
+
### Download
|
58
|
+
Use download-dir argument to specify the download directory(default: current dir).
|
59
|
+
|
60
|
+
```
|
61
|
+
oss-client download
|
62
|
+
```
|
63
|
+
|
64
|
+
If there is an object named 'a/b/c.jpg', directories 'a' and 'b' will be create recursively.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
data/bin/oss-client
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'aliyun/oss'
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'progress_bar'
|
6
|
+
|
7
|
+
options = {
|
8
|
+
delimiter: '/',
|
9
|
+
max_depth: 1,
|
10
|
+
download_dir: '.'
|
11
|
+
}
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: oss-client command [options]"
|
15
|
+
|
16
|
+
opts.on("--endpoint [STRING]", "Aliyun oss endpoint") do |str|
|
17
|
+
options[:endpoint] = str
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("--access_key_id [STRING]", "Aliyun oss access key id") do |str|
|
21
|
+
options[:access_key_id] = str
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("--access_key_secret [STRING]", "Aliyun oss access key secret") do |str|
|
25
|
+
options[:access_key_secret] = str
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("--bucket [STRING]", "Aliyun oss bucket name") do |str|
|
29
|
+
options[:bucket] = str
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-p", "--prefix [STRING]", "Prefix filter for oss objects") do |str|
|
33
|
+
options[:prefix] = str
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-d", "--delimiter [DEMILITER]", "Path delimiter for oss objects(default '/')") do |str|
|
37
|
+
options[:delimiter] = str
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("--max-depth [INTEGER]", OptionParser::DecimalInteger, "Max depth for command 'summary'(default 1)") do |int|
|
41
|
+
options[:max_depth] = int
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("--download-dir [PATH]", "Download path(default '.'") do |path|
|
45
|
+
options[:download_dir] = path
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
49
|
+
puts opts
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on_tail("--version", "Show version") do
|
54
|
+
puts File.read(File.join(File.dirname(__FILE__), '../VERSION'))
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
end.parse!
|
58
|
+
|
59
|
+
client = Aliyun::OSS::Client.new(
|
60
|
+
:endpoint => options[:endpoint] || ENV['ENDPOINT'],
|
61
|
+
:access_key_id => options[:access_key_id] || ENV['ACCESS_KEY_ID'],
|
62
|
+
:access_key_secret => options[:access_key_secret] || ENV['ACCESS_KEY_SECRET'])
|
63
|
+
bucket = client.get_bucket(options[:bucket] || ENV['BUCKET'])
|
64
|
+
|
65
|
+
case cmd = ARGV.pop
|
66
|
+
when 'list'
|
67
|
+
objects = bucket.list_objects(prefix: options[:prefix])
|
68
|
+
objects.each do |o|
|
69
|
+
puts o.key
|
70
|
+
end
|
71
|
+
when 'summary'
|
72
|
+
objects = bucket.list_objects(prefix: options[:prefix])
|
73
|
+
map = {}
|
74
|
+
objects.each do |o|
|
75
|
+
key = o.key.split(options[:delimiter])[0..options[:max_depth]-1].join(options[:delimiter])
|
76
|
+
map[key] ||= 0
|
77
|
+
map[key] += 1
|
78
|
+
end
|
79
|
+
map.each do |k, v|
|
80
|
+
puts "#{k}(#{v})"
|
81
|
+
end
|
82
|
+
when 'delete'
|
83
|
+
objects = bucket.list_objects(prefix: options[:prefix])
|
84
|
+
list = []
|
85
|
+
objects.each do |o|
|
86
|
+
puts o.key
|
87
|
+
list << o.key
|
88
|
+
end
|
89
|
+
unless list.empty?
|
90
|
+
puts "\nDelete all of above?(Y/N)"
|
91
|
+
list.each do |e|
|
92
|
+
puts "Deleting #{e}"
|
93
|
+
bucket.delete_object(e)
|
94
|
+
end if STDIN.gets(1).upcase == 'Y'
|
95
|
+
end
|
96
|
+
when 'download'
|
97
|
+
objects = bucket.list_objects(prefix: options[:prefix])
|
98
|
+
objects.each do |o|
|
99
|
+
arr = o.key.split(options[:delimiter])
|
100
|
+
filename = arr.pop
|
101
|
+
dir = File.join(options[:download_dir], arr.join('/'))
|
102
|
+
FileUtils.mkdir_p dir
|
103
|
+
puts "Downloading #{o.key}"
|
104
|
+
bar = ProgressBar.new(100, :bar, :percentage, :elapsed, :eta)
|
105
|
+
bucket.resumable_download(o.key, File.join(dir, filename)) do |p|
|
106
|
+
bar.increment!(p*100 - bar.count)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
when nil
|
110
|
+
raise 'Need to specify a command(list/summary/delete/download).See more in README.md'
|
111
|
+
else
|
112
|
+
raise "Command not supported: #{cmd}"
|
113
|
+
end
|
data/oss-client.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "oss-client"
|
5
|
+
gem.description = "Aliyun oss client"
|
6
|
+
gem.license = "MIT"
|
7
|
+
gem.homepage = "https://github.com/jicong/oss-client"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["sjtubreeze"]
|
11
|
+
gem.email = "sjtubreeze@163.com"
|
12
|
+
gem.has_rdoc = false
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_dependency "aliyun-sdk", [">= 0.6.0"]
|
19
|
+
gem.add_dependency "progress_bar", [">= 1.1.0"]
|
20
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
21
|
+
gem.add_development_dependency "test-unit", ">= 3.0.8"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oss-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sjtubreeze
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aliyun-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: progress_bar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.8
|
69
|
+
description: Aliyun oss client
|
70
|
+
email: sjtubreeze@163.com
|
71
|
+
executables:
|
72
|
+
- oss-client
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- README.md
|
78
|
+
- VERSION
|
79
|
+
- bin/oss-client
|
80
|
+
- oss-client.gemspec
|
81
|
+
homepage: https://github.com/jicong/oss-client
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Aliyun oss client
|
105
|
+
test_files: []
|