Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
def list_model_configuration(label=None, profile=DEFAULT_PROFILE):
    api, username = api_configuration(profile)
    api_instance = modelcatalog.ModelConfigurationApi(api)
    try:
        api_response = api_instance.modelconfigurations_get(username=username)
        return api_response
    except ApiException as e:
        raise e
Ejemplo n.º 3
0
def get_model_configuration(_id, profile=DEFAULT_PROFILE):
    api, username = api_configuration(profile)
    api_instance = modelcatalog.ModelConfigurationApi(api)
    try:
        api_response = api_instance.custom_modelconfigurations_id_get(
            _id, username=username)
        return api_response
    except ApiException as e:
        raise e
Ejemplo n.º 4
0
 def get_one(self, _id):
     api, username = get_api(profile=self.profile)
     api_instance = modelcatalog.ModelConfigurationApi(api)
     try:
         # List all Person entities
         api_response = api_instance.modelconfigurations_id_get(
             id=_id, username=username)
         return api_response
     except ApiException as e:
         raise e
Ejemplo n.º 5
0
 def get():
     # create an instance of the API class
     api, username = get_api()
     api_instance = modelcatalog.ModelConfigurationApi(api)
     try:
         # List all Person entities
         api_response = api_instance.modelconfigurations_get(
             username=username)
         return api_response
     except ApiException as e:
         raise e
Ejemplo n.º 6
0
    def get_by_label(label):
        api, username = get_api()
        api_instance = modelcatalog.ModelConfigurationApi(api_client=api)

        try:
            api_response = api_instance.modelconfigurations_get(
                username=username, label=label[0])
            return api_response
        except ApiException as e:
            logging.error(
                "Exception when calling ModelConfigurationConfigurationAPIs->modelconfigurations_get: %s\n"
                % e)
            raise e
Ejemplo n.º 7
0
 def post(self, request):
     api, username = get_api(profile=self.profile)
     api_instance = modelcatalog.ModelConfigurationApi(api)
     model_configuration = ModelConfiguration(
         **request) if isinstance(request, dict) else request
     try:
         api_response = api_instance.modelconfigurations_post(
             user=username, model_configuration=model_configuration)
         return api_response
     except ApiException as e:
         logging.error(
             "Exception when calling ModelConfigurationConfigurationSetupApi->modelconfigurationsetups_post: %s\n"
             % e)
         raise e
     return api_response