Class: Bim::Action::Fw

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/bim/action/fw.rb

Overview

Fw class uses by Bim::Subcommands::Fw

Constant Summary collapse

FW_PATH =
'/mgmt/tm/security/firewall/policy'.freeze
FW_URI =
URI.join(Bim::BASE_URL, Bim::Action::Fw::FW_PATH)
DETAIL_CONF =
{
  name: 'firewall_policy',
  items: false,
  attrs: %w[name fullPath],
  under_key: 'rulesReference',
  under_layer: {
    name: 'rules_reference',
    items: true,
    attrs: %w[name description ipProtocol ruleList],
    under_key: 'ruleListReference',
    under_layer: {
      name: 'rule_list_reference',
      items: false,
      attrs: %w[name fullPath],
      under_key: 'rulesReference',
      under_layer: {
        name: 'rules_reference',
        items: true,
        attrs: %w[name description destination source]
      }
    }
  }
}.freeze

Constants included from Util

Util::VS_PATH

Class Method Summary collapse

Class Method Details

.detail(name) ⇒ Object



41
42
43
44
# File 'lib/bim/action/fw.rb', line 41

def detail(name)
  start_uri = URI(sub_localhost(specify_link_by_name(FW_URI, name)))
  detail_depth(start_uri, DETAIL_CONF).to_json
end

.detail_depth(uri, conf) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/bim/action/fw.rb', line 46

def detail_depth(uri, conf)
  datas = JSON.parse(get_body(uri))
  if conf[:items]
    datas['items'].map do |data|
      detail_proc.call(data, conf, true)
    end
  else
    detail_proc.call(datas, conf)
  end
end

.detail_procObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bim/action/fw.rb', line 57

def detail_proc
  proc do |data, conf, map = false|
    d = {}
    conf[:attrs].each { |attr| d[attr] = data[attr] }

    (map ? (next d) : (return d)) unless data.key?(conf[:under_key])
    next_uri = URI(sub_localhost(data[conf[:under_key]]['link']))
    d[conf[:under_key]] = detail_depth(next_uri, conf[:under_layer])
    d
  end
end

.lsObject



35
36
37
38
39
# File 'lib/bim/action/fw.rb', line 35

def ls
  map(FW_URI) do |item|
    { 'item' => item['name'], 'fullPath' => item['fullPath'] }
  end
end