Class: Nexpose::SiloAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/multi_tenant_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SiloAccess

Returns a new instance of SiloAccess.



171
172
173
174
175
# File 'lib/nexpose/multi_tenant_user.rb', line 171

def initialize(&block)
  instance_eval &block if block_given?
  @sites = Array(@sites)
  @groups = Array(@groups)
end

Instance Attribute Details

#all_groupsObject

Returns the value of attribute all_groups.



163
164
165
# File 'lib/nexpose/multi_tenant_user.rb', line 163

def all_groups
  @all_groups
end

#all_sitesObject

Returns the value of attribute all_sites.



164
165
166
# File 'lib/nexpose/multi_tenant_user.rb', line 164

def all_sites
  @all_sites
end

#defaultObject

Returns the value of attribute default.



167
168
169
# File 'lib/nexpose/multi_tenant_user.rb', line 167

def default
  @default
end

#groupsObject

Returns the value of attribute groups.



169
170
171
# File 'lib/nexpose/multi_tenant_user.rb', line 169

def groups
  @groups
end

#role_nameObject

Returns the value of attribute role_name.



165
166
167
# File 'lib/nexpose/multi_tenant_user.rb', line 165

def role_name
  @role_name
end

#silo_idObject

Returns the value of attribute silo_id.



166
167
168
# File 'lib/nexpose/multi_tenant_user.rb', line 166

def silo_id
  @silo_id
end

#sitesObject

Returns the value of attribute sites.



168
169
170
# File 'lib/nexpose/multi_tenant_user.rb', line 168

def sites
  @sites
end

Class Method Details

.parse(xml) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/nexpose/multi_tenant_user.rb', line 206

def self.parse(xml)
  new do |access|
    access.all_groups = xml.attributes['all-groups'].to_s.chomp.eql?('true')
    access.all_sites = xml.attributes['all-sites'].to_s.chomp.eql?('true')
    access.role_name = xml.attributes['role-name']
    access.silo_id = xml.attributes['silo-id']
    access.default = xml.attributes['default-silo'].to_s.chomp.eql?('true')
    access.sites = []
    xml.elements.each('AllowedSites/AllowedSite') { |site| access.sites << site.attributes['id'].to_i }
    access.groups = []
    xml.elements.each('AllowedGroups/AllowedGroup') { |group| access.groups << group.attributes['id'].to_i }
  end
end

Instance Method Details

#as_xmlObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/nexpose/multi_tenant_user.rb', line 177

def as_xml
  xml = REXML::Element.new('SiloAccess')
  xml.add_attributes({'all-groups' => @all_groups,
                      'all-sites' => @all_sites,
                      'role-name' => @role_name,
                      'silo-id' => @silo_id,
                      'default-silo' => @default})

  unless @groups.empty?
    groups = xml.add_element('AllowedGroups')
    @groups.each do |group|
      groups.add_element('AllowedGroup', {'id' => group})
    end
  end

  unless @sites.empty?
    sites = xml.add_element('AllowedSites')
    @sites.each do |site|
      sites.add_element('AllowedSite', {'id' => site})
    end
  end

  xml
end

#to_xmlObject



202
203
204
# File 'lib/nexpose/multi_tenant_user.rb', line 202

def to_xml
  as_xml.to_s
end