module CpMgmt

Constants

VERSION

Attributes

configuration[RW]

Public Class Methods

access_layer() click to toggle source
# File lib/cp_mgmt.rb, line 37
def self.access_layer
  @access_layer ||= AccessLayer.new
end
access_rule() click to toggle source
# File lib/cp_mgmt.rb, line 41
def self.access_rule
  @access_rule ||= AccessRule.new
end
configure() { |configuration| ... } click to toggle source
# File lib/cp_mgmt.rb, line 25
def self.configure
  yield(configuration)
end
host() click to toggle source
# File lib/cp_mgmt.rb, line 29
def self.host
  @host ||= Host.new
end
install_policy(package, gateways) click to toggle source

installs provided policy

# File lib/cp_mgmt.rb, line 97
def self.install_policy(package, gateways)
  client = self.configuration.client
  self.logged_in?

  body = {"policy-package": package, targets: gateways}
  response = client.post do |req|
    req.url '/web_api/install-policy'
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-chkp-sid'] = ENV.fetch("sid")
    req.body = body.to_json
  end
  self.transform_response(response)
end
logged_in?() click to toggle source

Runs keepalive to stay logged in.

# File lib/cp_mgmt.rb, line 58
def self.logged_in?
  client = self.configuration.client

  if ENV.has_key?("sid")
    response = client.post do |req|
      req.url '/web_api/keepalive'
      req.headers['Content-Type'] = 'application/json'
      req.headers['X-chkp-sid'] = ENV.fetch("sid")
      req.body = "{}"
    end
  else
    self.login
  end
end
login() click to toggle source

Uses the above client to login to the API and set the sid in the env.

# File lib/cp_mgmt.rb, line 46
def self.login
  client = self.configuration.client
  body = {user: self.configuration.mgmt_user, password: self.configuration.mgmt_pass, domain: self.configuration.mgmt_domain}
  response = client.post do |req|
    req.url '/web_api/login'
    req.headers['Content-Type'] = 'application/json'
    req.body = body.to_json
  end
  ENV.store('sid', JSON.parse(response.body)["sid"])
end
network() click to toggle source
# File lib/cp_mgmt.rb, line 33
def self.network
  @network ||= Network.new
end
publish() click to toggle source

publishes provided policy

# File lib/cp_mgmt.rb, line 83
def self.publish
  client = self.configuration.client
  self.logged_in?

  response = client.post do |req|
    req.url '/web_api/publish'
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-chkp-sid'] = ENV.fetch("sid")
    req.body = "{}"
  end
  self.transform_response(response)
end
reset() click to toggle source
# File lib/cp_mgmt.rb, line 21
def self.reset
  @configuration = Configuration.new
end
show_object(uid) click to toggle source

shows object by uid

# File lib/cp_mgmt.rb, line 127
def self.show_object(uid)
  client = self.configuration.client
  self.logged_in?

  body = {"uid": uid}
  response = client.post do |req|
    req.url '/web_api/show-object'
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-chkp-sid'] = ENV.fetch("sid")
    req.body = body.to_json
  end
  self.transform_response(response)
end
transform_response(response) click to toggle source

checks the requests response and produces a predicable map

# File lib/cp_mgmt.rb, line 74
def self.transform_response(response)
  if response.status == 200
    {status: :success, body: JSON.parse(response.body)}
  else
    {status: :error, body: JSON.parse(response.body)}
  end
end
verify_policy(package) click to toggle source

verifies provided policy

# File lib/cp_mgmt.rb, line 112
def self.verify_policy(package)
  client = self.configuration.client
  self.logged_in?

  body = {"policy-package": package}
  response = client.post do |req|
    req.url '/web_api/verify-policy'
    req.headers['Content-Type'] = 'application/json'
    req.headers['X-chkp-sid'] = ENV.fetch("sid")
    req.body = body.to_json
  end
  self.transform_response(response)
end