red_drop 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +16 -0
- data/lib/red_drop/auth.rb +28 -0
- data/lib/red_drop/create.rb +11 -0
- data/lib/red_drop/delete.rb +30 -0
- data/lib/red_drop/droplet_wizard.rb +14 -0
- data/lib/red_drop/status.rb +17 -0
- data/lib/red_drop/version.rb +5 -0
- data/lib/red_drop.rb +29 -0
- data/red_drop.gemspec +38 -0
- data/sig/red_drop.rbs +4 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1db5773a0cd7ddbb2bc91980a382ad55df83d61698e9bce86c528234c05142e
|
4
|
+
data.tar.gz: d4452d721f41d8970e08154a346c97857318ff50eb0f224fdc996ee968918c60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4272b8cc7994a7588988df318ccee25fe11b787eca07944bacde902f95a60b8f2d3d390431c6ea95cdf1d24f20397ec7fd925045a039829dccff9c3cb1be821d
|
7
|
+
data.tar.gz: 613353c97c01c208b4a1980019f8499dc9e7f7061e064cce6df20be3d99d63d6e94738d5866fa6a5be717257383c2e1088005623f2e3701e0ee6d06fbbb72745
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
red_drop (0.1.0)
|
5
|
+
droplet_kit (~> 3.18)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.1)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
ansi (1.5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
axiom-types (0.1.1)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
ice_nine (~> 0.11.0)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
18
|
+
builder (3.2.4)
|
19
|
+
coercible (1.0.0)
|
20
|
+
descendants_tracker (~> 0.0.1)
|
21
|
+
descendants_tracker (0.0.4)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
23
|
+
droplet_kit (3.18.0)
|
24
|
+
faraday (>= 0.15)
|
25
|
+
kartograph (~> 0.2.8)
|
26
|
+
resource_kit (~> 0.1.5)
|
27
|
+
virtus (>= 1.0.3, <= 3)
|
28
|
+
faraday (2.7.1)
|
29
|
+
faraday-net_http (>= 2.0, < 3.1)
|
30
|
+
ruby2_keywords (>= 0.0.4)
|
31
|
+
faraday-net_http (3.0.2)
|
32
|
+
ice_nine (0.11.2)
|
33
|
+
json (2.5.1)
|
34
|
+
kartograph (0.2.8)
|
35
|
+
minitest (5.16.3)
|
36
|
+
minitest-reporters (1.5.0)
|
37
|
+
ansi
|
38
|
+
builder
|
39
|
+
minitest (>= 5.0)
|
40
|
+
ruby-progressbar
|
41
|
+
parallel (1.22.1)
|
42
|
+
parser (3.1.3.0)
|
43
|
+
ast (~> 2.4.1)
|
44
|
+
public_suffix (5.0.0)
|
45
|
+
rainbow (3.1.1)
|
46
|
+
rake (13.0.6)
|
47
|
+
regexp_parser (2.6.1)
|
48
|
+
resource_kit (0.1.8)
|
49
|
+
addressable (>= 2.3.6, < 3.0.0)
|
50
|
+
rexml (3.2.5)
|
51
|
+
rubocop (1.39.0)
|
52
|
+
json (~> 2.3)
|
53
|
+
parallel (~> 1.10)
|
54
|
+
parser (>= 3.1.2.1)
|
55
|
+
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
regexp_parser (>= 1.8, < 3.0)
|
57
|
+
rexml (>= 3.2.5, < 4.0)
|
58
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
59
|
+
ruby-progressbar (~> 1.7)
|
60
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
61
|
+
rubocop-ast (1.23.0)
|
62
|
+
parser (>= 3.1.1.0)
|
63
|
+
ruby-progressbar (1.11.0)
|
64
|
+
ruby2_keywords (0.0.5)
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
unicode-display_width (2.3.0)
|
67
|
+
virtus (2.0.0)
|
68
|
+
axiom-types (~> 0.1)
|
69
|
+
coercible (~> 1.0)
|
70
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
x86_64-linux
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
minitest (~> 5.0)
|
77
|
+
minitest-reporters (~> 1.5)
|
78
|
+
rake (~> 13.0)
|
79
|
+
red_drop!
|
80
|
+
rubocop (~> 1.21)
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.3.15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Sergio Ortiz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# RedDrop
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install the gem and add to the application's Gemfile by executing:
|
6
|
+
|
7
|
+
$ bundle add red_drop
|
8
|
+
|
9
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
10
|
+
|
11
|
+
$ gem install red_drop
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
require "red_drop"
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
20
|
+
|
21
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
|
+
|
23
|
+
### Todos
|
24
|
+
|
25
|
+
- Research making gem executable
|
26
|
+
- Research TDD and minitest vs rspec
|
27
|
+
- refactor status module to match delete module droplets var structure
|
28
|
+
- maybe convert delete module droplets array to hash with array index as key to avoid accidental deletions
|
29
|
+
- refactor delete while loop to match that of red_drop.rb
|
30
|
+
- refactor auth to use Faraday which is used by DropletKit
|
31
|
+
- refactor status to get ip address of runnning droplets
|
32
|
+
- Research having delete get status before executing
|
33
|
+
- use cloud_init to automate server config for SSH, ufw, docker
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sergio-ortiz/red_drop.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
class Auth
|
4
|
+
def initialize
|
5
|
+
file = File.open("secret.txt", "a+")
|
6
|
+
@secret = file.read
|
7
|
+
file.close
|
8
|
+
|
9
|
+
uri = URI('https://api.digitalocean.com/v2/droplets')
|
10
|
+
@http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https')
|
11
|
+
@req = Net::HTTP::Get.new(uri)
|
12
|
+
|
13
|
+
@req["Authorization"] = "Bearer #{@secret}"
|
14
|
+
@res = @http.request(@req)
|
15
|
+
end
|
16
|
+
|
17
|
+
def token
|
18
|
+
while @secret.empty? or not @res.code === "200"
|
19
|
+
puts "There in no valid API token in memory,\nplease enter a valid API token."
|
20
|
+
@secret = gets.chomp
|
21
|
+
File.write("secret.txt", @secret)
|
22
|
+
|
23
|
+
@req["Authorization"] = "Bearer #{@secret}"
|
24
|
+
@res = @http.request(@req)
|
25
|
+
end
|
26
|
+
@secret
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Create
|
2
|
+
def create
|
3
|
+
puts "loading... \n\n"
|
4
|
+
|
5
|
+
droplet = DropletKit::Droplet.new(name: 'drop', region: 'nyc1', size: 's-1vcpu-512mb-10gb', image: 'ubuntu-22-04-x64')
|
6
|
+
response = @client.droplets.create(droplet)
|
7
|
+
|
8
|
+
puts "Your droplet: #{response.id}, is being provisioned.\n"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Delete
|
2
|
+
def delete
|
3
|
+
puts "loading... \n\n"
|
4
|
+
|
5
|
+
droplets = @client.droplets.all.map { |droplet| droplet.to_h }
|
6
|
+
|
7
|
+
if droplets.length == 0
|
8
|
+
puts "There are no droplets in your DigitalOcean cloud.\n"
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "option: droplet_id\n"
|
13
|
+
droplets.each_with_index { |droplet, index| puts "#{index}: #{droplet[:id]}" }
|
14
|
+
puts "\nPlease enter an option for a droplet to delete?\n\n"
|
15
|
+
num = gets.to_i
|
16
|
+
|
17
|
+
while not droplets[num]
|
18
|
+
puts "\n#{num} is not a valid option, please enter a valid option\n\n"
|
19
|
+
num = gets.to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
response = @client.droplets.delete(id: droplets[num][:id])
|
23
|
+
|
24
|
+
if response
|
25
|
+
puts "\ndelete request processed succesfully\n\n"
|
26
|
+
else
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Status
|
2
|
+
def status
|
3
|
+
puts "loading... \n\n"
|
4
|
+
|
5
|
+
droplets = @client.droplets.all.map { |droplet| { "droplet_id" => droplet.id, "status" => droplet.status } }
|
6
|
+
status = { "new" => "provisioning", "active" => "running" }
|
7
|
+
droplets.each { |drop| drop["status"] = status[drop["status"]] }
|
8
|
+
|
9
|
+
if droplets.length == 0
|
10
|
+
puts "There are no droplets in your DigitalOcean cloud."
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
droplets.each { |droplet| puts droplet}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/lib/red_drop.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "red_drop/auth"
|
4
|
+
auth = Auth.new
|
5
|
+
token = auth.token
|
6
|
+
|
7
|
+
require 'droplet_kit'
|
8
|
+
client = DropletKit::Client.new(access_token: token)
|
9
|
+
|
10
|
+
require "red_drop/droplet_wizard"
|
11
|
+
|
12
|
+
droplet_wizard = DropletWizard.new(client)
|
13
|
+
|
14
|
+
command = nil
|
15
|
+
|
16
|
+
while not command === "quit"
|
17
|
+
puts "\nWhat would you like to do?\n['status', 'create', 'delete', 'quit']\n\n"
|
18
|
+
|
19
|
+
command = gets.chomp
|
20
|
+
|
21
|
+
case command
|
22
|
+
when "create"
|
23
|
+
droplet_wizard.create
|
24
|
+
when "status"
|
25
|
+
droplet_wizard.status
|
26
|
+
when "delete"
|
27
|
+
droplet_wizard.delete
|
28
|
+
end
|
29
|
+
end
|
data/red_drop.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/red_drop/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "red_drop"
|
7
|
+
spec.version = RedDrop::VERSION
|
8
|
+
spec.authors = ["Sergio Ortiz"]
|
9
|
+
spec.email = ["ortiz.sergio0303@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Simple cli for automating droplet management"
|
12
|
+
spec.description = "A cli wriiten in ruby for executing automated droplet tasks with sane configurations baked in."
|
13
|
+
spec.homepage = "https://github.com/sergio-ortiz/red_drop"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/sergio-ortiz/red_drop"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/sergio-ortiz/red_drop"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.5"
|
34
|
+
spec.add_dependency "droplet_kit", "~> 3.18"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
data/sig/red_drop.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: red_drop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio Ortiz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest-reporters
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: droplet_kit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.18'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.18'
|
41
|
+
description: A cli wriiten in ruby for executing automated droplet tasks with sane
|
42
|
+
configurations baked in.
|
43
|
+
email:
|
44
|
+
- ortiz.sergio0303@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/red_drop.rb
|
56
|
+
- lib/red_drop/auth.rb
|
57
|
+
- lib/red_drop/create.rb
|
58
|
+
- lib/red_drop/delete.rb
|
59
|
+
- lib/red_drop/droplet_wizard.rb
|
60
|
+
- lib/red_drop/status.rb
|
61
|
+
- lib/red_drop/version.rb
|
62
|
+
- red_drop.gemspec
|
63
|
+
- sig/red_drop.rbs
|
64
|
+
homepage: https://github.com/sergio-ortiz/red_drop
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
homepage_uri: https://github.com/sergio-ortiz/red_drop
|
69
|
+
source_code_uri: https://github.com/sergio-ortiz/red_drop
|
70
|
+
changelog_uri: https://github.com/sergio-ortiz/red_drop
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.6.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.3.15
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Simple cli for automating droplet management
|
90
|
+
test_files: []
|