Class: OceanKit::Firewalls
- Inherits:
-
Thor
- Object
- Thor
- OceanKit::Firewalls
- Defined in:
- lib/ocean_kit/resources/firewalls.rb
Instance Method Summary collapse
- #disable_all_ssh ⇒ Object
- #disable_http(number) ⇒ Object
- #disable_ssh(number) ⇒ Object
- #enable_all_ssh ⇒ Object
- #enable_http(number) ⇒ Object
- #enable_ssh(number) ⇒ Object
- #list ⇒ Object
Instance Method Details
#disable_all_ssh ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 32 def disable_all_ssh puts pastel.white.bold("Disabling SSH on all firewalls") do_client.firewalls.all.each_with_index do |fw, index| inbound_rules = firewall_inbound_rules(fw) fw.inbound_rules = remove_ssh_rule(inbound_rules) begin update_firewall(fw) puts pastel.green.bold("SSH disabled on firewall #{fw.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end end |
#disable_http(number) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 86 def disable_http(number) firewall = fetch_firewall(number) inbound_rules = firewall_inbound_rules(firewall) firewall.inbound_rules = remove_http_rule(inbound_rules) begin update_firewall(firewall) puts pastel.green.bold("HTTP disabled on firewall #{firewall.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end |
#disable_ssh(number) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 60 def disable_ssh(number) firewall = fetch_firewall(number) inbound_rules = firewall_inbound_rules(firewall) firewall.inbound_rules = remove_ssh_rule(inbound_rules) begin update_firewall(firewall) puts pastel.green.bold("SSH disabled on firewall #{firewall.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end |
#enable_all_ssh ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 17 def enable_all_ssh puts pastel.white.bold("Enabling SSH on all firewalls") do_client.firewalls.all.each_with_index do |fw, index| inbound_rules = firewall_inbound_rules(fw) fw.inbound_rules = add_ssh_rule(inbound_rules) begin update_firewall(fw) puts pastel.green.bold("SSH enabled on firewall #{fw.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end end |
#enable_http(number) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 73 def enable_http(number) firewall = fetch_firewall(number) inbound_rules = firewall_inbound_rules(firewall) firewall.inbound_rules = add_http_rule(inbound_rules) begin update_firewall(firewall) puts pastel.green.bold("HTTP enabled on firewall #{firewall.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end |
#enable_ssh(number) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 47 def enable_ssh(number) firewall = fetch_firewall(number) inbound_rules = firewall_inbound_rules(firewall) firewall.inbound_rules = add_ssh_rule(inbound_rules) begin update_firewall(firewall) puts pastel.green.bold("SSH enabled on firewall #{firewall.name}") rescue DropletKit::Error => e puts pastel.red.bold("Error: #{e.}") end end |
#list ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/ocean_kit/resources/firewalls.rb', line 6 def list puts pastel.white.bold.underline("Firewalls:\n") do_client.firewalls.all.each_with_index do |firewall, index| puts pastel.white.bold("[#{index}]: Firewall #{firewall.name} has #{firewall.droplet_ids.count} droplets") firewall_inbound_rules(firewall).each_with_index do |rule, ii| puts pastel.blue.bold(" [#{ii}] #{pastel.blue.bold(rule)}") end end end |