本文整理汇总了Python中mozci.utils.authentication.get_credentials函数的典型用法代码示例。如果您正苦于以下问题:Python get_credentials函数的具体用法?Python get_credentials怎么用?Python get_credentials使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_credentials函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)]
示例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
示例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
示例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
示例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
示例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)
示例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.")
示例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)
示例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
示例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
示例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)
示例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()
示例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
示例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()
示例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