Пример #1
0
def acquire(config, device_id):
    r = requests.post(config.baseURL + '/device/' + device_id + '/acquire',
                      headers=config.headers)
    if r.status_code == 200:
        return http.handle_response(r.json())

    print("\nError: ", r.json()['error'])
Пример #2
0
def list_user(config):
    r = requests.get(config.baseURL + '/admin/user', headers=config.headers)

    if r.status_code == 200:
        return http.handle_response(r.json())

    print(r.json())

    print("\nError: ", r.json()['error'])
Пример #3
0
def add_device(config):
    hostname = input('Enter the device\'s hostname: ')
    port = input('Enter the device\'s port: ')

    params = {'hostname': hostname, 'port': port}
    r = requests.post(config.baseURL + '/admin/device',
                      params=params,
                      headers=config.headers)

    if r.status_code == 201:
        return http.handle_response(r.json())

    print("\nError: ", r.json()['error'])
Пример #4
0
def update_user_exp(config, user_id):
    exp = input('Enter a new expiration [YYYY-MM-DD]: ')
    params = {'expiration': exp}

    r = requests.post(config.baseURL + '/admin/user/' + user_id +
                      '/expiration',
                      params=params,
                      headers=config.headers)

    if r.status_code == 200:
        return http.handle_response(r.json())

    print("\nError: ", r.json()['error'])
Пример #5
0
def create_user(config):
    user = {}
    user['username'] = input('Enter a username for the new user: '******'email'] = input('Enter an email for the new user: '******'password'] = getpass.getpass('Enter a password for the new user: '******'Do you want this user to be an administrator? [y/N] ')
    user[
        'role'] = 'administrator' if answer == 'y' or answer == 'Y' else 'user'
    answer = input(
        'Do you want to set an expiration date for the user? [Y/n] ')
    if answer not in ['n', 'N']:
        user['expiration'] = input('Enter an expiration date [YYYY-MM-DD]: ')

    r = requests.post(config.baseURL + '/admin/user',
                      headers=config.headers,
                      json=user)

    if r.status_code == 201:
        return http.handle_response(r.json())

    print("\nError: ", r.json()['error'])