99 def self . instances
1010 require 'json'
1111
12- if db_ismaster
12+ Puppet . debug ( "MONGODB_USER self.instances" )
13+
14+ #if db_ismaster
1315 script = 'EJSON.stringify(db.system.users.find().toArray())'
1416 # A hack to prevent prefetching failures until admin user is created
1517 script = "try {#{ script } } catch (e) { if (e.message.match(/requires authentication/) || e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
1618
1719 out = mongo_eval ( script )
18- Puppet . debug ( "Result of out in self.instances: #{ out } " )
19- Puppet . debug ( "Type of out in self.instances: #{ out . class } " )
20- Puppet . debug ( "Methods of out in self.instances: #{ out . methods } " )
21- Puppet . debug ( "String of out in self.instances: #{ out . to_s } has type #{ out . to_s . class } " )
22- Puppet . debug ( "Json of out in self.instances: #{ out . to_json } has type #{ out . to_s . class } " )
20+ Puppet . debug ( "MONGODB_USER Result of out in self.instances: #{ out } " )
21+ Puppet . debug ( "MONGODB_USER Type of out in self.instances: #{ out . class } " )
22+ Puppet . debug ( "MONGODB_USER Methods of out in self.instances: #{ out . methods } " )
23+ Puppet . debug ( "MONGODB_USER String of out in self.instances: #{ out . to_s } has type #{ out . to_s . class } " )
24+ Puppet . debug ( "MONGODB_USER Json of out in self.instances: #{ out . to_json } has type #{ out . to_s . class } " )
2325
2426
27+ Puppet . debug ( "MONGODB_USER Just before return if auth_enabled and error requires authentication or not authorized on admin" )
2528 return [ ] if auth_enabled && ( out . include? ( 'requires authentication' ) || out . include? ( 'not authorized on admin' ) )
29+ Puppet . debug ( "MONGODB_USER after return []" )
2630
2731 users = JSON . parse out
28- Puppet . debug ( "Result of users in self.instances: #{ users } " )
29- Puppet . debug ( "Type of users in self.instances: #{ users . class } " )
32+ Puppet . debug ( "MONGODB_USER Result of users in self.instances: #{ users } " )
33+ Puppet . debug ( "MONGODB_USER Type of users in self.instances: #{ users . class } " )
3034
3135 users . map do |user |
3236 new ( name : user [ '_id' ] ,
@@ -37,14 +41,15 @@ def self.instances
3741 password_hash : user [ 'credentials' ] [ 'MONGODB-CR' ] ,
3842 scram_credentials : user [ 'credentials' ] [ 'SCRAM-SHA-1' ] )
3943 end
40- else
41- Puppet . warning 'User info is available only from master host'
42- [ ]
43- end
44+ # else
45+ # Puppet.warning 'User info is available only from master host'
46+ # []
47+ # end
4448 end
4549
4650 # Assign prefetched users based on username and database, not on id and name
4751 def self . prefetch ( resources )
52+ Puppet . debug ( "MONGODB_USER self.prefetch" )
4853 users = instances
4954 resources . each do |name , resource |
5055 provider = users . find { |user | user . username == resource [ :username ] && user . database == resource [ :database ] }
@@ -55,6 +60,7 @@ def self.prefetch(resources)
5560 mk_resource_methods
5661
5762 def create
63+ Puppet . debug ( "MONGODB_USER create" )
5864 Puppet . debug ( "In mongodb_user.create. Only works when on the primery node" )
5965 if db_ismaster
6066 password_hash = @resource [ :password_hash ]
@@ -100,14 +106,17 @@ def create
100106 end
101107
102108 def destroy
109+ Puppet . debug ( "MONGODB_USER destroy" )
103110 mongo_eval ( "db.dropUser(#{ @resource [ :username ] . to_json } )" , @resource [ :database ] )
104111 end
105112
106113 def exists?
114+ Puppet . debug ( "MONGODB_USER exists?" )
107115 !( @property_hash [ :ensure ] == :absent || @property_hash [ :ensure ] . nil? )
108116 end
109117
110118 def password_hash = ( _value )
119+ Puppet . debug ( "MONGODB_USER password_hash with #{ _value } " )
111120 if db_ismaster
112121 command = {
113122 updateUser : @resource [ :username ] ,
@@ -122,6 +131,7 @@ def password_hash=(_value)
122131 end
123132
124133 def password = ( value )
134+ Puppet . debug ( "MONGODB_USER password= with #{ value } " )
125135 if mongo_26?
126136 mongo_eval ( "db.changeUserPassword(#{ @resource [ :username ] . to_json } , #{ value . to_json } )" , @resource [ :database ] )
127137 else
@@ -140,6 +150,7 @@ def password=(value)
140150 end
141151
142152 def roles = ( roles )
153+ Puppet . debug ( "MONGODB_USER roles with #{ roles } " )
143154 if db_ismaster
144155 grant = to_roles ( roles , @resource [ :database ] ) - to_roles ( @property_hash [ :roles ] , @resource [ :database ] )
145156 mongo_eval ( "db.getSiblingDB(#{ @resource [ :database ] . to_json } ).grantRolesToUser(#{ @resource [ :username ] . to_json } , #{ role_hashes ( grant , @resource [ :database ] ) . to_json } )" ) unless grant . empty?
@@ -154,6 +165,7 @@ def roles=(roles)
154165 private
155166
156167 def self . from_roles ( roles , db )
168+ Puppet . debug ( "MONGODB_USER self.from_roles with #{ roles } and db is #{ db } " )
157169 roles . map do |entry |
158170 if entry [ 'db' ] . empty? || entry [ 'db' ] == db
159171 entry [ 'role' ]
@@ -164,6 +176,7 @@ def self.from_roles(roles, db)
164176 end
165177
166178 def to_roles ( roles , db )
179+ Puppet . debug ( "MONGODB_USER self.to_roles with #{ roles } and db is #{ db } " )
167180 roles . map do |entry |
168181 if entry . include? '@'
169182 entry
@@ -174,6 +187,7 @@ def to_roles(roles, db)
174187 end
175188
176189 def role_hashes ( roles , db )
190+ Puppet . debug ( "MONGODB_USER self.role_hashes with #{ roles } and db is #{ db } " )
177191 roles . sort . map do |entry |
178192 if entry . include? '@'
179193 {
0 commit comments