ocean_kit 0.1.0 → 0.1.3

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: 75b92697c923ba3bbd38986a848323ad9698ceb0d2efee2f966867f401870486
4
- data.tar.gz: f7608656bda388738745ff19676e1109e8f5e53e7242137768b55ed0e068a9c7
3
+ metadata.gz: 2b7e53bd320bed32a746bf8c938e41916adc797399bc99f31588b1a046e0251f
4
+ data.tar.gz: bbc4ccb88be8a07bf60856eff18070c0506dd0b65493b2f2e8fefdae0a5593f3
5
5
  SHA512:
6
- metadata.gz: 369985ffe1b373181333a5f85316cf6fa197e6df49a45cd7bd25705949de5d35d762e785edbabe86c867d66be96ca77c0c2cdedb76c733d2115748a111bda29e
7
- data.tar.gz: b1d14c0a7cfd969c5bd592700f5eaca224a6875e835e56ce276adc26dfa55994f2dfacd46e56ad72ceade3beafbc0490bf0aa46e4426dda774bd1365922e8b93
6
+ metadata.gz: 91c945c7f2b00964879a4c90db6b5d1190c5de0acc90dda89abeb64f682628ec2f5616d8276e315f3fedaa80bd4f30b89a27fa683488ba75b45059453bb54f2c
7
+ data.tar.gz: 2054bd0e4293709c4616a9f40538d0f6b733a8e40537eb727802c943148fb42e8537534b1ebe428bc9a6b205fd32e624e989fd63d13d98d5cc097b29dbf5fbb1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ocean_kit (0.1.0)
4
+ ocean_kit (0.1.2)
5
5
  droplet_kit (~> 3.16, >= 3.16.1)
6
6
  pastel
7
7
  thor (~> 1.2)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OceanKit
2
2
 
3
- Digital Ocean CLI to update account settings.
3
+ Digital Ocean CLI.
4
4
 
5
5
  ## Installation
6
6
 
data/exe/ocean_kit CHANGED
@@ -2,6 +2,4 @@
2
2
 
3
3
  require "ocean_kit"
4
4
 
5
- require_relative "../lib/helpers"
6
-
7
5
  OceanKit::Client.start(ARGV)
@@ -0,0 +1,3 @@
1
+ require_relative "./client"
2
+ require_relative "./console"
3
+ require_relative "./firewalls"
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ def do_client
4
+ DropletKit::Client.new(access_token: access_token)
5
+ end
6
+
7
+ def access_token
8
+ credentials_file = YAML.load(File.read(File.expand_path("~/.ocean_kit/credentials.yml")))
9
+ credentials_file["digital_ocean_token"]
10
+ rescue => e
11
+ puts pastel.red.bold("Error: #{e.message}")
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ def pastel
4
+ Pastel.new
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ def fetch_firewall(number)
4
+ do_client.firewalls.all.each_with_index.filter { |firewall, index| index == number.to_i }.flatten.first
5
+ end
6
+
7
+ def update_firewall(firewall)
8
+ new_firewall = DropletKit::Firewall.new(
9
+ name: firewall.name,
10
+ inbound_rules: firewall.inbound_rules.map { |rule| new_inbound_rule(rule) },
11
+ outbound_rules: firewall.outbound_rules,
12
+ droplet_ids: firewall.droplet_ids,
13
+ tags: firewall.tags
14
+ )
15
+ do_client.firewalls.update(new_firewall, id: firewall.id)
16
+ end
17
+
18
+ def firewall_inbound_rules(firewall)
19
+ firewall.inbound_rules.map(&:to_h)
20
+ end
21
+
22
+ def new_inbound_rule(rule)
23
+ DropletKit::FirewallInboundRule.new(
24
+ protocol: rule[:protocol],
25
+ ports: rule[:ports],
26
+ sources: rule[:sources]
27
+ )
28
+ end
29
+
30
+ def remove_ssh_rule(rules_array)
31
+ rules_array.delete_if { |r| r[:ports] == "22" }
32
+ end
33
+
34
+ def add_ssh_rule(rules_array)
35
+ rules_array << {protocol: "tcp", ports: "22", sources: {addresses: ["0.0.0.0/0", "::/0"]}}
36
+ end
@@ -0,0 +1 @@
1
+ require_relative "./firewalls"
@@ -7,6 +7,9 @@ module OceanKit
7
7
  puts pastel.white.bold.underline("Firewalls:\n")
8
8
  do_client.firewalls.all.each_with_index do |firewall, index|
9
9
  puts pastel.white.bold("[#{index}]: Firewall #{firewall.name} has #{firewall.droplet_ids.count} droplets")
10
+ firewall_inbound_rules(firewall).each_with_index do |rule, ii|
11
+ puts pastel.blue.bold(" [#{ii}] #{pastel.blue.bold(rule)}")
12
+ end
10
13
  end
11
14
  end
12
15
 
@@ -14,12 +17,11 @@ module OceanKit
14
17
  def enable_all_ssh
15
18
  puts pastel.white.bold("Enabling SSH on all firewalls")
16
19
  do_client.firewalls.all.each_with_index do |fw, index|
17
- firewall = do_client.firewalls.find(id: fw.id)
18
- inbound_rules = firewall_inbound_rules(firewall)
19
- firewall.inbound_rules = add_ssh_rule(inbound_rules)
20
+ inbound_rules = firewall_inbound_rules(fw)
21
+ fw.inbound_rules = add_ssh_rule(inbound_rules)
20
22
  begin
21
- update_firewall(firewall)
22
- puts pastel.green.bold("SSH enabled on firewall #{firewall.name}")
23
+ update_firewall(fw)
24
+ puts pastel.green.bold("SSH enabled on firewall #{fw.name}")
23
25
  rescue DropletKit::Error => e
