red_drop 0.3.2 → 0.5.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: 0d28d88532deca7906c0a221dea00ed41441a10327fe2b0f8645683fd3212051
4
- data.tar.gz: 4092ed01f7810eb0f9f44862422a55a7d6657ca8dfc2b91baf1ad5353a40d18f
3
+ metadata.gz: 26e8eafa8d17697861606704de815460ab54c26ed722354cd1e11600df4df40b
4
+ data.tar.gz: ca8fe1639beb391c4e62f8881822a328d28d492c09f4e0fe632d85e542ea58ae
5
5
  SHA512:
6
- metadata.gz: 6b3924b1f24754a170c46b7f09bf6fcc35e5ab079999f6f448ed7bdd6fbe23e7e94613aa7df2413a20c99ea8d17f796620018cd71db3df18fadd03d800eb9e55
7
- data.tar.gz: bf86b6c9813d0e560f5d9b89ab7dc4d66dc5d6a6fe58a1167ce2f06d90ca0532bde3f685d100567fa1fb2dadeb3ea4a7b311e77e710a0cd32f1abd0a1ca3b1aa
6
+ metadata.gz: dc86110aab1a32d3979fb43db15587eaa7d4c746c92c37e6c4864d016dfd608aa5743f51a3e70cef2a8439e1370bff8d678c9761c90e124dbd52a923f79bf04d
7
+ data.tar.gz: fb5d12dd53f3efd7a0712729a0493fc99bafc54156cccd576a3d4d9bb2ccf852086529670c104d431b1d2b31c7aa5ff9a24f09efb8c2337a50854ed6639dabb5
data/Gemfile.lock CHANGED
@@ -1,37 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- red_drop (0.3.2)
5
- droplet_kit (~> 3.18)
4
+ red_drop (0.5.0)
5
+ faraday (~> 2.7)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.1)
11
- public_suffix (>= 2.0.2, < 6.0)
12
10
  ansi (1.5.0)
13
11
  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
12
  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)
13
+ faraday (2.7.2)
29
14
  faraday-net_http (>= 2.0, < 3.1)
30
15
  ruby2_keywords (>= 0.0.4)
31
16
  faraday-net_http (3.0.2)
32
- ice_nine (0.11.2)
33
17
  json (2.5.1)
34
- kartograph (0.2.8)
35
18
  minitest (5.16.3)
36
19
  minitest-reporters (1.5.0)
37
20
  ansi
@@ -41,12 +24,9 @@ GEM
41
24
  parallel (1.22.1)
42
25
  parser (3.1.3.0)
43
26
  ast (~> 2.4.1)
44
- public_suffix (5.0.0)
45
27
  rainbow (3.1.1)
46
28
  rake (13.0.6)
47
29
  regexp_parser (2.6.1)
48
- resource_kit (0.1.8)
49
- addressable (>= 2.3.6, < 3.0.0)
50
30
  rexml (3.2.5)
51
31
  rubocop (1.39.0)
52
32
  json (~> 2.3)
@@ -62,12 +42,7 @@ GEM
62
42
  parser (>= 3.1.1.0)
63
43
  ruby-progressbar (1.11.0)
64
44
  ruby2_keywords (0.0.5)
65
- thread_safe (0.3.6)
66
45
  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
46
 
72
47
  PLATFORMS
73
48
  x86_64-linux
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.
@@ -28,13 +46,25 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sergio
28
46
 
29
47
  ### Todos
30
48
 
31
- - Refactor: status module to match delete module droplets data structure
32
- - Refactor: delete module while loop to match that of red_drop.rb
33
49
  - Research: TDD whether its w/ minitest or rspec
