• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python authentication.get_credentials函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mozci.utils.authentication.get_credentials函数的典型用法代码示例。如果您正苦于以下问题:Python get_credentials函数的具体用法?Python get_credentials怎么用?Python get_credentials使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_credentials函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_all_jobs

    def get_all_jobs(self, repo_name, revision, use_cache=True):
        """
        Return a list with all jobs for that revision.

        If we can't query about this revision in buildapi_client we return an empty list.
        """
        if not use_cache:
            JOBS_CACHE[(repo_name, revision)] = \
                query_jobs_schedule(repo_name, revision, auth=get_credentials())

        if (repo_name, revision) not in JOBS_CACHE:
            JOBS_CACHE[(repo_name, revision)] = \
                query_jobs_schedule(repo_name, revision, auth=get_credentials())

        return JOBS_CACHE[(repo_name, revision)]
开发者ID:F3real,项目名称:mozilla_ci_tools,代码行数:15,代码来源:query_jobs.py


示例2: make_request

def make_request(repo_name, builder, revision, files=[], dry_run=False,
                 extra_properites=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_properites)

    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()
    )
    assert req.status_code != 401, req.reason
    content = req.json()
    LOG.debug("Status of the request: %s" %
              _jobs_api_url(content["request_id"]))

    return req
开发者ID:KWierso,项目名称:mozilla_ci_tools,代码行数:28,代码来源:buildapi.py


示例3: make_retrigger_request

def make_retrigger_request(repo_name, request_id, count=1, priority=0, dry_run=True):
    """
    Retrigger a request using buildapi self-serve. Returns a request.

    Buildapi documentation:
    POST  /self-serve/{branch}/request
    Rebuild `request_id`, which must be passed in as a POST parameter.
    `priority` and `count` are also accepted as optional
    parameters. `count` defaults to 1, and represents the number
    of times this build  will be rebuilt.
    """
    url = '{}/{}/request'.format(HOST_ROOT, repo_name)
    payload = {'request_id': request_id}

    if count != 1 or priority != 0:
        payload.update({'count': count,
                        'priority': priority})

    if dry_run:
        LOG.info('We would make a POST request to %s with the payload: %s' % (url, str(payload)))
        return None

    LOG.info("We're going to re-trigger an existing completed job with request_id: %s %i time(s)."
             % (request_id, count))
    req = requests.post(
        url,
        headers={'Accept': 'application/json'},
        data=payload,
        auth=get_credentials()
    )
    # TODO: add debug message with job_id URL.
    return req
开发者ID:go-bears,项目名称:mozilla_ci_tools,代码行数:32,代码来源:buildapi.py


示例4: valid_revision

def valid_revision(repo_name, revision):
    """
    There are revisions that won't exist in buildapi.
    This happens on pushes that do not have any jobs scheduled for them.
    """

    global VALID_CACHE
    if (repo_name, revision) in VALID_CACHE:
        return VALID_CACHE[(repo_name, revision)]

    LOG.debug("Determine if the revision is valid in buildapi.")
    url = "%s/%s/rev/%s?format=json" % (HOST_ROOT, repo_name, revision)
    req = requests.get(url, auth=get_credentials())
    if req.status_code == 401:
        LOG.critical("Your credentials were invalid")
        exit(1)

    content = json.loads(req.content)
    ret = True
    if isinstance(content, dict):
        failure_message = "Revision %s not found on branch %s" % (revision, repo_name)
        if content["msg"] == failure_message:
            LOG.warning(failure_message)
        ret = False

    VALID_CACHE[(repo_name, revision)] = ret
    return ret
开发者ID:glandium,项目名称:mozilla_ci_tools,代码行数:27,代码来源:buildapi.py


示例5: trigger_arbitrary_job

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
开发者ID:go-bears,项目名称:mozilla_ci_tools,代码行数:31,代码来源:buildapi.py


示例6: cancel

 def cancel(self, uuid, *args, **kwargs):
     return make_cancel_request(
         repo_name=kwargs['repo_name'],
         request_id=uuid,
         auth=get_credentials(),
         *args,
         **kwargs)
开发者ID:ka7,项目名称:mozilla_ci_tools,代码行数:7,代码来源:ci_manager.py


示例7: valid_credentials

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.")
开发者ID:go-bears,项目名称:mozilla_ci_tools,代码行数:7,代码来源:buildapi.py


示例8: schedule_arbitrary_job

 def schedule_arbitrary_job(self, repo_name, revision, uuid, *args, **kwargs):
     return trigger_arbitrary_job(repo_name=repo_name,
                                  builder=uuid,
                                  revision=revision,
                                  auth=get_credentials(),
                                  *args,
                                  **kwargs)
开发者ID:ka7,项目名称:mozilla_ci_tools,代码行数:7,代码来源:ci_manager.py


示例9: _all_urls_reachable

