nexpose 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99af3c0c74693a9df896c50271778eb81ba30347
4
- data.tar.gz: 6545d6a48af4804641464b9664e66b4ccd9c4874
3
+ metadata.gz: 53818a10219a24c3d90a3fb09b2f658936aedd0b
4
+ data.tar.gz: 1b9a61cfb7ee75f878f9969d1472bba737e8499c
5
5
  SHA512:
6
- metadata.gz: 0604a979b91e03b8d213fe29608a193228b633e679916480996b8e92d2cb1aeacaccd685c84a4b4d0380c9e0c796571827e48884807adadea521fa21ac7b8892
7
- data.tar.gz: 07bd389940f0ecf8d94442a5c388e79db2f3259c3f92c1d60c648cb2a6d2a398686b6a325c9b8eb2867909fe6cd4966215f6b9160a85be0d26d1f4b16c87ceb5
6
+ metadata.gz: f6fd0316810c84f88463f7db042ef87934cfefa0547fe9df7d8530d9b2d45d579452b22305b16850ae0ea1fcf13d5a5ea6dd45422a1c78a351955fa4c769b880
7
+ data.tar.gz: 5e7422dfe20cdc0066e47e9b0ba1638fa8d6c0269a85df03d50b38fe1f6b5aef1c45ac50f8d932aeeb95b3a0d5219646edd1de01332210f31d793abc6448f76f
@@ -118,7 +118,7 @@ module Nexpose
118
118
  GLOBAL_ADMINISTRATOR = 'global-admin'
119
119
  ASSET_OWNER = 'system-admin'
120
120
  SECURITY_MANAGER = 'security-manager'
121
- SITE_ADMINISTRATOR = 'site-admin'
121
+ SITE_OWNER = 'site-admin'
122
122
  USER = 'user'
123
123
 
124
124
  # Array of all privileges which are enabled for this role.
@@ -1,15 +1,49 @@
1
1
  module Nexpose
2
2
 
3
+ module NexposeAPI
4
+ include XMLUtils
5
+
6
+ # Retrieve a list of all users configured on this console.
7
+ #
8
+ # @return [Array[UserSummary]] Array of users.
9
+ #
10
+ def users
11
+ r = execute(make_xml('UserListingRequest'))
12
+ arr = []
13
+ if r.success
14
+ r.res.elements.each('UserListingResponse/UserSummary') do |summary|
15
+ arr << UserSummary.parse(summary)
16
+ end
17
+ end
18
+ arr
19
+ end
20
+
21
+ # Retrieve the User ID based upon the user's login name.
22
+ def get_user_id(user_name)
23
+ users.find { |user| user.name.eql? user_name }
24
+ end
25
+
26
+ # Delete a user from the Nexpose console.
27
+ #
28
+ # @param [Fixnum] user_id Unique ID for the user to delete.
29
+ # @return [Boolean] Whether or not the user deletion succeeded.
30
+ #
31
+ def delete_user(user_id)
32
+ response = execute(make_xml('UserDeleteRequest', { 'id' => user_id }))
33
+ response.success
34
+ end
35
+ end
36
+
3
37
  # Summary only returned by API when issuing a listing request.
4
38
  class UserSummary
5
- attr_reader :id, :auth_source, :auth_module, :user_name, :full_name, :email
39
+ attr_reader :id, :auth_source, :auth_module, :name, :full_name, :email
6
40
  attr_reader :is_admin, :is_disabled, :is_locked, :site_count, :group_count
7
41
 
8
- def initialize(id, auth_source, auth_module, user_name, full_name, email, is_admin, is_disabled, is_locked, site_count, group_count)
42
+ def initialize(id, auth_source, auth_module, name, full_name, email, is_admin, is_disabled, is_locked, site_count, group_count)
9
43
  @id = id
10
44
  @auth_source = auth_source
11
45
  @auth_module = auth_module
12
- @user_name = user_name
46
+ @name = name
13
47
  @full_name = full_name
14
48
  @email = email
15
49
  @is_admin = is_admin
@@ -19,52 +53,19 @@ module Nexpose
19
53
  @group_count = group_count
20
54
  end
21
55
 
