race 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ module Race::Run
2
+ class Ssh < Base
3
+ description 'This method lists all the available public SSH keys in your account that can be added to a droplet.'
4
+ syntax 'race ssh keys'
5
+ def keys
6
+ result = barge.key.all
7
+ if !result.success?
8
+ puts 'Error: Please check your information'.red
9
+ else
10
+ puts 'Your SSH Keys'.yellow
11
+ rows = []
12
+ rows << %w(ID Name)
13
+ result.ssh_keys.each do |key|
14
+ rows << [
15
+ key['id'],
16
+ key['name'].red
17
+ ]
18
+ end
19
+ table = Terminal::Table.new rows: rows
20
+ puts table
21
+ end
22
+ end
23
+
24
+ description 'This method allows you to add a new public SSH key to your account.'
25
+ syntax 'race ssh add [KEY_NAME] [KEY_EMAIL] [KEY_PUB]'
26
+ def add(*args)
27
+ name = args[0]
28
+ pub_key = args[1]
29
+ if name.nil? || pub_key.nil?
30
+ puts 'Argument Error'.red
31
+ puts 'Usage'.yellow
32
+ puts '$ race ssh add [KEY_NAME] [KEY_PUB]'.yellow
33
+ else
34
+ result = barge.key.create(name: name,
35
+ public_key: pub_key)
36
+ if !result.success?
37
+ puts "#{result.message}".red
38
+ else
39
+ puts 'SSH Key Added'.green
40
+ end
41
+ end
42
+ end
43
+
44
+ description 'This method shows a specific public SSH key in your account that can be added to a droplet.'
45
+ syntax 'race ssh show [KEY_ID]'
46
+ def show(*args)
47
+ id = args[0]
48
+ if id.nil?
49
+ puts 'Argument Error'.red
50
+ puts 'Usage'.yellow
51
+ puts '$ race ssh show [KEY_ID]'.yellow
52
+ else
53
+ fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
54
+ result = barge.key.show(id)
55
+ if !result.success?
56
+ puts "#{result.message}".red
57
+ else
58
+ puts 'SSH Keys'.yellow
59
+ rows = []
60
+ rows << %w(ID Name)
61
+ key = result.ssh_key
62
+ rows << [
63
+ key.id,
64
+ key.name.to_s.red
65
+ ]
66
+
67
+ table = Terminal::Table.new rows: rows
68
+ puts table
69
+ end
70
+ end
71
+ end
72
+
73
+ description 'This method allows you to modify an existing public SSH key in your account.'
74
+ syntax 'race ssh edit [KEY_ID] [KEY_NAME] [KEY_PUB]'
75
+ def update(*args)
76
+ id = args[0]
77
+ name = args[1]
78
+ pub_key = args[2]
79
+ if id.nil? || name.nil? || pub_key.nil?
80
+ puts 'Argument Error'.red
81
+ puts 'Usage'.yellow
82
+ puts '$ race ssh edit [KEY_ID] [KEY_NAME] [KEY_PUB]'.yellow
83
+ else
84
+ fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
85
+ result = barge.key.update(id, name: name,
86
+ public_key: pub_key)
87
+ if !result.success?
88
+ puts "#{result.message}".red
89
+ else
90
+ puts 'SSH Key Edited'.green
91
+ end
92
+ end
93
+ end
94
+
95
+ description 'This method will delete the SSH key from your account.'
96
+ syntax 'race ssh destroy [KEY_ID]'
97
+ def destroy(*args)
98
+ id = args[0]
99
+ if id.nil?
100
+ puts 'Argument Error'.red
101
+ puts 'Usage'.yellow
102
+ puts '$ race ssh destroy [KEY_ID]'.yellow
103
+ else
104
+ fail ArgumentError, "Argument Error - #{id}" unless id =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
105
+ result = barge.key.destroy(id)
106
+ if !result.success?
107
+ puts "#{result.message}".red
108
+ else
109
+ puts 'SSH Key Deleted'.green
110
+ end
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def config(value)
117
+ @config ||= value
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,58 @@
1
+ module Race
2
+ module Run
3
+ autoload :Base, 'system/run/base'
4
+ attr_accessor :main
5
+
6
+ def self.load_commands
7
+ Dir[File.join(File.dirname(__FILE__), 'commands', '*.rb')].each do |file|
8
+ require file
9
+ end
10
+ self
11
+ end
12
+
13
+ def self.add(opts)
14
+ commands[opts[:name]] = opts
15
+ end
16
+
17
+ def self.parse_command(ins = Commander::Runner.instance)
18
+ commands.each_pair do |name, opts|
19
+ name = Array(name)
20
+ names = [name.reverse.join('-'), name.join(' ')] if name.length > 1
21
+ name = name.join(' ')
22
+ ins.command name do |c|
23
+ c.description = opts[:options][:description]
24
+ c.summary = opts[:options][:summary]
25
+ c.syntax = opts[:options][:syntax]
26
+ (options_metadata = Array(opts[:options][:meta])).each do |o|
27
+ option_data = [o[:switches], o[:type], o[:description], o[:optional]].compact.flatten(1)
28
+ c.option *option_data
29
+ o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last)
30
+ end
31
+ c.when_called do |args, options|
32
+ object = opts[:class].new
33
+ object.options = options
34
+ run(object, opts[:method], args)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def self.run(obj, method, args)
43
+ obj.send(method, *args)
44
+ end
45
+
46
+ def self.hash_to_array(options)
47
+ return_data = []
48
+ options.each do |k, v|
49
+ return_data[k] = v
50
+ end
51
+ return_data
52
+ end
53
+
54
+ def self.commands
55
+ @commands ||= {}
56
+ end
57
+ end
58
+ end
data/race.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'race/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'race'
8
+ spec.version = Race::VERSION
9
+ spec.authors = ['Sedat Ciftci']
10
+ spec.email = ['me@sedat.us']
11
+ spec.summary = 'DigitalRaceean Command Line Tools'
12
+ spec.description = 'DigitalRaceean Command Line Tools'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'commander', '~> 4.2.0'
22
+ spec.add_runtime_dependency 'terminal-table', '~> 1.4.5'
23
+ spec.add_runtime_dependency 'netrc', '~> 0.7.7'
24
+ spec.add_runtime_dependency 'colorize'
25
+ spec.add_runtime_dependency 'barge'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.5'
28
+ spec.add_development_dependency 'rake'
29
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: race
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Sedat Ciftci
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: netrc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: barge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: DigitalRaceean Command Line Tools
112
+ email:
113
+ - me@sedat.us
114
+ executables:
115
+ - race
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/race
125
+ - lib/race.rb
126
+ - lib/race/version.rb
127
+ - lib/system/config.rb
128
+ - lib/system/run/base.rb
129
+ - lib/system/run/client.rb
130
+ - lib/system/run/commands/account.rb
131
+ - lib/system/run/commands/domain.rb
132
+ - lib/system/run/commands/droplets.rb
133
+ - lib/system/run/commands/images.rb
134
+ - lib/system/run/commands/info.rb
135
+ - lib/system/run/commands/regions.rb
136
+ - lib/system/run/commands/sizes.rb
137
+ - lib/system/run/commands/ssh.rb
138
+ - lib/system/run/run.rb
139
+ - race.gemspec
140
+ homepage: ''
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.2.2
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: DigitalRaceean Command Line Tools
164
+ test_files: []