lhj-tools 0.1.98 → 0.1.99
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/command/oss/del.rb +3 -8
- data/lib/lhj/command/oss/download.rb +29 -8
- data/lib/lhj/command/oss/info.rb +19 -1
- data/lib/lhj/command/oss/list.rb +2 -1
- data/lib/lhj/command/oss/update_bucket.rb +28 -0
- data/lib/lhj/command/oss/upload.rb +2 -0
- data/lib/lhj/command.rb +1 -0
- data/lib/lhj/helper/oss_config.rb +14 -0
- data/lib/lhj/helper/oss_helper.rb +22 -7
- data/lib/lhj/tools/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c1cb1e36ca0a061c4d3e53f5c0af5c0fb43f5c3dbb044fdd512c44f806a585d
|
4
|
+
data.tar.gz: 1ea501e7dde6f267da843ba2aa0f304e2ec038d0ed16f9a4b7348988d982ffab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04faa27361e9e260282b8ed9eaaec6d11336c7f5b4af80c069fc6f37956a485a178880ce6397aca1452d14fad32a47059b699bed3e6a67b75e98a5e57bc0921a
|
7
|
+
data.tar.gz: 6411de6c950b82eafcf5727c57cbd758a6d3350c1682171ba4bc589ad0ddde95b4a53344cf21b03148834af823f35f27bc0ce98585bfb682d744594257aa5ea8
|
data/lib/lhj/command/oss/del.rb
CHANGED
@@ -14,11 +14,8 @@ module Lhj
|
|
14
14
|
|
15
15
|
def handle
|
16
16
|
objects = Lhj::OSS::Helper.instance.list
|
17
|
-
obj_keys =
|
18
|
-
|
19
|
-
obj_keys << o.key
|
20
|
-
puts "#{i}.#{o.key}".yellow
|
21
|
-
end
|
17
|
+
obj_keys = objects.map(&:key)
|
18
|
+
obj_keys.each_with_index { |k, i| puts "#{i}.#{k}".yellow }
|
22
19
|
idx = @cli.ask('请选择删除的key: '.green)
|
23
20
|
idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
|
24
21
|
result_keys = []
|
@@ -28,9 +25,7 @@ module Lhj
|
|
28
25
|
result_keys << obj_keys[i.to_i] unless ma
|
29
26
|
end
|
30
27
|
oss_keys = result_keys.flatten
|
31
|
-
oss_keys.each
|
32
|
-
puts "删除的key为:#{oss_key}".red
|
33
|
-
end
|
28
|
+
oss_keys.each { |k| puts "删除的key为:#{k}".red }
|
34
29
|
Lhj::OSS::Helper.instance.batch_delete(oss_keys) if oss_keys.length > 0
|
35
30
|
end
|
36
31
|
|
@@ -8,19 +8,36 @@ module Lhj
|
|
8
8
|
class OSS < Command
|
9
9
|
class Download < OSS
|
10
10
|
|
11
|
+
def self.options
|
12
|
+
[
|
13
|
+
%w[--oss_key_file 本地下载的oss_key文件]
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
11
17
|
def initialize(argv)
|
12
18
|
@current_path = argv.shift_argument || Dir.pwd
|
13
19
|
@cli = HighLine.new
|
20
|
+
@oss_key_file = argv.option('oss_key_file')
|
14
21
|
super
|
15
22
|
end
|
16
23
|
|
17
24
|
def handle
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
puts "#{i}.#{o.key}".yellow
|
25
|
+
oss_keys = local_oss_keys if @oss_key_file
|
26
|
+
oss_keys ||= remote_oss_keys
|
27
|
+
Dir.chdir(@current_path) do
|
28
|
+
oss_keys.each { |k| download_with_key(k) }
|
23
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def local_oss_keys
|
33
|
+
key_file = File.join(@current_path, @oss_key_file)
|
34
|
+
oss_keys = []
|
35
|
+
oss_keys = YAML.load_file(key_file) if File.exist?(key_file)
|
36
|
+
oss_keys
|
37
|
+
end
|
38
|
+
|
39
|
+
def remote_oss_keys
|
40
|
+
obj_keys = request_oss_keys
|
24
41
|
idx = @cli.ask('请选择下载的序号: '.green)
|
25
42
|
idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
|
26
43
|
result_keys = []
|
@@ -29,9 +46,13 @@ module Lhj
|
|
29
46
|
result_keys << obj_keys[ma[:begin].to_i..ma[:end].to_i] if ma
|
30
47
|
result_keys << obj_keys[i.to_i] unless ma
|
31
48
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
49
|
+
result_keys.flatten
|
50
|
+
end
|
51
|
+
|
52
|
+
def request_oss_keys
|
53
|
+
objects = Lhj::OSS::Helper.instance.list
|
54
|
+
obj_keys = objects.map(&:key)
|
55
|
+
obj_keys.each_with_index { |k, i| puts "#{i}.#{k}".yellow }
|
35
56
|
end
|
36
57
|
|
37
58
|
def download_with_key(oss_key)
|
data/lib/lhj/command/oss/info.rb
CHANGED
@@ -7,7 +7,25 @@ module Lhj
|
|
7
7
|
class Info < OSS
|
8
8
|
|
9
9
|
def handle
|
10
|
-
|
10
|
+
puts '-------base-----------'
|
11
|
+
base_info
|
12
|
+
puts '-------alc-----------'
|
13
|
+
puts Lhj::OSS::Helper.instance.alc
|
14
|
+
puts '-------logging-----------'
|
15
|
+
puts Lhj::OSS::Helper.instance.logging
|
16
|
+
puts '-------lifecycle----------'
|
17
|
+
puts Lhj::OSS::Helper.instance.lifecycle
|
18
|
+
puts '-------cors-----------'
|
19
|
+
puts Lhj::OSS::Helper.instance.cors
|
20
|
+
puts '--------website----------'
|
21
|
+
puts Lhj::OSS::Helper.instance.website
|
22
|
+
puts '--------referer----------'
|
23
|
+
puts Lhj::OSS::Helper.instance.referer
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_info
|
27
|
+
puts Lhj::OSSConfig.oss_endpoint
|
28
|
+
puts Lhj::OSSConfig.oss_bucket
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
data/lib/lhj/command/oss/list.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'lhj/helper/oss_helper'
|
2
|
+
|
3
|
+
# lhj oss update-bucket
|
4
|
+
module Lhj
|
5
|
+
class Command
|
6
|
+
class OSS < Command
|
7
|
+
class UpdateBucket < OSS
|
8
|
+
|
9
|
+
def initialize(argv)
|
10
|
+
@cli = HighLine.new
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle
|
15
|
+
bucket_list = Lhj::OSSConfig.oss_bucket_list
|
16
|
+
return unless bucket_list.length.positive?
|
17
|
+
|
18
|
+
bucket_list.each_with_index { |k, i| puts "#{i}.#{k['name']}----#{k['location']}".yellow }
|
19
|
+
idx = @cli.ask('更新序号: '.green).strip.to_i
|
20
|
+
bucket = bucket_list[idx]
|
21
|
+
Lhj::OSSConfig.oss_endpoint = "#{bucket['location']}.aliyuncs.com"
|
22
|
+
Lhj::OSSConfig.oss_bucket = bucket['name']
|
23
|
+
Lhj::OSSConfig.save
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -22,6 +22,7 @@ module Lhj
|
|
22
22
|
def initialize(argv)
|
23
23
|
@current_path = argv.shift_argument || Dir.pwd
|
24
24
|
@tag = argv.option('tag')
|
25
|
+
@oss_key = argv.option('oss_key')
|
25
26
|
@cli = HighLine.new
|
26
27
|
super
|
27
28
|
end
|
@@ -51,6 +52,7 @@ module Lhj
|
|
51
52
|
|
52
53
|
def upload(file)
|
53
54
|
file_name = File.basename(file)
|
55
|
+
file_name = @oss_key if @oss_key
|
54
56
|
oss_key = file_name
|
55
57
|
oss_key = "#{@tag}/#{file_name}" if @tag
|
56
58
|
Lhj::OSS::Helper.instance.upload(oss_key, file)
|
data/lib/lhj/command.rb
CHANGED
@@ -19,6 +19,7 @@ module Lhj
|
|
19
19
|
require 'lhj/command/oss/list'
|
20
20
|
require 'lhj/command/oss/info'
|
21
21
|
require 'lhj/command/oss/list_bucket'
|
22
|
+
require 'lhj/command/oss/update_bucket'
|
22
23
|
require 'lhj/command/oss/download'
|
23
24
|
require 'lhj/command/code/view'
|
24
25
|
require 'lhj/command/code/code_template'
|
@@ -17,6 +17,10 @@ module Lhj
|
|
17
17
|
config['oss_endpoint']
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.oss_endpoint=(endpoint)
|
21
|
+
config['oss_endpoint'] = endpoint
|
22
|
+
end
|
23
|
+
|
20
24
|
def self.oss_access_key_id
|
21
25
|
config['oss_access_key_id']
|
22
26
|
end
|
@@ -29,8 +33,18 @@ module Lhj
|
|
29
33
|
config['oss_bucket']
|
30
34
|
end
|
31
35
|
|
36
|
+
def self.oss_bucket=(bucket)
|
37
|
+
config['oss_bucket'] = bucket
|
38
|
+
end
|
39
|
+
|
32
40
|
def self.oss_bucket_list
|
33
41
|
config['oss_bucket_list']
|
34
42
|
end
|
43
|
+
|
44
|
+
def self.save
|
45
|
+
file_to_save = File.open(config_file, 'w+')
|
46
|
+
YAML.dump(config, file_to_save)
|
47
|
+
file_to_save.close
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
@@ -73,13 +73,28 @@ module Lhj
|
|
73
73
|
@bucket.set_object_acl(key, acl)
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
def alc
|
77
|
+
@bucket.acl
|
78
|
+
end
|
79
|
+
|
80
|
+
def logging
|
81
|
+
@bucket.logging
|
82
|
+
end
|
83
|
+
|
84
|
+
def lifecycle
|
85
|
+
@bucket.lifecycle
|
86
|
+
end
|
87
|
+
|
88
|
+
def cors
|
89
|
+
@bucket.cors
|
90
|
+
end
|
91
|
+
|
92
|
+
def website
|
93
|
+
@bucket.website
|
94
|
+
end
|
95
|
+
|
96
|
+
def referer
|
97
|
+
@bucket.referer
|
83
98
|
end
|
84
99
|
|
85
100
|
def self.instance
|
data/lib/lhj/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhj-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.99
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xcodeproj
|
@@ -351,6 +351,7 @@ files:
|
|
351
351
|
- lib/lhj/command/oss/info.rb
|
352
352
|
- lib/lhj/command/oss/list.rb
|
353
353
|
- lib/lhj/command/oss/list_bucket.rb
|
354
|
+
- lib/lhj/command/oss/update_bucket.rb
|
354
355
|
- lib/lhj/command/oss/upload.rb
|
355
356
|
- lib/lhj/command/pgyer_upload.rb
|
356
357
|
- lib/lhj/command/refactor_rename.rb
|