Class: CloudhouseGuardian::Policy
Instance Attribute Summary collapse
Attributes inherited from BaseObject
#appliance_api_key, #appliance_url, #insecure, #sec_key
Instance Method Summary
collapse
Methods inherited from BaseObject
#http_delete, #http_get, #http_post, #http_put, #make_headers
Constructor Details
#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ Policy
Returns a new instance of Policy.
7
8
9
10
11
12
13
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 7
def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
super(appliance_url, appliance_api_key, sec_key, insecure)
self.id = nil
self.name = nil
self.short_description = nil
self.description = nil
end
|
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6
7
8
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 6
def description
@description
end
|
#id ⇒ Object
Returns the value of attribute id.
3
4
5
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 3
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 4
def name
@name
end
|
#short_description ⇒ Object
Returns the value of attribute short_description.
5
6
7
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 5
def short_description
@short_description
end
|
Instance Method Details
#add_file_check(section, file_path, attr, check, expected, absent_pass = false) ⇒ Object
79
80
81
82
83
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 79
def add_file_check(section, file_path, attr, check, expected, absent_pass=false)
url = "/api/v2/policies/#{self.id}/add_file_check.json?section=#{section}&file_path=#{file_path}&attr=#{attr}&check=#{check}&expected=#{expected}&absent_pass=#{absent_pass}"
obj = http_post(url, nil)
return obj
end
|
#create ⇒ Object
49
50
51
52
53
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 49
def create
h = to_hash
out = http_post("/api/v2/policies.json", h)
from_hash(out)
end
|
#delete ⇒ Object
61
62
63
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 61
def delete
http_delete("/api/v2/policies/#{self.id}.json")
end
|
#from_hash(h) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 15
def from_hash(h)
self.id = h['id'] if h.include?('id')
self.name = h['name'] if h.include?('name')
self.short_description = h['short_description'] if h.include?('short_description')
self.description = h['description'] if h.include?('description')
end
|
#load ⇒ Object
34
35
36
37
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 34
def load
obj = http_get("/api/v2/policies/#{self.id}.json")
from_hash(obj)
end
|
#policy_versions ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 66
def policy_versions
obj = http_get("/api/v2/policies/#{self.id}/versions.json")
the_list = PolicyVersionList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
obj.each do |x|
elem = PolicyVersion.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
elem.id = x["id"] if x.include?("id")
elem.version = x["version"] if x.include?("version")
elem.tag = x["tag"] if x.include?("tag")
the_list << elem
end
return the_list
end
|
#save ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 40
def save
if self.id.to_i == 0
return create
else
return update
end
end
|
#to_hash ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 21
def to_hash
h = {}
h['id'] = self.id
h['name'] = self.name
h['short_description'] = self.short_description
h['description'] = self.description
return h
end
|
#to_json(options = nil) ⇒ Object
29
30
31
32
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 29
def to_json(options = nil)
h = to_hash
return h.to_json(options)
end
|
#update ⇒ Object
56
57
58
59
|
# File 'lib/cloudhouse_guardian/Policy.rb', line 56
def update
h = to_hash
http_put("/api/v2/policies/#{self.id}.json", h)
end
|