bunbun 1.1.2 → 2.0.0
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 +4 -4
- data/CHANGES.md +6 -0
- data/LICENSE.txt +1 -1
- data/README.md +0 -28
- data/bunbun.gemspec +0 -1
- data/lib/bunbun/client/dns/statistics.rb +10 -0
- data/lib/bunbun/client/dns.rb +40 -0
- data/lib/bunbun/client.rb +4 -0
- data/lib/bunbun.rb +1 -2
- metadata +5 -28
- data/bin/bunny +0 -14
- data/lib/bunbun/cli/command.rb +0 -97
- data/lib/bunbun/cli/countries.rb +0 -12
- data/lib/bunbun/cli/keys.rb +0 -13
- data/lib/bunbun/cli/purge.rb +0 -5
- data/lib/bunbun/cli/regions.rb +0 -16
- data/lib/bunbun/cli/storage_command.rb +0 -21
- data/lib/bunbun/cli/storage_delete.rb +0 -9
- data/lib/bunbun/cli/storage_download.rb +0 -9
- data/lib/bunbun/cli/storage_edit.rb +0 -29
- data/lib/bunbun/cli/storage_files.rb +0 -22
- data/lib/bunbun/cli/storage_upload.rb +0 -20
- data/lib/bunbun/cli/storage_zone.rb +0 -5
- data/lib/bunbun/cli/storage_zone_create.rb +0 -5
- data/lib/bunbun/cli/storage_zones.rb +0 -17
- data/lib/bunbun/cli/zone.rb +0 -5
- data/lib/bunbun/cli/zone_create.rb +0 -5
- data/lib/bunbun/cli/zone_purge.rb +0 -5
- data/lib/bunbun/cli/zone_rules_delete.rb +0 -5
- data/lib/bunbun/cli/zone_rules_disenable.rb +0 -5
- data/lib/bunbun/cli/zone_rules_enable.rb +0 -5
- data/lib/bunbun/cli/zone_rules_post.rb +0 -5
- data/lib/bunbun/cli/zones.rb +0 -18
- data/lib/bunbun/cli.rb +0 -123
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 507d9d4d026ad4ecc32d38c408cb1480bd061f8cfff3f396806307ec3e6d24b7
|
|
4
|
+
data.tar.gz: cebcb7aa007f6df01ade714d61e76cbf46b5b063a0084dca19e5ab9db2e8b77f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3dde63b7412bcdd3b7937bb08061e504e1cb2ebcf6f4fb1a8bd690d79107b78b6533ae3e7721678cb86e528bf165ef8789cb8c434d2b7dfa23270d4f3bfaea67
|
|
7
|
+
data.tar.gz: 480723017f35b461af042e6a221bfad44a039cfbdd104b930e4ee8b501b72ef481d6f5cd8aa7b0aff204ab01384a03d6e8d058a37eddb32109b6fe7fa08f91c9
|
data/CHANGES.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -48,31 +48,3 @@ client.download("/#{zone}/#{file}", file)
|
|
|
48
48
|
|
|
49
49
|
You can store your access key in a `BUNNY_ACCESS_KEY` environment variable,
|
|
50
50
|
and the storage host in a `BUNNY_HOST` environment variable.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## CLI
|
|
54
|
-
|
|
55
|
-
The gem also includes a command line tool.
|
|
56
|
-
|
|
57
|
-
Store your access keys in your .netrc file, for example:
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
machine api.bunny.net
|
|
61
|
-
login user
|
|
62
|
-
password xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
63
|
-
machine storage.bunnycdn.com
|
|
64
|
-
login zone-name
|
|
65
|
-
password xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxx-xxxx
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Specify the access key for the bunny.net API, and any additional keys for
|
|
69
|
-
accessing edge storage. The login for the api.bunny.net entry can be anything,
|
|
70
|
-
the login for each storage entry should be the name of the storage zone.
|
|
71
|
-
|
|
72
|
-
You can then use the `bunny` command line tool like this:
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
$ bunny storage zones
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Run the tool without any arguments to see a list of available commands.
|
data/bunbun.gemspec
CHANGED
|
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md bunbun.gemspec]
|
|
14
14
|
s.required_ruby_version = '>= 3.3.0'
|
|
15
15
|
s.require_path = 'lib'
|
|
16
|
-
s.executables = ['bunny']
|
|
17
16
|
s.metadata = {
|
|
18
17
|
'homepage' => 'https://github.com/readysteady/bunbun',
|
|
19
18
|
'source_code_uri' => 'https://github.com/readysteady/bunbun',
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BunBun::Client::DNS < BunBun::Client::Namespace
|
|
4
|
+
autoload :Statistics, 'bunbun/client/dns/statistics'
|
|
5
|
+
|
|
6
|
+
def initialize(client)
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@statistics = Statistics.new(client)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create(body_params)
|
|
13
|
+
@client.post('/dnszone', BunBun::Body.transform_keys(body_params))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def delete(id)
|
|
17
|
+
@client.delete("/dnszone/#{id}")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get(id)
|
|
21
|
+
@client.get("/dnszone/#{id}")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def list(page: nil, per_page: nil, search: nil, view: nil)
|
|
25
|
+
params = {
|
|
26
|
+
page: page,
|
|
27
|
+
perPage: per_page,
|
|
28
|
+
search: search,
|
|
29
|
+
view: view,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@client.get(BunBun::URI.join('/dnszone', params))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
attr_reader :statistics
|
|
36
|
+
|
|
37
|
+
def update(id, body_params)
|
|
38
|
+
@client.post("/dnszone/#{id}", BunBun::Body.transform_keys(body_params))
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/bunbun/client.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'json'
|
|
|
5
5
|
class BunBun::Client
|
|
6
6
|
autoload :ApiKey, 'bunbun/client/api_key'
|
|
7
7
|
autoload :Country, 'bunbun/client/country'
|
|
8
|
+
autoload :DNS, 'bunbun/client/dns'
|
|
8
9
|
autoload :Namespace, 'bunbun/client/namespace'
|
|
9
10
|
autoload :PullZone, 'bunbun/client/pull_zone'
|
|
10
11
|
autoload :Region, 'bunbun/client/region'
|
|
@@ -23,6 +24,7 @@ class BunBun::Client
|
|
|
23
24
|
@user_agent = "ruby/#{RUBY_VERSION} bunbun/#{BunBun::VERSION}"
|
|
24
25
|
@api_key = BunBun::Client::ApiKey.new(self)
|
|
25
26
|
@country = BunBun::Client::Country.new(self)
|
|
27
|
+
@dns = BunBun::Client::DNS.new(self)
|
|
26
28
|
@pull_zone = BunBun::Client::PullZone.new(self)
|
|
27
29
|
@region = BunBun::Client::Region.new(self)
|
|
28
30
|
@statistics = BunBun::Client::Statistics.new(self)
|
|
@@ -43,6 +45,8 @@ class BunBun::Client
|
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
48
|
+
attr_reader :dns
|
|
49
|
+
|
|
46
50
|
def download(path, destination = nil)
|
|
47
51
|
start do |http|
|
|
48
52
|
message = Net::HTTP::Get.new(path)
|
data/lib/bunbun.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module BunBun
|
|
4
|
-
VERSION = '
|
|
4
|
+
VERSION = '2.0.0'
|
|
5
5
|
|
|
6
6
|
Error = Class.new(StandardError)
|
|
7
7
|
ClientError = Class.new(Error)
|
|
@@ -9,7 +9,6 @@ module BunBun
|
|
|
9
9
|
|
|
10
10
|
autoload :Base64, 'bunbun/base64'
|
|
11
11
|
autoload :Body, 'bunbun/body'
|
|
12
|
-
autoload :CLI, 'bunbun/cli'
|
|
13
12
|
autoload :Client, 'bunbun/client'
|
|
14
13
|
autoload :Response, 'bunbun/response'
|
|
15
14
|
autoload :URI, 'bunbun/uri'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bunbun
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Craft
|
|
@@ -68,45 +68,22 @@ dependencies:
|
|
|
68
68
|
description: Ruby client for bunny.net
|
|
69
69
|
email:
|
|
70
70
|
- email@timcraft.com
|
|
71
|
-
executables:
|
|
72
|
-
- bunny
|
|
71
|
+
executables: []
|
|
73
72
|
extensions: []
|
|
74
73
|
extra_rdoc_files: []
|
|
75
74
|
files:
|
|
76
75
|
- CHANGES.md
|
|
77
76
|
- LICENSE.txt
|
|
78
77
|
- README.md
|
|
79
|
-
- bin/bunny
|
|
80
78
|
- bunbun.gemspec
|
|
81
79
|
- lib/bunbun.rb
|
|
82
80
|
- lib/bunbun/base64.rb
|
|
83
81
|
- lib/bunbun/body.rb
|
|
84
|
-
- lib/bunbun/cli.rb
|
|
85
|
-
- lib/bunbun/cli/command.rb
|
|
86
|
-
- lib/bunbun/cli/countries.rb
|
|
87
|
-
- lib/bunbun/cli/keys.rb
|
|
88
|
-
- lib/bunbun/cli/purge.rb
|
|
89
|
-
- lib/bunbun/cli/regions.rb
|
|
90
|
-
- lib/bunbun/cli/storage_command.rb
|
|
91
|
-
- lib/bunbun/cli/storage_delete.rb
|
|
92
|
-
- lib/bunbun/cli/storage_download.rb
|
|
93
|
-
- lib/bunbun/cli/storage_edit.rb
|
|
94
|
-
- lib/bunbun/cli/storage_files.rb
|
|
95
|
-
- lib/bunbun/cli/storage_upload.rb
|
|
96
|
-
- lib/bunbun/cli/storage_zone.rb
|
|
97
|
-
- lib/bunbun/cli/storage_zone_create.rb
|
|
98
|
-
- lib/bunbun/cli/storage_zones.rb
|
|
99
|
-
- lib/bunbun/cli/zone.rb
|
|
100
|
-
- lib/bunbun/cli/zone_create.rb
|
|
101
|
-
- lib/bunbun/cli/zone_purge.rb
|
|
102
|
-
- lib/bunbun/cli/zone_rules_delete.rb
|
|
103
|
-
- lib/bunbun/cli/zone_rules_disenable.rb
|
|
104
|
-
- lib/bunbun/cli/zone_rules_enable.rb
|
|
105
|
-
- lib/bunbun/cli/zone_rules_post.rb
|
|
106
|
-
- lib/bunbun/cli/zones.rb
|
|
107
82
|
- lib/bunbun/client.rb
|
|
108
83
|
- lib/bunbun/client/api_key.rb
|
|
109
84
|
- lib/bunbun/client/country.rb
|
|
85
|
+
- lib/bunbun/client/dns.rb
|
|
86
|
+
- lib/bunbun/client/dns/statistics.rb
|
|
110
87
|
- lib/bunbun/client/namespace.rb
|
|
111
88
|
- lib/bunbun/client/pull_zone.rb
|
|
112
89
|
- lib/bunbun/client/pull_zone/edge_rules.rb
|
|
@@ -137,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
137
114
|
- !ruby/object:Gem::Version
|
|
138
115
|
version: '0'
|
|
139
116
|
requirements: []
|
|
140
|
-
rubygems_version: 4.0.
|
|
117
|
+
rubygems_version: 4.0.10
|
|
141
118
|
specification_version: 4
|
|
142
119
|
summary: Ruby client for bunny.net
|
|
143
120
|
test_files: []
|
data/bin/bunny
DELETED
data/lib/bunbun/cli/command.rb
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'optparse'
|
|
3
|
-
require 'tabulo'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
class BunBun::CLI::Command
|
|
7
|
-
def self.options
|
|
8
|
-
@options ||= []
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.option(name)
|
|
12
|
-
options << name
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.argument_names
|
|
16
|
-
@argument_names ||= instance_method(:call).parameters.select { _1[0] == :req || _1[0] == :opt }.map { _1[1] }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.argument_count
|
|
20
|
-
argument_names.length
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def option_parser
|
|
24
|
-
OptionParser.new do |opts|
|
|
25
|
-
self.class.options.each do |name|
|
|
26
|
-
opts.on("--#{name}=VALUE")
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
attr_accessor :options
|
|
32
|
-
|
|
33
|
-
def call
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
NETRC = Netrc.read
|
|
39
|
-
|
|
40
|
-
def get_access_key(host, zone_name = nil)
|
|
41
|
-
if zone_name.nil?
|
|
42
|
-
netrc_entry = NETRC[host]
|
|
43
|
-
raise BunBun::CLI::Error, "no netrc entry for #{host}" if netrc_entry.nil?
|
|
44
|
-
netrc_entry.password
|
|
45
|
-
else
|
|
46
|
-
netrc_entry = NETRC.each.find { _1[1] == host && _1[3] == zone_name }
|
|
47
|
-
raise BunBun::CLI::Error, "no netrc entry for #{host} (#{zone_name})" if netrc_entry.nil?
|
|
48
|
-
netrc_entry[5]
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def read_body_params(file)
|
|
53
|
-
JSON.parse(File.read(file))
|
|
54
|
-
rescue Errno::ENOENT
|
|
55
|
-
raise BunBun::CLI::Error, 'file does not exist'
|
|
56
|
-
rescue JSON::ParserError
|
|
57
|
-
raise BunBun::CLI::Error, 'file must be valid json'
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def client
|
|
61
|
-
@client ||= BunBun::Client.new(access_key: get_access_key('api.bunny.net'))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
BYTESIZE_UNITS = {
|
|
65
|
-
GB: 1_000_000_000,
|
|
66
|
-
MB: 1_000_000,
|
|
67
|
-
KB: 1_000
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
def format_bytesize(integer)
|
|
71
|
-
BYTESIZE_UNITS.each do |suffix, size|
|
|
72
|
-
if integer >= size
|
|
73
|
-
return "#{(integer.to_f / size).round(2)} #{suffix}"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
"#{integer} bytes"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def format_timestamp(string)
|
|
81
|
-
string.split('.').first.tr('T', ' ')
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def print_json(object, io: STDOUT)
|
|
85
|
-
io.puts JSON.pretty_generate(object)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def print_table(array, io: STDOUT)
|
|
89
|
-
return if array.empty?
|
|
90
|
-
|
|
91
|
-
table = Tabulo::Table.new(array, border: :modern)
|
|
92
|
-
|
|
93
|
-
yield table
|
|
94
|
-
|
|
95
|
-
io.puts table.pack
|
|
96
|
-
end
|
|
97
|
-
end
|
data/lib/bunbun/cli/countries.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::Countries < BunBun::CLI::Command
|
|
4
|
-
def call
|
|
5
|
-
items = client.country.list
|
|
6
|
-
|
|
7
|
-
print_table(items) do |t|
|
|
8
|
-
t.add_column('Name', align_header: :left) { _1['Name'] }
|
|
9
|
-
t.add_column('Code', align_header: :left) { _1['IsoCode'] }
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
data/lib/bunbun/cli/keys.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::Keys < BunBun::CLI::Command
|
|
4
|
-
def call
|
|
5
|
-
items = client.api_key.list
|
|
6
|
-
|
|
7
|
-
print_table(items.fetch('Items')) do |t|
|
|
8
|
-
t.add_column('ID', align_header: :left) { _1['Id'] }
|
|
9
|
-
t.add_column('Key', align_header: :left) { _1['Key'] }
|
|
10
|
-
t.add_column('Roles', align_header: :left) { _1['Roles'].join(', ') }
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
data/lib/bunbun/cli/purge.rb
DELETED
data/lib/bunbun/cli/regions.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::Regions < BunBun::CLI::Command
|
|
4
|
-
def call
|
|
5
|
-
items = client.region.list
|
|
6
|
-
|
|
7
|
-
print_table(items) do |t|
|
|
8
|
-
t.add_column('ID', align_header: :right) { _1['Id'] }
|
|
9
|
-
t.add_column('Name', align_header: :left) { _1['Name'] }
|
|
10
|
-
t.add_column('Region', align_header: :left) { _1['RegionCode'] }
|
|
11
|
-
t.add_column('Country', align_header: :left) { _1['CountryCode'] }
|
|
12
|
-
t.add_column('Latitude', align_header: :right) { _1['Latitude'] }
|
|
13
|
-
t.add_column('Longitude', align_header: :right) { _1['Longitude'] }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::StorageCommand < BunBun::CLI::Command
|
|
4
|
-
attr_accessor :storage_zone
|
|
5
|
-
attr_accessor :storage_host
|
|
6
|
-
attr_accessor :storage_access_key
|
|
7
|
-
|
|
8
|
-
def call(path)
|
|
9
|
-
unless path =~ /\A\/([\w\-]+)\//
|
|
10
|
-
raise BunBun::CLI::Error, 'path must start with a zone name'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
self.storage_zone = $1
|
|
14
|
-
|
|
15
|
-
self.storage_host = options[:host] || 'storage.bunnycdn.com'
|
|
16
|
-
|
|
17
|
-
self.storage_access_key = get_access_key(storage_host, storage_zone)
|
|
18
|
-
|
|
19
|
-
@client = BunBun::Client.new(host: storage_host, access_key: storage_access_key)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::StorageEdit < BunBun::CLI::StorageCommand
|
|
4
|
-
option :host
|
|
5
|
-
|
|
6
|
-
def call(path)
|
|
7
|
-
super
|
|
8
|
-
|
|
9
|
-
response = client.download(path)
|
|
10
|
-
|
|
11
|
-
unless response.content_type.start_with?('text/') || response.content_type == 'application/json'
|
|
12
|
-
raise BunBun::CLI::Error, "cannot edit #{response.content_type} files"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
text = response.body
|
|
16
|
-
|
|
17
|
-
pipe = IO.popen(ENV.fetch('EDITOR'), 'w+')
|
|
18
|
-
pipe.puts(text)
|
|
19
|
-
pipe.close_write
|
|
20
|
-
|
|
21
|
-
edited_text = pipe.read
|
|
22
|
-
|
|
23
|
-
pipe.close
|
|
24
|
-
|
|
25
|
-
unless edited_text.empty? || edited_text == text
|
|
26
|
-
client.upload(path, edited_text, content_type: response.content_type)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::StorageFiles < BunBun::CLI::StorageCommand
|
|
4
|
-
option :host
|
|
5
|
-
|
|
6
|
-
def call(path)
|
|
7
|
-
unless path.end_with?('/')
|
|
8
|
-
raise BunBun::CLI::Error, 'path must end with a trailing slash'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
super
|
|
12
|
-
|
|
13
|
-
items = client.get(path)
|
|
14
|
-
|
|
15
|
-
print_table(items) do |t|
|
|
16
|
-
t.add_column('Name', align_header: :left) { _1['ObjectName'] }
|
|
17
|
-
t.add_column('Size') { format_bytesize(_1['Length']) unless _1['Length'].zero? }
|
|
18
|
-
t.add_column('Created', align_header: :right) { format_timestamp(_1['DateCreated']) }
|
|
19
|
-
t.add_column('Modified', align_header: :right) { format_timestamp(_1['LastChanged']) }
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'shellwords'
|
|
3
|
-
|
|
4
|
-
class BunBun::CLI::StorageUpload < BunBun::CLI::StorageCommand
|
|
5
|
-
option :host
|
|
6
|
-
|
|
7
|
-
def call(path, file)
|
|
8
|
-
unless path.end_with?('/')
|
|
9
|
-
raise BunBun::CLI::Error, 'path must end with a trailing slash'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
super(path)
|
|
13
|
-
|
|
14
|
-
content_type = `file -b --mime-type #{Shellwords.escape(file)}`.chomp
|
|
15
|
-
|
|
16
|
-
File.open(file, 'rb') do |io|
|
|
17
|
-
client.upload(path + File.basename(file), io, content_type: content_type)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::StorageZones < BunBun::CLI::Command
|
|
4
|
-
def call
|
|
5
|
-
items = client.storage_zone.list
|
|
6
|
-
|
|
7
|
-
print_table(items.sort_by { _1['Name'] }) do |t|
|
|
8
|
-
t.add_column('ID', align_header: :right) { _1['Id'] }
|
|
9
|
-
t.add_column('Name', align_header: :left) { _1['Name'] }
|
|
10
|
-
t.add_column('Region', align_header: :left) { _1['Region'] }
|
|
11
|
-
t.add_column('Hostname', align_header: :left) { _1['StorageHostname'] }
|
|
12
|
-
t.add_column('Size', align_header: :left) { format_bytesize(_1['StorageUsed']) }
|
|
13
|
-
t.add_column('Files', align_header: :right) { _1['FilesStored'] }
|
|
14
|
-
t.add_column('Modified', align_header: :right) { format_timestamp(_1['DateModified']) }
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/lib/bunbun/cli/zone.rb
DELETED
data/lib/bunbun/cli/zones.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BunBun::CLI::Zones < BunBun::CLI::Command
|
|
4
|
-
def call
|
|
5
|
-
items = client.pull_zone.list
|
|
6
|
-
|
|
7
|
-
print_table(items) do |t|
|
|
8
|
-
t.add_column('ID', align_header: :right) { _1['Id'] }
|
|
9
|
-
t.add_column('Name', align_header: :left) { _1['Name'] }
|
|
10
|
-
t.add_column('Storage Zone', align_header: :right) { _1['StorageZoneId'] }
|
|
11
|
-
t.add_column('Bandwidth') { format_bytesize(_1['MonthlyBandwidthUsed']) }
|
|
12
|
-
t.add_column('Domain', align_header: :left) { |zone|
|
|
13
|
-
hostnames = zone['Hostnames'].reject { _1['IsSystemHostname'] || _1['IsManagedHostname'] }
|
|
14
|
-
hostnames.map { _1['Value'] }.first
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
data/lib/bunbun/cli.rb
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'netrc'
|
|
3
|
-
require 'optparse'
|
|
4
|
-
|
|
5
|
-
class BunBun::CLI
|
|
6
|
-
Error = Class.new(StandardError)
|
|
7
|
-
|
|
8
|
-
autoload :Command, 'bunbun/cli/command'
|
|
9
|
-
autoload :StorageCommand, 'bunbun/cli/storage_command'
|
|
10
|
-
|
|
11
|
-
def self.commands
|
|
12
|
-
@commands ||= []
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.command(key)
|
|
16
|
-
autoload_path = 'bunbun/cli/' + key.join('_')
|
|
17
|
-
|
|
18
|
-
autoload command_class_name(key), autoload_path
|
|
19
|
-
|
|
20
|
-
commands << key
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def self.command_class_name(key)
|
|
24
|
-
key.map(&:capitalize).join.to_sym
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
command %w[countries]
|
|
28
|
-
command %w[keys]
|
|
29
|
-
command %w[purge]
|
|
30
|
-
command %w[regions]
|
|
31
|
-
command %w[storage delete]
|
|
32
|
-
command %w[storage download]
|
|
33
|
-
command %w[storage edit]
|
|
34
|
-
command %w[storage files]
|
|
35
|
-
command %w[storage upload]
|
|
36
|
-
command %w[storage zone create]
|
|
37
|
-
command %w[storage zone]
|
|
38
|
-
command %w[storage zones]
|
|
39
|
-
command %w[zone create]
|
|
40
|
-
command %w[zone purge]
|
|
41
|
-
command %w[zone rules delete]
|
|
42
|
-
command %w[zone rules disenable]
|
|
43
|
-
command %w[zone rules enable]
|
|
44
|
-
command %w[zone rules post]
|
|
45
|
-
command %w[zone]
|
|
46
|
-
command %w[zones]
|
|
47
|
-
|
|
48
|
-
def call(args)
|
|
49
|
-
if args.empty? || args.size == 1 && args.first == '--help'
|
|
50
|
-
print_usage
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
option_args, command_args = args.partition { _1.start_with?('-') }
|
|
56
|
-
|
|
57
|
-
key = self.class.commands.find { command_args.first(_1.length) == _1 }
|
|
58
|
-
|
|
59
|
-
if key.nil?
|
|
60
|
-
error "#{command_args.join(' ')} is not a valid command"
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
command_class = get_command_class(key)
|
|
64
|
-
|
|
65
|
-
command = command_class.new
|
|
66
|
-
|
|
67
|
-
if option_parser = command.option_parser
|
|
68
|
-
command.options = {}
|
|
69
|
-
|
|
70
|
-
option_parser.parse(option_args, into: command.options)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
command_args = command_args.drop(key.length)
|
|
74
|
-
|
|
75
|
-
if command_args.length < command_class.argument_count
|
|
76
|
-
error "not enough arguments (expected #{command_class.argument_count})"
|
|
77
|
-
elsif command_args.length > command_class.argument_count
|
|
78
|
-
error "too many arguments (expected #{command_class.argument_count})"
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
command.call(*command_args)
|
|
82
|
-
rescue OptionParser::InvalidOption
|
|
83
|
-
error 'invalid option'
|
|
84
|
-
rescue OptionParser::MissingArgument
|
|
85
|
-
error 'missing option argument'
|
|
86
|
-
rescue BunBun::Error, BunBun::CLI::Error => exception
|
|
87
|
-
error exception.message
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
private
|
|
91
|
-
|
|
92
|
-
def get_command_class(key)
|
|
93
|
-
BunBun::CLI.const_get(self.class.command_class_name(key))
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def print_usage(io: STDOUT, program_name: File.basename($0))
|
|
97
|
-
io.puts "Usage: #{program_name} COMMAND"
|
|
98
|
-
io.puts
|
|
99
|
-
|
|
100
|
-
self.class.commands.each do |key|
|
|
101
|
-
command_class = get_command_class(key)
|
|
102
|
-
|
|
103
|
-
arguments = command_class.argument_names.map { ' ' + _1.to_s.upcase }.join
|
|
104
|
-
|
|
105
|
-
options = command_class.options.map { " [--#{_1}=#{_1.upcase}]" }.join
|
|
106
|
-
|
|
107
|
-
io.puts " #{program_name} #{key.join(' ')}#{arguments}#{options}"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
io.puts
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def error(message)
|
|
114
|
-
message = 'ERROR: ' + message
|
|
115
|
-
message = color_red(message) if STDERR.isatty
|
|
116
|
-
|
|
117
|
-
Kernel::abort(message)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def color_red(text)
|
|
121
|
-
"\e[#{31}m#{text}\e[m"
|
|
122
|
-
end
|
|
123
|
-
end
|