Module: CpMgmt
- Defined in:
- lib/cp_mgmt.rb,
lib/cp_mgmt/host.rb,
lib/cp_mgmt/network.rb,
lib/cp_mgmt/version.rb,
lib/cp_mgmt/access_rule.rb,
lib/cp_mgmt/access_layer.rb,
lib/cp_mgmt/configuration.rb
Defined Under Namespace
Classes: AccessLayer, AccessRule, Configuration, Error, Host, Network
Constant Summary collapse
- VERSION =
"1.0.4"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .access_layer ⇒ Object
- .access_rule ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .host ⇒ Object
-
.install_policy(package, gateways) ⇒ Object
installs provided policy.
-
.logged_in? ⇒ Boolean
Runs keepalive to stay logged in.
-
.login ⇒ Object
Uses the above client to login to the API and set the sid in the env.
- .network ⇒ Object
-
.publish ⇒ Object
publishes provided policy.
- .reset ⇒ Object
-
.show_object(uid) ⇒ Object
shows object by uid.
-
.transform_response(response) ⇒ Object
checks the requests response and produces a predicable map.
-
.verify_policy(package) ⇒ Object
verifies provided policy.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
14 15 16 |
# File 'lib/cp_mgmt.rb', line 14 def configuration @configuration end |
Class Method Details
.access_layer ⇒ Object
37 38 39 |
# File 'lib/cp_mgmt.rb', line 37 def self.access_layer @access_layer ||= AccessLayer.new end |
.access_rule ⇒ Object
41 42 43 |
# File 'lib/cp_mgmt.rb', line 41 def self.access_rule @access_rule ||= AccessRule.new end |
.configure {|configuration| ... } ⇒ Object
25 26 27 |
# File 'lib/cp_mgmt.rb', line 25 def self.configure yield(configuration) end |
.host ⇒ Object
29 30 31 |
# File 'lib/cp_mgmt.rb', line 29 def self.host @host ||= Host.new end |
.install_policy(package, gateways) ⇒ Object
installs provided policy
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# 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? ⇒ Boolean
Runs keepalive to stay logged in.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
Uses the above client to login to the API and set the sid in the env.
46 47 48 49 50 51 52 53 54 55 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/cp_mgmt.rb', line 33 def self.network @network ||= Network.new end |
.publish ⇒ Object
publishes provided policy
83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
21 22 23 |
# File 'lib/cp_mgmt.rb', line 21 def self.reset @configuration = Configuration.new end |
.show_object(uid) ⇒ Object
shows object by uid
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# 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) ⇒ Object
checks the requests response and produces a predicable map
74 75 76 77 78 79 80 |
# 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) ⇒ Object
verifies provided policy
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# 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 |