def _all_urls_reachable(urls):
    """Determine if the URLs are reachable."""
    for url in urls:
        url_tested = _public_url(url)
        LOG.debug("We are going to test if we can reach %s" % url_tested)
        req = requests.head(url_tested, auth=get_credentials())
        if not req.ok:
            LOG.warning("We can't reach %s for this reason %s" %
                        (url, req.reason))
            return False

    return True
开发者ID:nikkisquared,项目名称:mozilla_ci_tools,代码行数:12,代码来源:misc.py


示例10: get_jobs

def get_jobs(rev):
    """Get all jobs that ran in a revision."""
    url = "https://secure.pub.build.mozilla.org/buildapi/self-serve/try/rev/%s?format=json" % rev
    LOG.debug("About to fetch %s" % url)

    req = requests.get(url, auth=get_credentials())

    if req.status_code not in [200]:
        raise Exception

    data = req.json()
    jobs = []
    for build in data:
        jobs.append((build["buildername"], build.get("status")))
    return jobs
开发者ID:armenzg,项目名称:try_extender,代码行数:15,代码来源:revision_info.py


示例11: trigger

def trigger(builder, revision, files=[], dry_run=False, extra_properties=None):
    """Helper to trigger a job.

    Returns a request.
    """
    _add_builder_to_scheduling_manager(revision=revision, buildername=builder)

    repo_name = query_repo_name_from_buildername(builder)
    return trigger_arbitrary_job(repo_name=repo_name,
                                 builder=builder,
                                 revision=revision,
                                 auth=get_credentials(),
                                 files=files,
                                 dry_run=dry_run,
                                 extra_properties=extra_properties)
开发者ID:ka7,项目名称:mozilla_ci_tools,代码行数:15,代码来源:mozci.py


示例12: query_jobs_schedule

def query_jobs_schedule(repo_name, revision):
    """ Query Buildapi for jobs """
    repo_url = query_repo_url(repo_name)
    if not pushlog.valid_revision(repo_url, revision):
        raise BuildapiException

    url = "%s/%s/rev/%s?format=json" % (HOST_ROOT, repo_name, revision)
    LOG.debug("About to fetch %s" % url)
    req = requests.get(url, auth=get_credentials())

    # If the revision doesn't exist on buildapi, that means there are
    # no builapi jobs for this revision
    if req.status_code not in [200]:
        return []

    return req.json()
开发者ID:go-bears,项目名称:mozilla_ci_tools,代码行数:16,代码来源:buildapi.py


示例13: make_cancel_request

def make_cancel_request(repo_name, request_id, dry_run=True):
    """
    Cancel a request using buildapi self-serve. Returns a request.

    Buildapi documentation:
    DELETE /self-serve/{branch}/request/{request_id} Cancel the given request
    """
    url = '{}/{}/request/{}'.format(HOST_ROOT, repo_name, request_id)
    if dry_run:
        LOG.info('We would make a DELETE request to %s.' % url)
        return None

    LOG.info("We're going to cancel the job at %s" % url)
    req = requests.delete(url, auth=get_credentials())
    # TODO: add debug message with the canceled job_id URL. Find a way
    # to do that without doing an additional request.
    return req
开发者ID:go-bears,项目名称:mozilla_ci_tools,代码行数:17,代码来源:buildapi.py


示例14: query_jobs_schedule

def query_jobs_schedule(repo_name, revision):
    """
    Return a list with all jobs for that revision.

    If we can't query about this revision in buildapi we return an empty list.

    raises BuildapiException
    """
    if not valid_revision(repo_name, revision):
        raise BuildapiException

    url = "%s/%s/rev/%s?format=json" % (HOST_ROOT, repo_name, revision)
    LOG.debug("About to fetch %s" % url)
    req = requests.get(url, auth=get_credentials())
    assert req.status_code in [200], req.content

    return req.json()
开发者ID:KWierso,项目名称:mozilla_ci_tools,代码行数:17,代码来源:buildapi.py


示例15: valid_revision

def valid_revision(repo_name, revision):
    """
    There are revisions that won't exist in buildapi.
    This happens on pushes that do not have any jobs scheduled for them.
    """
    LOG.debug("Determine if the revision is valid in buildapi.")
    url = "%s/%s/rev/%s?format=json" % (HOST_ROOT, repo_name, revision)
    req = requests.get(url, auth=get_credentials())

    content = json.loads(req.content)
    if isinstance(content, dict):
        failure_message = "Revision %s not found on branch %s" % (revision, repo_name)
        if content["msg"] == failure_message:
            LOG.warning(failure_message)
            return False
    else:
        return True
开发者ID:chmanchester,项目名称:mozilla_ci_tools,代码行数:17,代码来源:buildapi.py


示例16: query_repositories

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
开发者ID:nikkisquared,项目名称:mozilla_ci_tools,代码行数:43,代码来源:buildapi.py


示例17: trigger

