red_drop 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 650b690e863fa3223fa8111c28f1105f644107396b006614980e6394096d8f59
4
- data.tar.gz: 23a050d37eb35151c4c91fb08a98d98a074d897e4aab159610bf157ec1bbe183
3
+ metadata.gz: 39b5e008df5f5d43afd211101c2ac866a9446c310a2ebbbb153924c5071984e2
4
+ data.tar.gz: b56a8836f6013f1c85e5d791389dd007986a7f62d4dfc98473e3402312537d2f
5
5
  SHA512:
6
- metadata.gz: e24b7f0d8a9f898a75f79aef5e3e6a448ea8a58880c430a4b386361e84e10bab1493be6d56a1b60a6311eab83b7bf1420e55b94e5d883a6bfaa7608831894682
7
- data.tar.gz: 14c7800731c053b00a2d2562dbb5b4e2ab4688551ec0c85068f3907abe100773642fee970fb3d6b69f371ab0c62757679c7606aaac0ebd45b201a208673dd631
6
+ metadata.gz: 07fb962ef9b66d417b6c6467727946c559da5e3bca564368ca5173255afe41f4ce540277ab4a0f8f2b18a45c28d00ce8e268024e37c93f310ee6c96cb5892420
7
+ data.tar.gz: 8575bbfb5f2e53383b1b00e0c7ea3514910bc6e59d9be538c878190f0c91ae5fd30a2c0064566e1e1212a937cee5ccd144d63b57a9282be49d3693b53354e3b7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- red_drop (0.3.1)
4
+ red_drop (0.4.0)
5
5
  droplet_kit (~> 3.18)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
- # red_drop
1
+ # red_drop:drop_of_blood: [![Gem Version](https://badge.fury.io/rb/red_drop.svg)](https://badge.fury.io/rb/red_drop)
2
2
 
3
- Simple cli for automating droplet management with sane defaults baked in.
3
+ Simple "interactive" cli for automating digitalocean droplet management with sane defaults baked in for research and development.
4
+
5
+ Expirementing with the cloud can be expensive and stressful when you have to manually setup and take down Virtual Machines in order to avoid unwanted charges.
6
+
7
+ Have you ever wonderd "Hmmm... If only there was a simple way to have a linux server in the cloud so that I can fully take advantage of all those free new member credits"?
8
+
9
+ Most tools are not geared towards automating provisioning for simple research and development on cloud platforms. In fact they can be quite overwhelming with the multitude of different configurations they provide on all their cloud services.
10
+
11
+ red_drop is an easy to use tool that will take the stress out of provisioning and destroying droplets with reasonable configurations for research and development on digitalocean's cloud.
4
12
 
5
13
  ## Installation
6
14
 
@@ -14,8 +22,18 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
22
 
15
23
  ## Usage
16
24
 
25
+ After installing the gem, simply enter the following command:
26
+
17
27
  $ red_drop
18
28
 