34
- - Research: converting delete module droplets array to hash to avoid accidental deletions
35
- - Research: status module to get ip address of runnning droplets
36
- - Research: delete module to get droplet status before executing
37
- - 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
+ - Features: cloud-init cloud-config.yaml for user_data in create class request
55
+ - Research: including created_at when puts droplets
56
+
57
+ ### Useful Links
58
+
59
+ [Ruby language reference](https://www.ruby-lang.org/en/)
60
+
61
+ [RubyGems docs](https://guides.rubygems.org/)
62
+
63
+ [Faraday: http client library](https://lostisland.github.io/faraday/)
64
+
65
+ [DigitalOcean API reference](https://docs.digitalocean.com/reference/api/)
66
+
67
+ [cloud-init reference](https://cloudinit.readthedocs.io/en/latest/topics/modules.html)
38
68
 
39
69
  ## License
40
70
 
data/lib/red_drop/auth.rb CHANGED
@@ -8,10 +8,11 @@ class Auth
8
8
  @secret = file.read
9
9
  file.close
10
10
 
11
- @faraday = Faraday.new("https://api.digitalocean.com/v2/droplets")
12
- @res = @faraday.get do |req|
13
- req.headers["Authorization"] = "Bearer #{@secret}"
14
- end
11
+ @conn = Faraday.new(
12
+ url: "https://api.digitalocean.com/v2/droplets",
13
+ headers: {"Authorization" => "Bearer #{@secret}"},
14
+ )
15
+ @res = @conn.get
15
16
  end
16
17
 
17
18
  def token
@@ -20,10 +21,9 @@ class Auth
20
21
  @secret = gets.chomp
21
22
  File.write("secret.txt", @secret)
22
23
 
23
- @res = @faraday.get do |req|
24
- req.headers["Authorization"] = "Bearer #{@secret}"
25
- end
24
+ @conn.headers["Authorization"] = "Bearer #{@secret}"
25
+ @res = @conn.get
26
26
  end
27
- @secret
27
+ @conn
28
28
  end
29
29
  end
@@ -5,11 +5,15 @@ 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
- response = @client.droplets.create(droplet)
10
+ response = @client.post do |req|
11
+ req.body = {name: 'RedDrop', region: 'nyc1', size: 's-1vcpu-512mb-10gb', image: 'ubuntu-22-04-x64'}
12
+ end
13
+
14
+ body = JSON.parse(response.body)
11
15
 
12
- puts "Your droplet: #{response.id}, is being provisioned.\n"
16
+ puts "Your droplet: #{body["droplet"]["id"]}, is being provisioned.\n"
13
17
  end
14
18
  end
15
19
 
@@ -4,31 +4,35 @@ class Delete
4
4
  end
5
5
 
6
6
  def execute
7
- puts "loading... \n\n"
7
+ puts "loading... \n"
8
8
 
9
- droplets = @client.droplets.all.map { |droplet| droplet.to_h }
9
+ droplets = JSON.parse(@client.get.body)["droplets"]
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.delete(droplets[option]["id"].to_s)
27
31
 
28
- if response
32
+ if response.success?
29
33
  puts "\ndelete request processed succesfully\n\n"
30
- else
31
- result
34
+ else
35
+ puts response.body
32
36
  end
33
37
  end
34
38
  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 = JSON.parse(@client.get.body)["droplets"]
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["status"] = "running on #{droplet["networks"]["ip_address"]}"
21
+ else
22
+ droplet["status"] = "ip not yet assigned, try again in a minute"
23
+ end
24
+
25
+ puts "droplet: #{droplet["id"]} #{droplet["status"]}"
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.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/red_drop.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  require "red_drop/auth"
2
- require "droplet_kit"
3
2
  require "red_drop/create"
4
3
  require "red_drop/status"
5
4
  require "red_drop/delete"
6
5
 
7
6
  class RedDrop
8
7
  def initialize
9
- client = DropletKit::Client.new(access_token: Auth.new.token)
8
+ client = Auth.new.token
10
9
 
11
10
  @task_menu = {
12
11
  "create" => Create.new(client),
data/red_drop.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
33
  spec.add_development_dependency "minitest-reporters", "~> 1.5"
34
- spec.add_dependency "droplet_kit", "~> 3.18"
34
+ spec.add_dependency "faraday", "~> 2.7"
35
35
 
36
36
  # For more information and examples about making a new gem, check out our
37
37
  # guide at: https://bundler.io/guides/creating_gem.html
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.2
4
+ version: 0.5.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-09 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-reporters
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: droplet_kit
28
+ name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.18'
33
+ version: '2.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.18'
40
+ version: '2.7'
41
41
  description: A cli wriiten in ruby for executing automated droplet tasks with sane
42
42
  configurations baked in.
43
43
  email:
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.3.15
87
+ rubygems_version: 3.3.26
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Simple cli for automating droplet management