def trigger(builder, revision, files=None, dry_run=False, extra_properties=None):
    """Helper to trigger a job.

    Returns a request.
    """
    _add_builder_to_scheduling_manager(revision=revision, buildername=builder)

    repo_name = query_repo_name_from_buildername(builder)

    if is_downstream(builder) and not files:
        raise MozciError('We have requested to trigger a test job, however, we have not provided '
                         'which files to run against.')

    return trigger_arbitrary_job(repo_name=repo_name,
                                 builder=builder,
                                 revision=revision,
                                 auth=get_credentials(),
                                 files=files,
                                 dry_run=dry_run,
                                 extra_properties=extra_properties)
开发者ID:armenzg,项目名称:mozilla_ci_tools,代码行数:20,代码来源:mozci.py


示例18: query_repositories

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
开发者ID:whimboo,项目名称:mozilla_ci_tools,代码行数:41,代码来源:repositories.py


示例19: trigger

def trigger(builder, revision, files=[], dry_run=False, extra_properties=None):
    """Helper to trigger a job.

    Returns a request.
    """
    global SCHEDULING_MANAGER
    sch_mgr = SCHEDULING_MANAGER

    if revision not in sch_mgr:
        sch_mgr[revision] = []

    sch_mgr[revision].append(builder)

    repo_name = query_repo_name_from_buildername(builder)
    return trigger_arbitrary_job(repo_name=repo_name,
                                 builder=builder,
                                 revision=revision,
                                 auth=get_credentials(),
                                 files=files,
                                 dry_run=dry_run,
                                 extra_properties=extra_properties)
开发者ID:martiansideofthemoon,项目名称:mozilla_ci_tools,代码行数:21,代码来源:mozci.py


示例20: trigger_range

def trigger_range(buildername, revisions, times=1, dry_run=False,
                  files=None, extra_properties=None, trigger_build_if_missing=True):
    """Schedule the job named "buildername" ("times" times) in every revision on 'revisions'."""
    repo_name = query_repo_name_from_buildername(buildername)
    repo_url = repositories.query_repo_url(repo_name)

    if revisions != []:
        LOG.info("We want to have %s job(s) of %s on the following revisions: "
                 % (times, buildername))
        for r in revisions:
            LOG.info(" - %s" % r)

    for rev in revisions:
        LOG.info("")
        LOG.info("=== %s ===" % rev)
        if VALIDATE and not valid_revision(repo_url, rev):
            LOG.info("We can't trigger anything on pushes without a valid revision.")
            continue

        LOG.info("We want to have %s job(s) of %s" % (times, buildername))

        # 1) How many potentially completed jobs can we get for this buildername?
        matching_jobs = QUERY_SOURCE.get_matching_jobs(repo_name, rev, buildername)
        status_summary = StatusSummary(matching_jobs)

        # TODO: change this debug message when we have a less hardcoded _status_summary
        LOG.debug("We found %d pending/running jobs, %d successful jobs and "
                  "%d failed jobs" % (status_summary.pending_jobs + status_summary.running_jobs,
                                      status_summary.successful_jobs, status_summary.failed_jobs))

        if status_summary.potential_jobs >= times:
            LOG.info("We have %d job(s) for '%s' which is enough for the %d job(s) we want." %
                     (status_summary.potential_jobs, buildername, times))

        else:
            # 2) If we have less potential jobs than 'times' instances then
            #    we need to fill it in.
            LOG.info("We have found %d potential job(s) matching '%s' on %s. "
                     "We need to trigger more." % (status_summary.potential_jobs, buildername, rev))

            # If a job matching what we want already exists, we can
            # use the retrigger API in self-serve to retrigger that
            # instead of creating a new arbitrary job
            if len(matching_jobs) > 0 and files is None:
                request_id = QUERY_SOURCE.get_buildapi_request_id(repo_name, matching_jobs[0])
                make_retrigger_request(
                    repo_name=repo_name,
                    request_id=request_id,
                    auth=get_credentials(),
                    count=(times - status_summary.potential_jobs),
                    dry_run=dry_run)

            # If no matching job exists, we have to trigger a new arbitrary job
            else:
                list_of_requests = trigger_job(
                    revision=rev,
                    buildername=buildername,
                    times=(times - status_summary.potential_jobs),
                    dry_run=dry_run,
                    files=files,
                    extra_properties=extra_properties,
                    trigger_build_if_missing=trigger_build_if_missing)

                if list_of_requests and any(req.status_code != 202 for req in list_of_requests):
                    LOG.warning("Not all requests succeeded.")
开发者ID:martiansideofthemoon,项目名称:mozilla_ci_tools,代码行数:65,代码来源:mozci.py



注:本文中的mozci.utils.authentication.get_credentials函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mozcrash.check_for_crashes函数代码示例发布时间:2022-05-27
下一篇:
Python util.OrderedDefaultDict类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap