SuperUser.create - Python API

Creates a new super-user. Current user’s UST must belong to an already existing super-user.

API

self.sso.user.create_super_user

create_super_user(self, cid, data, current_ust, current_app, remote_addr)

Creates a new super-user.

Parameters:
  • cid (string) – Correlation ID used by audit log
  • data (string) –

    A dictionary of values to create a new user from. On output, the dictionary will be enriched with defaults assigned during the creation process.

    Keys accepted:

    Key Optional Default Notes
    username Must be unique among all users
    password Yes 192 bits If not given, a random string of 192 bits will be assigned
    password_must_change Yes False  
    display_name Yes Display name
    first_name Yes First name
    middle_name Yes Middle name
    last_name Yes Last name
    email Yes User’s email
    is_locked Yes Should the account be locked upon creation, i.e. logging in will not be possible
    sign_up_status Yes final User’s initial signup status, by default it is ‘final’ meaning the user is fully signed up
  • current_ust (string) – Current user’s UST
  • current_app (string) – Name of application the current user is issuing the call from
  • remote_addr (string) – User’s remote address
Return type:

None - the input ‘data’ dictionary is modified in place.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# Zato

from zato.server.service import Service

class MyService(Service):
    def handle(self):

        # Request metadata
        current_ust = 'gAAAAABalo6MX7z62Pyo416OFfDJ-4MuTMmSpIqAmvOXWckG...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # Creation data
        data = {
          'username': 'admin1',
          'password': 'Zp=VZMdZ2-!S6EJ5~sh5cfMiZ7--,aD3Nbya ^8j',
          'password_must_change': True,
          'display_name': 'My User'
        }

        # Create user
        self.sso.user.create_super_user(self.cid, data, current_ust, current_app, remote_addr)

        # The input dictionary will have been updated in place
        self.logger.info(data)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
INFO {
  'display_name': 'My User',
  'is_active': True,
  'is_internal': False,
  'is_super_user': True,
  'is_approved': True,
  'is_locked': False,
  'password_expiry': datetime.datetime(2020, 2, 28, 11, 33, 13, 359733),
  'password_must_change': True,
  'password_last_set': datetime.datetime(2018, 2, 28, 11, 33, 13, 359733),
  'sign_up_time': datetime.datetime(2018, 2, 28, 11, 33, 13, 359733),
  'sign_up_status': 'final',
  'username': 'admin1',
  'user_id': 'zusr5znzppxrwp8dp8qsp5g8khes86'
}