Class: CivoCLI::Firewall
- Inherits:
-
Thor
- Object
- Thor
- CivoCLI::Firewall
- Defined in:
- lib/firewall.rb
Instance Method Summary collapse
- #create(firewall_name) ⇒ Object
- #delete_rule(firewall_id, rule_id) ⇒ Object
- #list ⇒ Object
- #list_rules(firewall_id) ⇒ Object
- #new_rule ⇒ Object
- #remove(firewall_ID) ⇒ Object
Instance Method Details
#create(firewall_name) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/firewall.rb', line 4 def create(firewall_name) CivoCLI::Config.set_api_auth Civo::Firewall.create(name: firewall_name) puts "Created firewall #{firewall_name.colorize(:green)}" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#delete_rule(firewall_id, rule_id) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/firewall.rb', line 76 def delete_rule(firewall_id, rule_id) CivoCLI::Config.set_api_auth Civo::FirewallRule.remove(firewall_id: firewall_id, id: rule_id) puts "Removed Firewall rule #{rule_id.colorize(:red)}" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#list ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/firewall.rb', line 15 def list CivoCLI::Config.set_api_auth rows = [] Civo::Firewall.all.items.each do |element| rows << [element.id, element.name, element.rules_count, element.instances_count] end puts Terminal::Table.new headings: ['ID', 'Name', 'No. of Rules', 'instances using'], rows: rows rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#list_rules(firewall_id) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/firewall.rb', line 62 def list_rules(firewall_id) CivoCLI::Config.set_api_auth rules = Civo::FirewallRule.all(firewall_id: firewall_id) rows = [] rules.each do |rule| rows << [rule.id, rule.protocol, rule.start_port, rule.end_port, rule.direction, rule.cidr.items.join(", "), rule.label] end puts Terminal::Table.new title: "Firewall rules for #{firewall_id}", headings: ['ID', 'Protocol', 'Start Port', 'End Port', 'Direction', 'CIDR', 'Label'], rows: rows rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#new_rule ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/firewall.rb', line 46 def new_rule CivoCLI::Config.set_api_auth if ![:end_port] Civo::FirewallRule.create(firewall_id: [:firewall_id], start_port: [:start_port], end_port: [:start_port], cidr: [:cidr], direction: [:direction], label: [:label]) end if [:end_port] Civo::FirewallRule.create(firewall_id: [:firewall_id], start_port: [:start_port], end_port: [:end_port], cidr: [:cidr], direction: [:direction], label: [:label]) end puts "New rule" + ([:label].nil? ? "" : " #{[:label].colorize(:green)}") + " created" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#remove(firewall_ID) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/firewall.rb', line 29 def remove(firewall_ID) CivoCLI::Config.set_api_auth Civo::Firewall.remove(id: firewall_ID) puts "Removed firewall #{firewall_ID.colorize(:red)}" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |