sentinelUsersSetup.js.j2 812 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// {{ ansible_managed }}

// NOTE: must be kept in sync with User in the source code

var addUserIfNotExist = function(user) {
  var query = Object.assign({}, user);
  delete query.creationTimeUtc;
  delete query.hashedPassword;
  var existingUserCount = db.users.find(query).count();
  if (existingUserCount === 0) {
    db.users.insert(user);
    print("user added: ".concat(user.id));
  }
}

var users = [
17
{% for user in sentinel_api_users %}
18
19
20
  {
    id: "{{ user.id }}",
    email: "{{ user.email }}",
21
    hashedPassword: "{{ user.password|hashpw }}",
22
23
24
25
26
27
28
29
30
    activeKey: "{{ user.active_key }}",
    verified: {{ user.verified|to_nice_json }},
    isAdmin: {{ user.is_admin|to_nice_json }},
    creationTimeUtc: new Date()
  }{% if not loop.last %},{% endif %}
{% endfor %}
];

users.forEach(addUserIfNotExist);