Class: Nexpose::MultiTenantUser

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) ⇒ MultiTenantUser

Returns a new instance of MultiTenantUser.



75
76
77
78
79
# File 'lib/nexpose/multi_tenant_user.rb', line 75

def initialize(&block)
  instance_eval(&block) if block_given?

  @silo_access = Array(@silo_access)
end

Instance Attribute Details

#auth_source_idObject

Returns the value of attribute auth_source_id.



68
69
70
# File 'lib/nexpose/multi_tenant_user.rb', line 68

def auth_source_id
  @auth_source_id
end

#emailObject

Returns the value of attribute email.



69
70
71
# File 'lib/nexpose/multi_tenant_user.rb', line 69

def email
  @email
end

#enabledObject

Returns the value of attribute enabled.



72
73
74
# File 'lib/nexpose/multi_tenant_user.rb', line 72

def enabled
  @enabled
end

#full_nameObject

Returns the value of attribute full_name.



66
67
68
# File 'lib/nexpose/multi_tenant_user.rb', line 66

def full_name
  @full_name
end

#idObject

Returns the value of attribute id.



65
66
67
# File 'lib/nexpose/multi_tenant_user.rb', line 65

def id
  @id
end

#passwordObject

Returns the value of attribute password.



70
71
72
# File 'lib/nexpose/multi_tenant_user.rb', line 70

def password
  @password
end

#silo_accessObject

Returns the value of attribute silo_access.



73
74
75
# File 'lib/nexpose/multi_tenant_user.rb', line 73

def silo_access
  @silo_access
end

#superuserObject

Returns the value of attribute superuser.



71
72
73
# File 'lib/nexpose/multi_tenant_user.rb', line 71

def superuser
  @superuser
end

#user_nameObject

Returns the value of attribute user_name.



67
68
69
# File 'lib/nexpose/multi_tenant_user.rb', line 67

def user_name
  @user_name
end

Class Method Details

.load(connection, user_id) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'lib/nexpose/multi_tenant_user.rb', line 150

def self.load(connection, user_id)
  r = connection.execute(connection.make_xml('MultiTenantUserConfigRequest', { 'user-id' => user_id }), '1.2')

  if r.success
    r.res.elements.each('MultiTenantUserConfigResponse/MultiTenantUserConfig') do |config|
      return MultiTenantUser.parse(config)
    end
  end
  nil
end

.parse(xml) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/nexpose/multi_tenant_user.rb', line 136

def self.parse(xml)
  new do |user|
    user.id             = xml.attributes['id'].to_i
    user.full_name      = xml.attributes['full-name']
    user.user_name      = xml.attributes['user-name']
    user.email          = xml.attributes['email']
    user.superuser      = xml.attributes['superuser'].to_s.chomp.eql?('true')
    user.enabled        = xml.attributes['enabled'].to_s.chomp.eql?('true')
    user.auth_source_id = xml.attributes['authsrcid'].to_i
    user.silo_access    = []
    xml.elements.each('SiloAccesses/SiloAccess') { |access| user.silo_access << SiloAccess.parse(access) }
  end
end

Instance Method Details

#as_xmlObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/nexpose/multi_tenant_user.rb', line 113

def as_xml
  xml = REXML::Element.new('MultiTenantUserConfig')
  xml.add_attributes({ 'id'        => @id,
                       'full-name' => @full_name,
                       'user-name' => @user_name,
                       'authsrcid' => @auth_source_id,
                       'email'     => @email,
                       'password'  => @password,
                       'superuser' => @superuser,
                       'enabled'   => @enabled })
  siloaccesses = xml.add_element('SiloAccesses')
  @silo_access.each { |silo_access| siloaccesses.add_element(silo_access.as_xml) }
  xml
end

#create(connection) ⇒ String

Saves this silo user to a Nexpose console.

Parameters:

  • connection (Connection)

    Connection to console where this silo user will be saved.

Returns:

  • (String)

    User ID assigned to this configuration, if successful.



106
107
108
109
110
111
# File 'lib/nexpose/multi_tenant_user.rb', line 106

def create(connection)
  xml = connection.make_xml('MultiTenantUserCreateRequest')
  xml.add_element(as_xml)
  r = connection.execute(xml, '1.2')
  @id = r.attributes['user-id'] if r.success
end

#delete(connection) ⇒ Object



128
129
130
# File 'lib/nexpose/multi_tenant_user.rb', line 128

def delete(connection)
  connection.delete_silo_user(@id)
end

#save(connection) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/nexpose/multi_tenant_user.rb', line 81

def save(connection)
  if @id
    update(connection)
  else
    create(connection)
  end
end

#to_xmlObject



132
133
134
# File 'lib/nexpose/multi_tenant_user.rb', line 132

def to_xml
  as_xml.to_s
end

#update(connection) ⇒ String

Updates this silo user on a Nexpose console.

Parameters:

  • connection (Connection)

    Connection to console where this silo user will be saved.

Returns:

  • (String)

    User ID assigned to this configuration, if successful.



94
95
96
97
98
99
# File 'lib/nexpose/multi_tenant_user.rb', line 94

def update(connection)
  xml = connection.make_xml('MultiTenantUserUpdateRequest')
  xml.add_element(as_xml)
  r = connection.execute(xml, '1.2')
  @id = r.attributes['user-id'] if r.success
end