22
- def to_s
23
- out = "#{@user_name} (#{@full_name}) [ID: #{@id}]"
24
- out << " e-mail: #{@email}" unless @email.empty?
25
- out << ' Administrator' if @is_admin
26
- out << ' Disabled' if @is_disabled
27
- out << ' Locked' if @is_locked
28
- out << ", sites: #{@site_count}"
29
- out << ", groups: #{@group_count}"
30
- end
31
-
32
56
  # Provide a list of user accounts and information about those accounts.
33
- def self.listing(connection)
34
- xml = '<UserListingRequest session-id="' + connection.session_id + '" />'
35
- r = connection.execute(xml, '1.1')
36
- if r.success
37
- res = []
38
- r.res.elements.each('UserListingResponse/UserSummary') do |summary|
39
- res << UserSummary.new(
40
- summary.attributes['id'].to_i,
41
- summary.attributes['authSource'],
42
- summary.attributes['authModule'],
43
- summary.attributes['userName'],
44
- summary.attributes['fullName'],
45
- summary.attributes['email'],
46
- summary.attributes['administrator'].to_s.chomp.eql?('1'),
47
- summary.attributes['disabled'].to_s.chomp.eql?('1'),
48
- summary.attributes['locked'].to_s.chomp.eql?('1'),
49
- summary.attributes['siteCount'].to_i,
50
- summary.attributes['groupCount'].to_i)
51
- end
52
- res
53
- else
54
- false
55
- end
56
- end
57
-
58
- # Retrieve the User ID based upon the user's login name.
59
- def self.get_user_id(connection, user_name)
60
- xml = '<UserListingRequest session-id="' + connection.session_id + '" />'
61
- r = connection.execute(xml, '1.1')
62
- if r.success
63
- r.res.elements.each('UserListingResponse/UserSummary') do |user|
64
- return user.attributes['id'] if user_name.eql? user.attributes['userName']
65
- end
66
- end
67
- return -1
57
+ def self.parse(summary)
58
+ new(summary.attributes['id'].to_i,
59
+ summary.attributes['authSource'],
60
+ summary.attributes['authModule'],
61
+ summary.attributes['userName'],
62
+ summary.attributes['fullName'],
63
+ summary.attributes['email'],
64
+ summary.attributes['administrator'].to_s.chomp.eql?('1'),
65
+ summary.attributes['disabled'].to_s.chomp.eql?('1'),
66
+ summary.attributes['locked'].to_s.chomp.eql?('1'),
67
+ summary.attributes['siteCount'].to_i,
68
+ summary.attributes['groupCount'].to_i)
68
69
  end
69
70
  end
70
71
 
@@ -103,15 +104,6 @@ module Nexpose
103
104
  @groups = []
104
105
  end
105
106
 
106
- def to_s
107
- out = "#{@name} (#{@full_name}) [ID: #{@id}, Role: #{@role_name}]"
108
- out << ' Disabled' unless @enabled
109
- out << ' All-Sites' if @all_sites
110
- out << ' All-Groups' if @all_groups
111
- out << " e-mail: #{@email}" unless @email.nil? || @email.empty?
112
- out
113
- end
114
-
115
107
  def to_xml
116
108
  xml = '<UserConfig'
117
109
  xml << %Q{ id="#{@id}"}
@@ -177,22 +169,9 @@ module Nexpose
177
169
  end
178
170
  end
179
171
 
180
- # Delete a user account.
181
- def self.delete(connection, user_id)
182
- xml = '<UserDeleteRequest session-id="' + connection.session_id + '"'
183
- xml << %Q{ id="#{user_id}"}
184
- xml << ' />'
185
- r = connection.execute(xml, '1.1')
186
- if r.success
187
- r.res.elements.each('UserConfigResponse/UserConfig') do |config|
188
- '1'.eql? config.attributes['id']
189
- end
190
- end
191
- end
192
-
193
172
  # Delete the user account associated with this object.
194
173
  def delete(connection)
195
- User.delete(connection, @id)
174
+ connection.delete_user(@id)
196
175
  end
197
176
  end
198
177
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexpose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - HD Moore
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-22 00:00:00.000000000 Z
13
+ date: 2013-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: librex