Ejemplo n.º 1
0
def do_retrieve_artifact(args, config):
    artifact_id = args.artifact_id

    url = config.get('DEFAULT', 'url')
  
    client = ArtifactBatch(base_url=url)

    result = client.retrieve_artifact(artifact_id).decode()

    if result is not None:
        output = ''
        result = filter_output(result)
        output = ret_msg("success","OK","ArtifactRecord",result)
        print(output)
    else:
        raise ArtifactException("Artifact not found {}".format(artifact_id))
Ejemplo n.º 2
0
def do_retrieve_artifact(args, config):
    """
    Retrieves the state associating with the UUID in the
    Transaction Family : Artifact
    
    Args:
        args (ArgumentParser):
            ArgumentParser object containing required parameters
        config (ConfigParser): ConfigParser which contains the default url
        
    Returns:
        type: str
        String representing JSON object which allows the client to know that
        the call was either a success or a failure.
    
    Raises:
        ArtifactException:
            * If failed to retrieve the uuid
    
    """
    all_flag = args.all
    range_flag = args.range

    artifact_id = args.artifact_id

    if range_flag != None:
        all_flag = True

    b_url = config.get("DEFAULT", "url")
    client = ArtifactBatch(base_url=b_url)
    data = client.retrieve_artifact(artifact_id, all_flag, range_flag)

    if data is not None:

        if all_flag == False:
            output = ret_msg("success", "OK", "ArtifactRecord", data.decode())
        else:
            output = ret_msg("success", "OK", "ArtifactRecord", data)

        print(output)
    else:
        raise ArtifactException("Artifact not found {}".format(artifact_id))
Ejemplo n.º 3
0
def api_do_retrieve_artifact(artifact_id,
                             config,
                             all_flag=False,
                             range_flag=None):
    """
    API version of "do_retrieve_artifact" function.
    """
    if range_flag != None:
        all_flag = True

    b_url = config.get("DEFAULT", "url")
    client = ArtifactBatch(base_url=b_url)
    data = client.retrieve_artifact(artifact_id, all_flag, range_flag)

    if data is not None:

        if all_flag == False:
            output = ret_msg("success", "OK", "ArtifactRecord", data.decode())
        else:
            if range_flag == None:
                output = ret_msg("success", "OK", "ArtifactRecord", data)
            else:
                if len(data) != 0:
                    output = ret_msg("success", "OK", "ArtifactRecord",
                                     json.dumps(data[0]))
                else:
                    output = ret_msg("success", "OK", "ArtifactRecord", "{}")

        return output
    else:
        return ret_msg(
                    "failed",
                    "ArtifactException : UUID {} does not exist." \
                    .format(artifact_id),
                    "ArtifactRecord", "{}"
                )