def updateuser(self): if self.name != False: if self.x_marketpayuser_id != False: # Variables definidas marketpay_key = "73a4d867-aeec-4e89-a295-64f14dc25ab9" marketpay_secret = "kFNm3CQU-ynHaM5g4OZ4MsSxOqmM85j4lgOVLkCgQYY=" marketpay_domain = "https://api-sandbox.marketpay.io" # Configuración CLiente token_url = 'https://api-sandbox.marketpay.io/v2.01/oauth/token' key = 'Basic %s' % base64.b64encode( b'73a4d867-aeec-4e89-a295-64f14dc25ab9:kFNm3CQU-ynHaM5g4OZ4MsSxOqmM85j4lgOVLkCgQYY=' ).decode('ascii') data = {'grant_type': 'client_credentials'} headers = { 'Authorization': key, 'Content-Type': 'application/x-www-form-urlencoded' } r = requests.post(token_url, data=data, headers=headers) rs = r.content.decode() response = json.loads(rs) token = response['access_token'] # Configuración default de Swagger config = swagger_client.Configuration() config.host = marketpay_domain config.access_token = token client = swagger_client.ApiClient(configuration=config) api_instance = swagger_client.Configuration.set_default(config) apiUser = swagger_client.UsersApi() address = swagger_client.Address( address_line1=self.street, address_line2=self.street2, city=self.city, postal_code=self.zip, country=self.x_codigopais_id, region=self.x_nombreprovincia_id) user_id = self.x_marketpayuser_id user_natural = swagger_client.UserNaturalPut(address=address) user_natural.email = self.email user_natural.first_name = self.name user_natural.occupation = self.function user_natural.tag = self.comment user_natural.country_of_residence = self.x_codigopais_id user_natural.nationality = self.x_codigopais_id try: api_response = apiUser.users_put_natural( user_id, user_natural=user_natural) except ApiException as e: print("Exception when calling UsersApi->users_put: %s\n" % e)
def delete_user(account_id, name): try: api_client = kapua_config.get_api_client() api_instance = swagger_client.UsersApi(api_client) user_id = get_user_id(account_id, name) api_client = kapua_config.get_api_client() api_instance.user_delete(account_id, user_id) print(f'Deleted user id: {user_id}') except ApiException as e: print(f'Exception when calling API: {e}')
def get_user(): global user if user is None: if os.path.exists(SAVED_USER): user = pickle.load(open(SAVED_USER, "rb")) if user.keycloak_config.client_mode in trueValues: logging.info("Command performed using client authorization.\n") else: logging.info("Command performed with user: {}\n".format(user.username)) users_api = swagger_client.UsersApi(user.get_api_client()) utils.checked_api_call(users_api, 'get_logged_user') # inits the user if it doesn't exist in pnc's db already else: user = UserConfig() return user
def main(): authority_url = 'https://login.windows.net/[Your Tenant]' client_id = '[Your client_id]' client_secret = '[Your secret]' context = adal.AuthenticationContext(authority_url, api_version=None) token = context.acquire_token_with_client_credentials( client_id, client_id, client_secret) api_client = ApiClient() #api_client.configuration.host = "[Set this if custom host and port is needed]" bearer_token = "Bearer " + token['accessToken'] api_client.set_default_header('Authorization', bearer_token) api_user = swagger_client.UsersApi(api_client) me = api_user.me_get() pprint(me)
def create_user(account_id, name): try: api_client = kapua_config.get_api_client() api_instance = swagger_client.UsersApi(api_client) body = swagger_client.UserCreator(name=name) api_response = api_instance.user_create(account_id, body) pprint(api_response) print( f'Created user {name} for account {account_id} with id: {api_response.id}' ) return api_response.id except ApiException as e: print(f'Exception when calling API: {e}')
def get_user_id(account_id, name): try: api_client = kapua_config.get_api_client() api_instance = swagger_client.UsersApi(api_client) api_response = api_instance.user_simple_query(account_id, name=name, limit=1) if len(api_response.items) > 0: user_id = api_response.items[0].id print(f'Found user id: {user_id} for {name}') return user_id else: raise NameError(f'No user named {name} found') except ApiException as e: print(f'Exception when calling API: {e}')
from __future__ import print_function import json import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = swagger_client.UsersApi(swagger_client.ApiClient()) long_url = "http://mail.ru" try: # shotter link, return short link api_instance.api_long_to_short_put(long_url=long_url) short_postfix = json.loads( api_instance.api_client.last_response.data)['short_link'].split( '/')[-1] api_instance.api_short_postfix_get(short_postfix=short_postfix) api_instance.api_statistic_short_postfix_get(short_postfix=short_postfix) print(api_instance.api_client.last_response.data) except ApiException as e: print("Exception when calling UsersApi->api_long_to_short_put: %s\n" % e)
def build_users_client(self, token): return swagger_client.UsersApi( swagger_client.ApiClient(self.build_config_with_token(token)))
logging.error( "No Keycloak token is present. Commands requiring authentication will fail." ) return swagger_client.ApiClient(self.pnc_config.url) def get_api_client(self): return self.apiclient if os.path.exists(SAVED_USER): user = pickle.load(open(SAVED_USER, "rb")) if user.keycloak_config.client_mode in trueValues: logging.info("Command performed using client authorization.\n") else: logging.info("Command performed with user: {}\n".format(user.username)) users_api = swagger_client.UsersApi(user.get_api_client()) utils.checked_api_call( users_api, 'get_logged_user' ) # inits the user if it doesn't exist in pnc's db already else: user = UserConfig() def save(): if user.token: pickle.dump(user, open(SAVED_USER, "wb"), protocol=pickle.HIGHEST_PROTOCOL) atexit.register(save)
# # 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)
def create(self, values): record = super(x_marketpayuser, self).create(values) # Variables definidas marketpay_key = "73a4d867-aeec-4e89-a295-64f14dc25ab9" marketpay_secret = "kFNm3CQU-ynHaM5g4OZ4MsSxOqmM85j4lgOVLkCgQYY=" marketpay_domain = "https://api-sandbox.marketpay.io" # Configuración CLiente token_url = 'https://api-sandbox.marketpay.io/v2.01/oauth/token' key = 'Basic %s' % base64.b64encode( b'73a4d867-aeec-4e89-a295-64f14dc25ab9:kFNm3CQU-ynHaM5g4OZ4MsSxOqmM85j4lgOVLkCgQYY=' ).decode('ascii') data = {'grant_type': 'client_credentials'} headers = { 'Authorization': key, 'Content-Type': 'application/x-www-form-urlencoded' } r = requests.post(token_url, data=data, headers=headers) rs = r.content.decode() response = json.loads(rs) token = response['access_token'] # Configuración default de Swagger config = swagger_client.Configuration() config.host = marketpay_domain config.access_token = token client = swagger_client.ApiClient(configuration=config) api_instance = swagger_client.Configuration.set_default(config) apiUser = swagger_client.UsersApi() ############# Función Create User and Wallet ##################### address = swagger_client.Address(address_line1=record['street'], address_line2=record['street2'], city=record['city'], postal_code=record['zip'], country=record['x_codigopais_id'], region=record['x_nombreprovincia_id']) user_natural = swagger_client.UserNaturalPost(address=address) user_natural.email = record['email'] user_natural.first_name = record['name'] user_natural.occupation = record['function'] user_natural.tag = record['comment'] user_natural.country_of_residence = record['x_codigopais_id'] user_natural.nationality = record['x_codigopais_id'] try: api_response = apiUser.users_post_natural( user_natural=user_natural) record['x_marketpayuser_id'] = api_response.id except ApiException as e: print("Exception when calling UsersApi->users_post: %s\n" % e) ###########Create wallet for the user######################## apiWallet = swagger_client.WalletsApi() ownersList = [api_response.id] wallet = swagger_client.WalletPost(owners=ownersList, description="wallet en EUR", currency='EUR') try: api_response = apiWallet.wallets_post(wallet=wallet) record['x_marketpaywallet_id'] = api_response.id except ApiException as e: print("Exception when calling WalletApi->Wallet_post: %s\n" % e) return record
def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.user_client = swagger_client.UsersApi(self.api_client) self.auth_client = swagger_client.AuthApi(self.api_client)