def http_get()

in precommit/src/main/python/jenkins-admin.py [0:0]


def http_get(resource, ignore_error=False, username=None, password=None):
    """ get the contents of a URL """

    try:
        if username and password:
            response = requests.get(resource, auth=(username, password), timeout=10)
        else:
            response = requests.get(resource, timeout=10)
        response.raise_for_status()
    except requests.exceptions.HTTPError as http_err:
        errstr = str(http_err)
        print(
            f'%{resource} returns HTTP error %{response.status_code}: %{errstr}\n'
        )
        if ignore_error:
            return ''
        print('Aborting.')
        sys.exit(1)
    return response.text