24
26
  puts pastel.red.bold("Error: #{e.message}")
25
27
  end
@@ -30,12 +32,11 @@ module OceanKit
30
32
  def disable_all_ssh
31
33
  puts pastel.white.bold("Disabling SSH on all firewalls")
32
34
  do_client.firewalls.all.each_with_index do |fw, index|
33
- firewall = do_client.firewalls.find(id: fw.id)
34
- inbound_rules = firewall_inbound_rules(firewall)
35
- firewall.inbound_rules = remove_ssh_rule(inbound_rules)
35
+ inbound_rules = firewall_inbound_rules(fw)
36
+ fw.inbound_rules = remove_ssh_rule(inbound_rules)
36
37
  begin
37
- update_firewall(firewall)
38
- puts pastel.green.bold("SSH disabled on firewall #{firewall.name}")
38
+ update_firewall(fw)
39
+ puts pastel.green.bold("SSH disabled on firewall #{fw.name}")
39
40
  rescue DropletKit::Error => e
40
41
  puts pastel.red.bold("Error: #{e.message}")
41
42
  end
@@ -44,7 +45,7 @@ module OceanKit
44
45
 
45
46
  desc "enable_ssh [firewall_number]", "Enable SSH on given firewall"
46
47
  def enable_ssh(number)
47
- firewall = do_client.firewalls.find(id: fetch_firewall_id(number))
48
+ firewall = fetch_firewall(number)
48
49
  inbound_rules = firewall_inbound_rules(firewall)
49
50
  firewall.inbound_rules = add_ssh_rule(inbound_rules)
50
51
  begin
@@ -57,7 +58,7 @@ module OceanKit
57
58
 
58
59
  desc "disable_ssh [firewall_number]", "Disable SSH on given firewall"
59
60
  def disable_ssh(number)
60
- firewall = do_client.firewalls.find(id: fetch_firewall_id(number))
61
+ firewall = fetch_firewall(number)
61
62
  inbound_rules = firewall_inbound_rules(firewall)
62
63
  firewall.inbound_rules = remove_ssh_rule(inbound_rules)
63
64
  begin
@@ -67,50 +68,5 @@ module OceanKit
67
68
  puts pastel.red.bold("Error: #{e.message}")
68
69
  end
69
70
  end
70
-
71
- private
72
-
73
- def fetch_firewall_id(number)
74
- do_client.firewalls.all.each_with_index.filter { |firewall, index| index == number.to_i }.flatten.first.id
75
- end
76
-
77
- def update_firewall(firewall)
78
- new_firewall = DropletKit::Firewall.new(
79
- name: firewall.name,
80
- inbound_rules: firewall.inbound_rules.map { |rule| new_inbound_rule(rule) },
81
- outbound_rules: firewall.outbound_rules,
82
- droplet_ids: firewall.droplet_ids,
83
- tags: firewall.tags
84
- )
85
- do_client.firewalls.update(new_firewall, id: firewall.id)
86
- end
87
-
88
- def firewall_inbound_rules(firewall)
89
- firewall.inbound_rules.map(&:to_h)
90
- end
91
-
92
- def new_inbound_rule(rule)
93
- DropletKit::FirewallInboundRule.new(
94
- protocol: rule[:protocol],
95
- ports: rule[:ports],
96
- sources: rule[:sources]
97
- )
98
- end
99
-
100
- def remove_ssh_rule(rules_array)
101
- rules_array.delete_if { |r| r[:ports] == "22" }
102
- end
103
-
104
- def add_ssh_rule(rules_array)
105
- rules_array << {protocol: "tcp", ports: "22", sources: {addresses: ["0.0.0.0/0", "::/0"]}}
106
- end
107
-
108
- def pastel
109
- Pastel.new
110
- end
111
-
112
- def find_firewall_by_id(id)
113
- do_client.firewalls.find(id:)
114
- end
115
71
  end
116
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OceanKit
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/ocean_kit.rb CHANGED
@@ -6,23 +6,13 @@ require "thor"
6
6
  require "yaml"
7
7
 
8
8
  require_relative "ocean_kit/version"
9
- require_relative "./ocean_kit/firewalls"
9
+ require_relative "./ocean_kit/resources/base"
10
+ require_relative "./ocean_kit/helpers/base"
10
11
 
11
12
  module OceanKit
12
13
  class Client < Thor
13
14
  desc "firewalls SUBCOMMAND ...ARGS", "manage your DO firewall"
14
15
  subcommand "firewalls", Firewalls
15
-
16
- no_commands {
17
- def client
18
- DropletKit::Client.new(access_token: access_token)
19
- end
20
-
21
- def access_token
22
- credentials_file = YAML.load(File.read(File.expand_path("~/.ocean_kit/credentials.yml")))
23
- credentials_file["digital_ocean_token"]
24
- end
25
- }
26
16
  end
27
17
 
28
18
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Policastro
@@ -77,9 +77,13 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - exe/ocean_kit
80
- - lib/helpers.rb
81
80
  - lib/ocean_kit.rb
82
- - lib/ocean_kit/firewalls.rb
81
+ - lib/ocean_kit/helpers/base.rb
82
+ - lib/ocean_kit/helpers/client.rb
83
+ - lib/ocean_kit/helpers/console.rb
84
+ - lib/ocean_kit/helpers/firewalls.rb
85
+ - lib/ocean_kit/resources/base.rb
86
+ - lib/ocean_kit/resources/firewalls.rb
83
87
  - lib/ocean_kit/version.rb
84
88
  - ocean_kit.gemspec
85
89
  - sig/ocean_kit.rbs
data/lib/helpers.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def do_client
4
- ocean = OceanKit::Client.new
5
- ocean.client
6
- end