race 0.1.6

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4d1b1e1ae7a8e4f81cbd0c0e54c03935f4c760d
4
+ data.tar.gz: 521ace13d92f351ee7b3ed02ebedd4c2325638da
5
+ SHA512:
6
+ metadata.gz: f19a982e79d2721359729af0689450375e56289b216b3c3c6eb102f6ad4d486a62f18b79a3107d60d7c0a896f93de479862b4d992085c24522b823ff93ef1af4
7
+ data.tar.gz: 554c011027c99c0d754f6474d7625a5ba16a893594d8173f7c96e834eb5adc8e58e8c24424a94e87689dffd4a6646131d33c69fb4285d98b6faaffb0ef53662f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in race.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sedat CIFTCI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # Race
2
+
3
+ Digitalocean commandline tools
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'race'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install race
18
+
19
+ ## Droplets
20
+ <pre>
21
+ Droplet List
22
+ $ race droplets
23
+
24
+ Create New Droplet
25
+ $ race droplets new [DROPLET_NAME] [SIZE_ID] [IMAGE_ID] [REGION_ID]
26
+
27
+ Reboot Droplet
28
+ $ race droplets reboot [DROPLET_ID]
29
+
30
+ Droplet Power Cycle
31
+ $ race droplets cycle [DROPLET_ID]
32
+
33
+ Power Down Droplet
34
+ $ race droplets down [DROPLET_ID]
35
+
36
+ Power Off Droplet
37
+ $ race droplets off [DROPLET_ID]
38
+
39
+ Power On Droplet
40
+ $ race droplets on [DROPLET_ID]
41
+
42
+ Reset Droplet Password
43
+ $ race droplets reset_password [DROPLET_ID]
44
+
45
+ Resize Droplet
46
+ $ race droplets resize [DROPLET_ID] [SIZE_ID]
47
+
48
+ Create Snapshot
49
+ $ race droplets create-snaphot [DROPLET_ID] [SNAPSHOT_NAME]
50
+
51
+ Show droplet snapshots
52
+ $ race droplets snapshots [DROPLET_ID]
53
+
54
+ Restore Droplet
55
+ $ race droplets restore [DROPLET_ID] [IMAGE_ID]
56
+
57
+ Rebuild Droplet
58
+ $ race droplets rebuild [DROPLET_ID] [IMAGE_ID]
59
+
60
+ Rename Droplet
61
+ $ race droplets rename [DROPLET_ID] [NEW_NAME]
62
+
63
+ Enable IPv6 for a droplet
64
+ $ race droplets enable-ipv6 [DROPLET_ID]
65
+
66
+ Droplet Kernels
67
+ $ race droplets kernels [DROPLET_ID]
68
+
69
+ Change Kernels
70
+ $ race droplets change-kernel [DROPLET_ID] [KERNEL_ID]
71
+
72
+ Disable Droplet Backup
73
+ $ race droplets disable-backup [DROPLET_ID]
74
+
75
+ Enable Private Network
76
+ $ race droplets enable-private-network [DROPLET_ID]
77
+
78
+ </pre>
79
+ ## SSH
80
+ <pre>
81
+ SSH Key List
82
+ $ race ssh keys
83
+
84
+ Add SSH Key
85
+ $ race ssh add [KEY_NAME] [KEY_PUB]
86
+
87
+ Show SSH Key
88
+ $ race ssh show [KEY_ID]
89
+
90
+ Edit SSH Key
91
+ $ race ssh edit [KEY_ID] [KEY_NAME] [KEY_PUB]
92
+
93
+ Destroy SSH Key
94
+ $ race ssh destroy [KEY_ID]
95
+ </pre>
96
+ ## Regions
97
+ <pre>
98
+ Region List
99
+ $ race regions
100
+ </pre>
101
+
102
+ ## Domains
103
+ <pre>
104
+ Show all domains
105
+ $ race domain
106
+
107
+ Show domain
108
+ $ race domain show [DOMAIN_NAME]
109
+
110
+ Destroy domain
111
+ $ race domain destroy [DOMAIN_NAME]
112
+
113
+ Create Domain
114
+ $ race domain create [DOMAIN_NAME] [TYPE] [IP]
115
+ </pre>
116
+
117
+ ## Sizes
118
+ <pre>
119
+ Size List
120
+ $ race sizes
121
+ </pre>
122
+ ## Images
123
+ <pre>
124
+ Show Images
125
+ $ race images [true]
126
+
127
+ Show Image
128
+ $ race images show [IMAGE_ID]
129
+
130
+ Destroy Image
131
+ $ race images destroy [IMAGE_ID]
132
+
133
+ Transfer Image
134
+ $ race images transfer [IMAGE_ID] [REGION_ID]
135
+ </pre>
136
+
137
+
138
+ ## Get Account Information
139
+ <pre>
140
+ Show Account Information
141
+ $ race account
142
+ </pre>
143
+
144
+ ## Information
145
+ <pre>
146
+ Show API Key and Client ID
147
+ $ race info show
148
+
149
+ Change Information
150
+ $ race info change
151
+ </pre>
152
+
153
+ ## Contributing
154
+
155
+ 1. Fork it (http://github.com/0x73/race/fork)
156
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
157
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
158
+ 4. Push to the branch (`git push origin my-new-feature`)
159
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/race ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require 'pathname'
4
+ require 'netrc'
5
+ require 'colorize'
6
+ require 'terminal-table'
7
+
8
+ bin_file = Pathname.new(__FILE__).realpath
9
+
10
+ $LOAD_PATH.unshift File.expand_path('../../lib', bin_file)
11
+
12
+ config = Netrc.read("#{(ENV['HOME'] || './')}/race.netrc")
13
+ if config['api.digitalocean.com'].nil?
14
+ api_key = [(print 'Access Tokens: '), STDIN.gets.rstrip][1]
15
+ client_id = 'empty'
16
+ config['api.digitalocean.com'] = api_key, client_id
17
+ config.save
18
+ else
19
+ require 'race'
20
+ Race::Runner.start
21
+ end
@@ -0,0 +1,3 @@
1
+ module Race
2
+ VERSION = '0.1.6'
3
+ end
data/lib/race.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'race/version'
2
+ require 'system/config'
3
+ require 'system/run/client'
4
+ require 'system/run/run'
@@ -0,0 +1,18 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'barge'
4
+ module Race
5
+ class Config
6
+ def self.get(key)
7
+ config = Netrc.read("#{(ENV['HOME'] || './')}/race.netrc")
8
+ config = config['api.digitalocean.com']
9
+ options = {
10
+ api_key: config[0]
11
+ }
12
+ options[:"#{key}"]
13
+ end
14
+ def self.get_barge
15
+ barge = ::Barge::Client.new(access_token: get(:api_key))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,64 @@
1
+ class Race::Run::Base
2
+ attr_writer :options, :config
3
+
4
+ def self.method_added(method)
5
+ return if self == Race::Run::Base
6
+ return if private_method_defined? method
7
+ return if protected_method_defined? method
8
+ prefix = get_object_name
9
+ method_name = method.to_s == 'run' ? nil : method.to_s.gsub('_', '-')
10
+ name = [prefix, method_name].compact
11
+ Race::Run.add(name: name,
12
+ class: self,
13
+ method: method,
14
+ options: options)
15
+ @options = nil
16
+ end
17
+
18
+ def self.get_object_name(value = nil)
19
+ @object_name ||= begin
20
+ value ||= name.split('::').last if name && !name.empty?
21
+ value.to_s.split(/(?=[A-Z])/).join('-').downcase if value
22
+ end
23
+ end
24
+
25
+ def self.syntax(value)
26
+ options[:syntax] = value
27
+ end
28
+
29
+ def self.description(value)
30
+ options[:description] = value
31
+ end
32
+
33
+ def self.summary(value)
34
+ options[:summary] = value
35
+ end
36
+
37
+ def self.example(value)
38
+ options[:example] = value
39
+ end
40
+
41
+ def self.option(switches, description = nil, options = {})
42
+ meta << {
43
+ switches: switches,
44
+ description: description,
45
+ type: options[:type].nil? ? 'String' : options[:type],
46
+ default: options[:default],
47
+ optional: options[:optional]
48
+ }
49
+ end
50
+
51
+ def self.options
52
+ @options ||= {}
53
+ end
54
+
55
+ def self.meta
56
+ options[:meta] ||= []
57
+ end
58
+
59
+ def barge
60
+ puts "I'm thinking, please wait... \n".blue
61
+ Race::Config.get_barge
62
+ end
63
+
64
+ end
@@ -0,0 +1,13 @@
1
+ require 'commander'
2
+ require 'commander/command'
3
+ require 'commander/import'
4
+ module Race
5
+ class Runner
6
+ def self.start
7
+ program :name, 'Digital Raceean Client'
8
+ program :version, Race::VERSION
9
+ program :description, 'Digital Raceean Command Line Tools'
10
+ Race::Run.load_commands.parse_command
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module Race::Run
2
+ class Account < Base
3
+ description 'Get User Information'
4
+ syntax 'race account'
5
+ def run(*_args)
6
+ result = barge.account.show
7
+ if !result
8
+ puts 'Error: Please check your information'.red
9
+ else
10
+ puts 'Account Information'.yellow
11
+ rows = []
12
+ rows << %w(Limit Email UUID EmailVerified)
13
+
14
+ result.each do |res|
15
+ user = res[1]
16
+ rows << [
17
+ user.droplet_limit,
18
+ user.email,
19
+ user.uuid,
20
+ user.email_verified == true ? 'True'.green : 'False'.red
21
+ ]
22
+ end
23
+ table = Terminal::Table.new rows: rows
24
+ puts table
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,88 @@
1
+ module Race::Run
2
+ class Domain < Base
3
+ description 'Show all domains'
4
+ syntax 'race domain'
5
+ def run
6
+ result = barge.domain.all
7
+ if !result.success?
8
+ puts "#{result.error}".red
9
+ else
10
+ puts 'Domains'.yellow
11
+ rows = []
12
+ rows << %w(Name TTL)
13
+ result.domains.each do |domain|
14
+ rows << [
15
+ domain.name.to_s.red,
16
+ domain.ttl
17
+ ]
18
+ end
19
+ table = Terminal::Table.new rows: rows
20
+ puts table
21
+ end
22
+ end
23
+
24
+ description 'Show domain'
25
+ syntax 'race domain show [DOMAIN_NAME]'
26
+ def show(*args)
27
+ domain = args[0]
28
+ if domain.nil?
29
+ puts 'Argument Error'.red
30
+ puts 'Usage'.yellow
31
+ puts '$ race domain show [DOMAIN_NAME]'.yellow
32
+ else
33
+ result = barge.domain.show(domain.to_s)
34
+ if !result.success?
35
+ puts "#{result.message}".red
36
+ else
37
+ puts "Domain Information - #{domain}".yellow
38
+ rows = []
39
+ rows << %w(Name TTL)
40
+ rows << [
41
+ result.domain.name.to_s.red,
42
+ result.domain.ttl
43
+ ]
44
+ table = Terminal::Table.new rows: rows
45
+ puts table
46
+ end
47
+ end
48
+ end
49
+
50
+ description 'Destroy domain'
51
+ syntax 'race domain destroy [DOMAIN_NAME]'
52
+ def destroy(*args)
53
+ domain = args[0]
54
+ if domain.nil?
55
+ puts 'Argument Error'.red
56
+ puts 'Usage'.yellow
57
+ puts '$ race domain destroy [DOMAIN_NAME]'.yellow
58
+ else
59
+ result = barge.domain.destroy(domain.to_s)
60
+ if !result.success?
61
+ puts "#{result.message}".red
62
+ else
63
+ puts 'Domain destroyed'.green
64
+ end
65
+ end
66
+ end
67
+
68
+ description 'Create domain record'
69
+ syntax 'race domain create [DOMAIN_NAME] [TYPE] [IP]'
70
+ def create(*args)
71
+ name = args[0]
72
+ type = args[1]
73
+ data = args[2]
74
+ if data.nil? || type.nil? || data.nil?
75
+ puts 'Argument Error'.red
76
+ puts 'Usage'.yellow
77
+ puts '$ race domain create [DOMAIN_NAME] [TYPE] [IP]'.yellow
78
+ else
79
+ result = barge.domain.create_record(name.to_s, { type: name.to_s, data: data.to_s })
80
+ if !result.success?
81
+ puts "#{result.message}".red
82
+ else
83
+ puts 'Domain created'.green
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end