Skip to content

Helper module

get_auth(credential_file, url)

Instantiate the JIRA object.

Parameters:

Name Type Description Default
credential_file str

the credentials file

required
url str

the REST URL

required

Returns:

Name Type Description
JIRA

The JIRA class instance

Source code in jira_python_utils/helper.py
def get_auth(credential_file: str, url: str):
    """Instantiate the JIRA object.

    Args:
        credential_file (str): the credentials file
        url: the REST URL

    Returns:
        JIRA: The JIRA class instance
    """
    username, password = get_credentials(credential_file)

    options = {
        'server': url,
        'verify': False
    }

    auth_jira = JIRA(options=options, basic_auth=(username, password))

    if auth_jira is None:
        error_console.print(f"Could not instantiate JIRA for url '{url}'")
        sys.exit(1)

    return auth_jira

get_auth_jira(credential_file, url)

Instantiate the JIRA object.

Parameters:

Name Type Description Default
credential_file str

the credentials file

required
url str

the REST URL

required

Returns:

Name Type Description
JIRA

The JIRA class instance

Source code in jira_python_utils/helper.py
def get_auth_jira(credential_file: str, url: str):
    """Instantiate the JIRA object.

    Args:
        credential_file (str): the credentials file
        url: the REST URL

    Returns:
        JIRA: The JIRA class instance
    """
    username, password = get_username_password(credential_file)

    options = {
        'server': url,
        'verify': False
    }

    logging.info(f"options: {options}")

    auth_jira = JIRA(
        options=options,
        basic_auth=(username, password)
    )

    if auth_jira is None:
        error_console.print(f"Could not instantiate JIRA for url '{url}'")
        sys.exit(1)

    auth = (username, password)

    return auth_jira, auth

get_credentials(credential_file)

Parse the credential file and retrieve the username and password.

Parameters:

Name Type Description Default
credential_file str

The credential file.

required

Returns:

Type Description
(str, str)

Tuple[str,str]: The username and password.

Source code in jira_python_utils/helper.py
def get_credentials(credential_file: str) -> (str, str):
    """Parse the credential file and retrieve the username and password.

    Args:
        credential_file (str): The credential file.

    Returns:
        Tuple[str,str]: The username and password.
    """
    with open(credential_file, 'r') as f:
        line = f.readline()
        line = line.strip()

        (username, password) = line.split(':')

        if username is None or username == "":
            raise Exception(f"username is empty in file '{credential_file}'")

        if password is None or password == "":
            raise Exception(f"password is empty in file '{credential_file}'")

        console.print("read username and password from credentials file")
    return (username, password)

get_rest_url(rest_url_file)

Get the REST URL from the file.

Parameters:

Name Type Description Default
rest_url_file str

The path to the file containing the REST URL.

required

Returns:

Name Type Description
str str

The REST URL.

Source code in jira_python_utils/helper.py
def get_rest_url(rest_url_file: str) -> str:
    """Get the REST URL from the file.

    Args:
        rest_url_file (str): The path to the file containing the REST URL.

    Returns:
        str: The REST URL.
    """
    with open(rest_url_file, 'r') as f:
        url = f.readline()
        url = url.strip()
        console.print(f"Retrieved the REST URL from file '{rest_url_file}'")
    return url

get_username_password(credential_file)

Parse the credential file and retrieve the username and password.

Source code in jira_python_utils/helper.py
def get_username_password(credential_file: str) -> Tuple[str,str]:
    """Parse the credential file and retrieve the username and password."""
    with open(credential_file, 'r') as f:
        line = f.readline()
        line = line.strip()
        (username, password) = line.split(':')
        console.print(f"read username and password from credentials file '{credential_file}'")
        return username, password