Top Level Namespace
Defined Under Namespace
Modules: OceanKit
Instance Method Summary collapse
- #access_token ⇒ Object
- #add_http_rule(rules_array) ⇒ Object
- #add_ssh_rule(rules_array) ⇒ Object
- #bold_text(text) ⇒ Object
- #check_credentials_file ⇒ Object
- #credentials_file ⇒ Object
- #default_text(text) ⇒ Object
- #do_client ⇒ Object
- #fetch_firewall(number) ⇒ Object
- #firewall_inbound_rules(firewall) ⇒ Object
- #new_inbound_rule(rule) ⇒ Object
- #pastel ⇒ Object
- #remove_http_rule(rules_array) ⇒ Object
- #remove_ssh_rule(rules_array) ⇒ Object
- #underline_text(text) ⇒ Object
- #update_firewall(firewall) ⇒ Object
Instance Method Details
#access_token ⇒ Object
7 8 9 |
# File 'lib/ocean_kit/helpers/client.rb', line 7 def access_token credentials_file["digital_ocean_token"] end |
#add_http_rule(rules_array) ⇒ Object
38 39 40 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 38 def add_http_rule(rules_array) rules_array << {protocol: "tcp", ports: "80", sources: {addresses: ["0.0.0.0/0", "::/0"]}} end |
#add_ssh_rule(rules_array) ⇒ Object
34 35 36 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 34 def add_ssh_rule(rules_array) rules_array << {protocol: "tcp", ports: "22", sources: {addresses: ["0.0.0.0/0", "::/0"]}} end |
#bold_text(text) ⇒ Object
15 16 17 |
# File 'lib/ocean_kit/helpers/console.rb', line 15 def bold_text(text) pastel.white.bold(text) end |
#check_credentials_file ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ocean_kit/helpers/client.rb', line 15 def check_credentials_file if credentials_file.nil? puts pastel.red.bold("Error: credentials file not found. Please run `ocean_kit config setup` first.") exit 1 end end |
#credentials_file ⇒ Object
11 12 13 |
# File 'lib/ocean_kit/helpers/client.rb', line 11 def credentials_file YAML.load(File.read(File.("~/.ocean_kit/credentials.yml"))) end |
#default_text(text) ⇒ Object
7 8 9 |
# File 'lib/ocean_kit/helpers/console.rb', line 7 def default_text(text) pastel.white(text) end |
#do_client ⇒ Object
3 4 5 |
# File 'lib/ocean_kit/helpers/client.rb', line 3 def do_client DropletKit::Client.new(access_token: access_token) end |
#fetch_firewall(number) ⇒ Object
3 4 5 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 3 def fetch_firewall(number) do_client.firewalls.all.each_with_index.filter { |firewall, index| index == number.to_i }.flatten.first end |
#firewall_inbound_rules(firewall) ⇒ Object
18 19 20 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 18 def firewall_inbound_rules(firewall) firewall.inbound_rules.map(&:to_h) end |
#new_inbound_rule(rule) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 22 def new_inbound_rule(rule) DropletKit::FirewallInboundRule.new( protocol: rule[:protocol], ports: rule[:ports], sources: rule[:sources] ) end |
#pastel ⇒ Object
3 4 5 |
# File 'lib/ocean_kit/helpers/console.rb', line 3 def pastel Pastel.new end |
#remove_http_rule(rules_array) ⇒ Object
42 43 44 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 42 def remove_http_rule(rules_array) rules_array.delete_if { |r| r[:ports] == "80" } end |
#remove_ssh_rule(rules_array) ⇒ Object
30 31 32 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 30 def remove_ssh_rule(rules_array) rules_array.delete_if { |r| r[:ports] == "22" } end |
#underline_text(text) ⇒ Object
11 12 13 |
# File 'lib/ocean_kit/helpers/console.rb', line 11 def underline_text(text) pastel.white.bold.underline(text) end |
#update_firewall(firewall) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ocean_kit/helpers/firewalls.rb', line 7 def update_firewall(firewall) new_firewall = DropletKit::Firewall.new( name: firewall.name, inbound_rules: firewall.inbound_rules.map { |rule| new_inbound_rule(rule) }, outbound_rules: firewall.outbound_rules, droplet_ids: firewall.droplet_ids, tags: firewall. ) do_client.firewalls.update(new_firewall, id: firewall.id) end |