def push(is_setup, yaml_file_path, profile): credentials_file = Path( os.getenv("MINT_API_CREDENTIALS_FILE", __DEFAULT_MINT_API_CREDENTIALS_FILE__) ).expanduser() credentials = configparser.ConfigParser() credentials.optionxform = str if credentials_file.exists(): credentials.read(credentials_file) username = credentials[profile]["api_username"] password = credentials[profile]["api_password"] try: transformed_json = _transform_data.create_json(yaml_file_path) except FileNotFoundError: logging.error("Could not fine \"" + yaml_file_path + "\" please for typos in path name") quit() # Login the user into the API to get the access token api_instance = modelcatalog.DefaultApi() configuration = modelcatalog.Configuration() try: api_response = api_instance.user_login_get(username, password) pprint(api_response) data = json.dumps(ast.literal_eval(api_response)) access_token = json.loads(data)["access_token"] configuration.access_token=access_token except ApiException as e: logging.error("Exception when calling DefaultApi->user_login_get: %s\n" % e) quit() if is_setup == "false": api_instance = modelcatalog.ModelConfigurationApi(modelcatalog.ApiClient(configuration)) try: api_response = api_instance.modelconfigurations_post(username, model_configuration=transformed_json) logging.info(api_response) except ApiException as e: logging.error("Exception when calling ModelConfigurationApi->modelconfigurations_post: %s\n" % e) quit() else: api_instance = modelcatalog.ModelConfigurationSetupApi(modelcatalog.ApiClient(configuration)) try: api_response = api_instance.modelconfigurationsetups_post(username, model_configuration_setup=transformed_json) logging.info(api_response) except ApiException as e: logging.error("Exception when calling ModelConfigurationSetupApi->modelconfigurationsetups_post: %s\n" % e) quit()
def login(username, password): api_instance = modelcatalog.DefaultApi() configuration = modelcatalog.Configuration() try: api_response = api_instance.user_login_get(username, password) access_token = api_response["access_token"] configuration.access_token = access_token except ApiException as e: logging.error( "Exception when calling DefaultApi->user_login_get: %s\n" % e) quit() return configuration
def _api_configuration(username, password, server=None): configuration = modelcatalog.Configuration() if server is None: configuration.host = server api_instance = modelcatalog.DefaultApi(ApiClient(configuration=configuration)) try: api_response = api_instance.user_login_get(username, password) access_token = api_response["access_token"] configuration.access_token = access_token except ApiException as e: logging.error("Exception when calling DefaultApi->user_login_get: %s\n" % e) quit() return configuration
def _api_configuration(username, password, server=None): configuration = modelcatalog.Configuration() if server: configuration.host = server api_instance = modelcatalog.DefaultApi( ApiClient(configuration=configuration)) user = User(username=username, password=password) try: api_response = api_instance.user_login_post(user=user) access_token = ast.literal_eval(api_response)['access_token'] configuration.access_token = access_token except ApiException as e: logging.error( "Exception when calling DefaultApi->user_login_get: %s\n" % e) quit() return configuration