Ejemplo n.º 1
0
def delete_account(name):
    scope_id = kapua_config.get_scope_id()
    try:
        api_client = kapua_config.get_api_client()
        api_instance = swagger_client.AccountsApi(api_client)

        account_id = get_account_id(name)
        api_instance.account_delete(scope_id, account_id)
        print(f'Deleted account id: {account_id}')

    except ApiException as e:
        print(f'Exception when calling API: {e}')
Ejemplo n.º 2
0
def create_account(name, organization, email):
    scope_id = kapua_config.get_scope_id()
    try:
        api_client = kapua_config.get_api_client()
        api_instance = swagger_client.AccountsApi(api_client)

        # AccountCreator | Provides the information for the new Account to be created
        body = swagger_client.AccountCreator(name=name,
                                             organization_name=organization,
                                             organization_email=email)

        # Create an Account
        api_response = api_instance.account_create(scope_id, body)
        pprint(api_response)
        print(f'Created account with id: {api_response.id}')

    except ApiException as e:
        print(f'Exception when calling API: {e}')
Ejemplo n.º 3
0
def get_account_id(name):
    scope_id = kapua_config.get_scope_id()
    try:
        api_client = kapua_config.get_api_client()
        api_instance = swagger_client.AccountsApi(api_client)
        api_response = api_instance.account_simple_query(scope_id,
                                                         name=name,
                                                         limit=1)

        if len(api_response.items) > 0:
            account_id = api_response.items[0].id
            print(f'Found account id: {account_id} for {name}')
            return account_id
        else:
            raise NameError(f'No account named {name} found')

    except ApiException as e:
        print(f'Exception when calling API: {e}')
Ejemplo n.º 4
0
#
# Kapua REST API test script
# Author: Lisa Ong, NUS/ISS
#

import time
from pprint import pprint

# Generated python client
import swagger_client
from swagger_client.rest import ApiException

import kapua_config

try:
    # Authenticate an API user
    api_client = kapua_config.get_api_client()
    pprint(api_client.configuration.api_key)

    users_api = swagger_client.UsersApi(api_client)
    body = swagger_client.UserQuery(
    )  # UserQuery | The UserQuery to use to filter count results

    # Count the number of users
    users_response = users_api.user_count(kapua_config.get_scope_id(), body)
    pprint(users_response)

except ApiException as e:
    print("Exception when calling API: %s\n" % e)