29
+ It will then try to look for a valid authentication token. If it can't find one it will prompt you for one. You can find yours or generate one from the API tab on your digitalocean dashboard panel.
30
+
31
+ In order to use this tool you will need a digitalocean account with a payment method on your account. You can use the referral badge below to sign up with $200 of free credit for 60 days to use as your payment method.
32
+
33
+ [![DigitalOcean Referral Badge](https://web-platforms.sfo2.digitaloceanspaces.com/WWW/Badge%203.svg)](https://www.digitalocean.com/?refcode=9a321408e86f&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
34
+
35
+ The referral badge above will also help fund research and developmet on the project.
36
+
19
37
  ## Development
20
38
 
21
39
  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.
@@ -29,13 +47,25 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sergio
29
47
  ### Todos
30
48
 
31
49
  - Research: TDD whether its w/ minitest or rspec
32
- - Refactor: status module to match delete module droplets data structure
33
- - Research: converting delete module droplets array to hash to avoid accidental deletions
34
- - Refactor: delete module while loop to match that of red_drop.rb
35
- - Research: Faraday, used by DropletKit, to replace built-in HTTP client library
36
- - Research: status module to get ip address of runnning droplets
37
- - Research: delete module to get droplet status before executing
38
- - Research: using cloud_init to automate server config for SSH, ufw, docker
50
+ - Research: authenticating ssh key on DigitalOcean to eventually disable password login
51
+ - Research: delete and status class to filter droplet destroy status before puts droplets
52
+ - Research: \# frozen_string_literal: true "magic comment"
53
+ - Research: File system programming in Ruby
54
+ - Research: replacing droplet_kit wrapper for vanilla Faraday http client library
55
+ - Features: cloud-init cloud-config.yaml for user_data in create class request
56
+ - Research: including created_at when puts droplets
57
+
58
+ ### Useful Links
59
+
60
+ [Ruby language reference](https://www.ruby-lang.org/en/)
61
+
62
+ [RubyGems docs](https://guides.rubygems.org/)
63
+
64
+ [Faraday: http client library](https://lostisland.github.io/faraday/)
65
+
66
+ [DigitalOcean API reference](https://docs.digitalocean.com/reference/api/)
67
+
68
+ [cloud-init reference](https://cloudinit.readthedocs.io/en/latest/topics/modules.html)
39
69
 
40
70
  ## License
41
71
 
data/exe/red_drop CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "red_drop"
4
4
 
5
- RedDrop.start
5
+ RedDrop.new.begin
data/lib/red_drop/auth.rb CHANGED
@@ -1,27 +1,28 @@
1
- require "net/http"
1
+ require "faraday"
2
2
 
3
3
  class Auth
4
4
  def initialize
5
+ puts "loading..."
6
+
5
7
  file = File.open("secret.txt", "a+")
6
8
  @secret = file.read
7
9
  file.close
8
10
 
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)
11
+ @faraday = Faraday.new("https://api.digitalocean.com/v2/droplets")
12
+ @res = @faraday.get do |req|
13
+ req.headers["Authorization"] = "Bearer #{@secret}"
14
+ end
15
15
  end
16
16
 
17
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."
18
+ while @secret.empty? or not @res.success?
19
+ puts "\nThere in no valid API token in memory,\nplease enter a valid API token."
20
20
  @secret = gets.chomp
21
21
  File.write("secret.txt", @secret)
22
22
 
23
- @req["Authorization"] = "Bearer #{@secret}"
24
- @res = @http.request(@req)
23
+ @res = @faraday.get do |req|
24
+ req.headers["Authorization"] = "Bearer #{@secret}"
25
+ end
25
26
  end
26
27
  @secret
27
28
  end
@@ -5,8 +5,9 @@ class Create
5
5
 
6
6
  def execute
7
7
  puts "loading... \n\n"
8
+ #user_data = File.read("cloud-config.yaml")
8
9
 
9
- droplet = DropletKit::Droplet.new(name: 'drop', region: 'nyc1', size: 's-1vcpu-512mb-10gb', image: 'ubuntu-22-04-x64')
10
+ droplet = DropletKit::Droplet.new(name: 'RedDrop', region: 'nyc1', size: 's-1vcpu-512mb-10gb', image: 'ubuntu-22-04-x64')
10
11
  response = @client.droplets.create(droplet)
11
12
 
12
13
  puts "Your droplet: #{response.id}, is being provisioned.\n"
@@ -4,31 +4,33 @@ class Delete
4
4
  end
5
5
 
6
6
  def execute
7
- puts "loading... \n\n"
7
+ puts "loading... \n"
8
8
 
9
9
  droplets = @client.droplets.all.map { |droplet| droplet.to_h }
10
10
 
11
11
  if droplets.length == 0
12
- puts "There are no droplets in your DigitalOcean cloud.\n"
12
+ puts "\nThere are no droplets in your DigitalOcean cloud.\n"
13
13
  return
14
14
  end
15
15
 
16
- puts "option: droplet_id\n"
17
- droplets.each_with_index { |droplet, index| puts "#{index}: #{droplet[:id]}" }
18
- puts "\nPlease enter an option for a droplet to delete?\n\n"
19
- num = gets.to_i
16
+ hash = {}
17
+ droplets.each_with_index { |drop, i| hash[i.to_s] = drop }
18
+ droplets = hash
20
19
 
21
- while not droplets[num]
22
- puts "\n#{num} is not a valid option, please enter a valid option\n\n"
23
- num = gets.to_i
20
+ option = nil
21
+
22
+ until droplets.has_key? option
23
+ puts "\noption: droplet_id\n"
24
+ droplets.each { |key, droplet| puts "#{key}: #{droplet[:id]}" }
25
+ puts "\nPlease enter an option for a droplet to delete?\n\n"
26
+
27
+ option = gets.chomp
24
28
  end
25
29
 
26
- response = @client.droplets.delete(id: droplets[num][:id])
30
+ response = @client.droplets.delete(id: droplets[option][:id])
27
31
 
28
32
  if response
29
33
  puts "\ndelete request processed succesfully\n\n"
30
- else
31
- result
32
34
  end
33
35
  end
34
36
  end
@@ -6,16 +6,24 @@ class Status
6
6
  def execute
7
7
  puts "loading... \n\n"
8
8
 
9
- droplets = @client.droplets.all.map { |droplet| { "droplet_id" => droplet.id, "status" => droplet.status } }
10
- status = { "new" => "provisioning", "active" => "running" }
11
- droplets.each { |drop| drop["status"] = status[drop["status"]] }
9
+ droplets = @client.droplets.all.map { |droplet| droplet.to_h }
12
10
 
13
11
  if droplets.length == 0
14
12
  puts "There are no droplets in your DigitalOcean cloud."
15
13
  return
16
14
  end
17
15
 
18
- droplets.each { |droplet| puts droplet}
16
+ droplets.each do |droplet|
17
+ droplet[:networks] = droplet[:networks][:v4].find { |n| n[:type] == "public" }
18
+
19
+ if droplet[:networks]
20
+ droplet[:ip] = "running on #{droplet[:networks][:ip_address]}"
21
+ else
22
+ droplet[:ip] = "ip not yet assigned, try again in a minute"
23
+ end
24
+
25
+ puts "droplet: #{droplet[:id]} #{droplet[:ip]}"
26
+ end
19
27
  end
20
28
  end
21
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedDrop
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/red_drop.rb CHANGED
@@ -1,27 +1,29 @@
1
1
  require "red_drop/auth"
2
- require 'droplet_kit'
2
+ require "droplet_kit"
3
3
  require "red_drop/create"
4
4
  require "red_drop/status"
5
5
  require "red_drop/delete"
6
6
 
7
7
  class RedDrop
8
- client = DropletKit::Client.new(access_token: Auth.new.token)
8
+ def initialize
9
+ client = DropletKit::Client.new(access_token: Auth.new.token)
9
10
 
10
- @@task_menu = {
11
- "create" => Create.new(client),
12
- "status" => Status.new(client),
13
- "delete" => Delete.new(client)
14
- }
11
+ @task_menu = {
12
+ "create" => Create.new(client),
13
+ "status" => Status.new(client),
14
+ "delete" => Delete.new(client)
15
+ }
16
+ end
15
17
 
16
- def self.start
18
+ def begin
17
19
  input = nil
18
20
 
19
21
  until input.eql? "exit"
20
- puts "\nEnter from task menu below.\n#{@@task_menu.keys << "exit"}\n\n"
22
+ puts "\nEnter from task menu below.\n#{@task_menu.keys << "exit"}\n\n"
21
23
 
22
24
  input = gets.chomp
23
25
 
24
- @@task_menu[input].execute if @@task_menu.has_key? input
26
+ @task_menu[input].execute if @task_menu.has_key? input
25
27
  end
26
28
  end
27
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_drop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Ortiz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-reporters