コード例 #1
0
ファイル: buildapi.py プロジェクト: go-bears/mozilla_ci_tools
def valid_credentials():
    """Verify that the user's credentials are valid."""
    LOG.debug("Determine if the user's credentials are valid.")
    req = requests.get(HOST_ROOT, auth=get_credentials())
    if req.status_code == 401:
        remove_credentials()
        raise AuthenticationError("Your credentials were invalid. Please try again.")
コード例 #2
0
ファイル: buildapi.py プロジェクト: go-bears/mozilla_ci_tools
def trigger_arbitrary_job(repo_name, builder, revision, files=[], dry_run=False,
                          extra_properties=None):
    """
    Request buildapi to trigger a job for us.

    We return the request or None if dry_run is True.
    """
    url = _builders_api_url(repo_name, builder, revision)
    payload = _payload(repo_name, revision, files, extra_properties)

    if dry_run:
        LOG.info("Dry-run: We were going to request a job for '%s'" % builder)
        LOG.info("         with this payload: %s" % str(payload))
        return None

    # NOTE: A good response returns json with request_id as one of the keys
    req = requests.post(
        url,
        headers={'Accept': 'application/json'},
        data=payload,
        auth=get_credentials()
    )
    if req.status_code == 401:
        remove_credentials()
        raise AuthenticationError("Your credentials were invalid. Please try again.")

    content = req.json()
    LOG.debug("Status of the request: %s" %
              _jobs_api_url(content["request_id"]))

    return req
コード例 #3
0
def valid_credentials():
    """
    Verify that the user's credentials are valid.

    Raises an AuthenticationError if the credentials are invalid.
    """
    LOG.debug("Determine if the user's credentials are valid.")
    req = requests.get(HOST_ROOT, auth=get_credentials())
    if req.status_code == 401:
        remove_credentials()
        raise AuthenticationError(
            "Your credentials were invalid. Please try again.")
コード例 #4
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        url = "%s/branches?format=json" % HOST_ROOT
        LOG.debug("About to fetch %s" % url)
        req = requests.get(url, auth=get_credentials())
        if req.status_code == 401:
            remove_credentials()
            raise AuthenticationError(
                "Your credentials were invalid. Please try again.")

        REPOSITORIES = req.json()
        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES
コード例 #5
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        try:
            REPOSITORIES = make_query_repositories_request(
                auth=get_credentials(), dry_run=False)
        except BuildapiAuthError:
            remove_credentials()
            raise AuthenticationError(
                "Your credentials were invalid. Please try again.")

        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES
コード例 #6
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        url = "%s/branches?format=json" % HOST_ROOT
        LOG.debug("About to fetch %s" % url)
        req = requests.get(url, auth=get_credentials())
        if req.status_code == 401:
            remove_credentials()
            raise AuthenticationError("Your credentials were invalid. Please try again.")

        REPOSITORIES = req.json()
        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES
コード例 #7
0
def trigger_arbitrary_job(repo_name,
                          builder,
                          revision,
                          files=[],
                          dry_run=False,
                          extra_properties=None):
    """
    Request buildapi to trigger a job for us.

    We return the request or None if dry_run is True.

    Raises AuthenticationError if credentials are invalid.
    """
    url = _builders_api_url(repo_name, builder, revision)
    payload = _payload(repo_name, revision, files, extra_properties)

    if dry_run:
        LOG.info("Dry-run: We were going to request a job for '%s'" % builder)
        LOG.info("         with this payload: %s" % str(payload))
        return None

    # NOTE: A good response returns json with request_id as one of the keys
    req = requests.post(url,
                        headers={'Accept': 'application/json'},
                        data=payload,
                        auth=get_credentials())
    if req.status_code == 401:
        remove_credentials()
        raise AuthenticationError(
            "Your credentials were invalid. Please try again.")

    try:
        content = req.json()
        LOG.debug("Status of the request: %s" %
                  _jobs_api_url(content["request_id"]))
        return req

    except ValueError:
        LOG.warning("We did not get info from %s (status code: %s)" %
                    (url, req.status_code))
        return None
コード例 #8
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        try:
            REPOSITORIES = make_query_repositories_request(auth=get_credentials(), dry_run=False)
        except BuildapiAuthError:
            remove_credentials()
            raise AuthenticationError("Your credentials were invalid. Please try again.")

        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES