ocean_kit 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/exe/ocean_kit +1 -1
- data/lib/ocean_kit/helpers/base.rb +3 -0
- data/lib/ocean_kit/helpers/client.rb +20 -0
- data/lib/ocean_kit/helpers/console.rb +17 -0
- data/lib/ocean_kit/helpers/firewalls.rb +36 -0
- data/lib/ocean_kit/resources/base.rb +3 -0
- data/lib/ocean_kit/resources/config.rb +21 -0
- data/lib/ocean_kit/resources/droplets.rb +21 -0
- data/lib/ocean_kit/{firewalls.rb → resources/firewalls.rb} +1 -46
- data/lib/ocean_kit/version.rb +1 -1
- data/lib/ocean_kit.rb +8 -12
- metadata +9 -3
- data/lib/helpers.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84dcf8fe7afd5f888192ce09e6ec3c7153052a812142ae4726d7cbf15b7a43dd
|
4
|
+
data.tar.gz: 930fa733a585ea61efe68c924b66596bf05b80f63282e535f4435f5e1e8adb2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1189f7a21bd24d3bddbf4d0b2144a3b67e1f16df14c02b6b38189cbf921ef2c4bbf5bec976640860ce3a4a7dd9acbefbb23a94ed6f9b52fd38d3db48cff844f1
|
7
|
+
data.tar.gz: 073dc845350bea427160ec66556ffcb06bde23b95cacac2b28b0065f5f58e2cb9543edf372cdfe640bbef32661c49095e3544644bfab1d2f78f8493b8348c9f6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -55,7 +55,7 @@ Commands:
|
|
55
55
|
ocean_kit firewalls enable_all_ssh # Enables SSH on all firewalls
|
56
56
|
ocean_kit firewalls enable_ssh [firewall_number] # Enable SSH on given firewall
|
57
57
|
ocean_kit firewalls help [COMMAND] # Describe subcommands or one specific subcommand
|
58
|
-
ocean_kit firewalls list # Lists all firewalls
|
58
|
+
ocean_kit firewalls list # Lists all firewalls.
|
59
59
|
```
|
60
60
|
|
61
61
|
## Development
|
data/exe/ocean_kit
CHANGED
@@ -0,0 +1,20 @@
|
|
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["digital_ocean_token"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def credentials_file
|
12
|
+
YAML.load(File.read(File.expand_path("~/.ocean_kit/credentials.yml")))
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_credentials_file
|
16
|
+
if credentials_file.nil?
|
17
|
+
puts pastel.red.bold("Error: credentials file not found. Please run `ocean_kit setup` first.")
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def pastel
|
4
|
+
Pastel.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def default_text(text)
|
8
|
+
pastel.white(text)
|
9
|
+
end
|
10
|
+
|
11
|
+
def underline_text(text)
|
12
|
+
pastel.white.bold.underline(text)
|
13
|
+
end
|
14
|
+
|
15
|
+
def bold_text(text)
|
16
|
+
pastel.white.bold(text)
|
17
|
+
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,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OceanKit
|
4
|
+
class Config < Thor
|
5
|
+
desc "setup", "Setup OceanKit environment"
|
6
|
+
def setup
|
7
|
+
# First create the ~/.ocean_kit directory if it doesn't exist
|
8
|
+
Dir.mkdir(File.expand_path("~/.ocean_kit")) unless File.directory?(File.expand_path("~/.ocean_kit"))
|
9
|
+
# Next create the credentials.yml file if it doesn't exist
|
10
|
+
unless File.file?(File.expand_path("~/.ocean_kit/credentials.yml"))
|
11
|
+
File.write(File.expand_path("~/.ocean_kit/credentials.yml"), <<~YAML)
|
12
|
+
---
|
13
|
+
digital_ocean_token: <YOUR_DIGITAL_OCEAN_TOKEN>
|
14
|
+
|
15
|
+
YAML
|
16
|
+
end
|
17
|
+
puts pastel.green.bold("Successfully setup OceanKit environment.")
|
18
|
+
puts pastel.white.bold("Please add your Digital Ocean personal access token your credentials in ~/.ocean_kit/credentials.yml")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OceanKit
|
4
|
+
class Droplets < Thor
|
5
|
+
desc "list", "Lists all droplers."
|
6
|
+
def list
|
7
|
+
puts underline_text("Droplets:\n")
|
8
|
+
do_client.droplets.all.each_with_index do |droplet, index|
|
9
|
+
puts "------------------------------\n"
|
10
|
+
|
11
|
+
puts pastel.white.bold "#: ", pastel.clear.white(index + 1)
|
12
|
+
puts pastel.white.bold "Name: ", pastel.clear.white(droplet.name)
|
13
|
+
puts pastel.white.bold "ID: ", pastel.clear.white(droplet.id)
|
14
|
+
puts pastel.white.bold "Public IP: ", pastel.clear.white(droplet.networks.v4.first.ip_address)
|
15
|
+
puts pastel.white.bold "Region: ", pastel.clear.white(droplet.region.slug)
|
16
|
+
puts pastel.white.bold "Status: ", pastel.clear.white(droplet.status)
|
17
|
+
puts pastel.white.bold "Created: ", pastel.clear.white(droplet.created_at)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module OceanKit
|
4
4
|
class Firewalls < Thor
|
5
|
-
desc "list", "Lists all firewalls
|
5
|
+
desc "list", "Lists all firewalls."
|
6
6
|
def list
|
7
7
|
puts pastel.white.bold.underline("Firewalls:\n")
|
8
8
|
do_client.firewalls.all.each_with_index do |firewall, index|
|
@@ -68,50 +68,5 @@ module OceanKit
|
|
68
68
|
puts pastel.red.bold("Error: #{e.message}")
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def fetch_firewall(number)
|
75
|
-
do_client.firewalls.all.each_with_index.filter { |firewall, index| index == number.to_i }.flatten.first
|
76
|
-
end
|
77
|
-
|
78
|
-
def update_firewall(firewall)
|
79
|
-
new_firewall = DropletKit::Firewall.new(
|
80
|
-
name: firewall.name,
|
81
|
-
inbound_rules: firewall.inbound_rules.map { |rule| new_inbound_rule(rule) },
|
82
|
-
outbound_rules: firewall.outbound_rules,
|
83
|
-
droplet_ids: firewall.droplet_ids,
|
84
|
-
tags: firewall.tags
|
85
|
-
)
|
86
|
-
do_client.firewalls.update(new_firewall, id: firewall.id)
|
87
|
-
end
|
88
|
-
|
89
|
-
def firewall_inbound_rules(firewall)
|
90
|
-
firewall.inbound_rules.map(&:to_h)
|
91
|
-
end
|
92
|
-
|
93
|
-
def new_inbound_rule(rule)
|
94
|
-
DropletKit::FirewallInboundRule.new(
|
95
|
-
protocol: rule[:protocol],
|
96
|
-
ports: rule[:ports],
|
97
|
-
sources: rule[:sources]
|
98
|
-
)
|
99
|
-
end
|
100
|
-
|
101
|
-
def remove_ssh_rule(rules_array)
|
102
|
-
rules_array.delete_if { |r| r[:ports] == "22" }
|
103
|
-
end
|
104
|
-
|
105
|
-
def add_ssh_rule(rules_array)
|
106
|
-
rules_array << {protocol: "tcp", ports: "22", sources: {addresses: ["0.0.0.0/0", "::/0"]}}
|
107
|
-
end
|
108
|
-
|
109
|
-
def pastel
|
110
|
-
Pastel.new
|
111
|
-
end
|
112
|
-
|
113
|
-
def find_firewall_by_id(id)
|
114
|
-
do_client.firewalls.find(id:)
|
115
|
-
end
|
116
71
|
end
|
117
72
|
end
|
data/lib/ocean_kit/version.rb
CHANGED
data/lib/ocean_kit.rb
CHANGED
@@ -6,23 +6,19 @@ require "thor"
|
|
6
6
|
require "yaml"
|
7
7
|
|
8
8
|
require_relative "ocean_kit/version"
|
9
|
-
require_relative "./ocean_kit/
|
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
|
-
desc "
|
14
|
-
subcommand "
|
14
|
+
desc "config SUBCOMMAND ...ARGS", "Create OceanKit folder and credentials.yml file"
|
15
|
+
subcommand "config", Config
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
DropletKit::Client.new(access_token: access_token)
|
19
|
-
end
|
17
|
+
desc "droplets SUBCOMMAND ...ARGS", "manage your Digital Ocean droplets"
|
18
|
+
subcommand "droplets", Droplets
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
credentials_file["digital_ocean_token"]
|
24
|
-
end
|
25
|
-
}
|
20
|
+
desc "firewalls SUBCOMMAND ...ARGS", "manage your Digital Ocean firewalls"
|
21
|
+
subcommand "firewalls", Firewalls
|
26
22
|
end
|
27
23
|
|
28
24
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leo Policastro
|
@@ -77,9 +77,15 @@ 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/
|
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/config.rb
|
87
|
+
- lib/ocean_kit/resources/droplets.rb
|
88
|
+
- lib/ocean_kit/resources/firewalls.rb
|
83
89
|
- lib/ocean_kit/version.rb
|
84
90
|
- ocean_kit.gemspec
|
85
91
|
- sig/ocean_kit.rbs
|