signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def dumpJson(obj, **kwargs): | def handleDateAndBinaryForJs(x):<EOL><INDENT>if six.PY3 and isinstance(x, six.binary_type):<EOL><INDENT>x = x.decode()<EOL><DEDENT>if isinstance(x, datetime.datetime) or isinstance(x, datetime.date):<EOL><INDENT>return stringDate(x)<EOL><DEDENT>else:<EOL><INDENT>return x<EOL><DEDENT><DEDENT>d = json.dumps(obj, separators=('<STR_LIT:U+002C>', '<STR_LIT::>'), default=handleDateAndBinaryForJs, **kwargs)<EOL>assert '<STR_LIT:\n>' not in d<EOL>return d<EOL> | Match JS's JSON.stringify. When using the default seperators,
base64 encoding JSON results in \n sequences in the output. Hawk
barfs in your face if you have that in the text | f15765:m4 |
def makeB64UrlSafe(b64str): | if isinstance(b64str, six.text_type):<EOL><INDENT>b64str = b64str.encode()<EOL><DEDENT>return b64str.replace(b'<STR_LIT:+>', b'<STR_LIT:->').replace(b'<STR_LIT:/>', b'<STR_LIT:_>')<EOL> | Make a base64 string URL Safe | f15765:m6 |
def makeB64UrlUnsafe(b64str): | if isinstance(b64str, six.text_type):<EOL><INDENT>b64str = b64str.encode()<EOL><DEDENT>return b64str.replace(b'<STR_LIT:->', b'<STR_LIT:+>').replace(b'<STR_LIT:_>', b'<STR_LIT:/>')<EOL> | Make a base64 string URL Unsafe | f15765:m7 |
def encodeStringForB64Header(s): | if isinstance(s, six.text_type):<EOL><INDENT>s = s.encode()<EOL><DEDENT>return base64.encodestring(s).strip().replace(b'<STR_LIT:\n>', b'<STR_LIT>')<EOL> | HTTP Headers can't have new lines in them, let's | f15765:m8 |
def slugId(): | return slugid.nice()<EOL> | Generate a taskcluster slugid. This is a V4 UUID encoded into
URL-Safe Base64 (RFC 4648, sec 5) with '=' padding removed | f15765:m9 |
def stableSlugId(): | _cache = {}<EOL>def closure(name):<EOL><INDENT>if name not in _cache:<EOL><INDENT>_cache[name] = slugId()<EOL><DEDENT>return _cache[name]<EOL><DEDENT>return closure<EOL> | Returns a closure which can be used to generate stable slugIds.
Stable slugIds can be used in a graph to specify task IDs in multiple
places without regenerating them, e.g. taskId, requires, etc. | f15765:m10 |
def scopeMatch(assumedScopes, requiredScopeSets): | for scopeSet in requiredScopeSets:<EOL><INDENT>for requiredScope in scopeSet:<EOL><INDENT>for scope in assumedScopes:<EOL><INDENT>if scope == requiredScope:<EOL><INDENT>break<EOL><DEDENT>if scope.endswith("<STR_LIT:*>") and requiredScope.startswith(scope[:-<NUM_LIT:1>]):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL> | Take a list of a assumed scopes, and a list of required scope sets on
disjunctive normal form, and check if any of the required scope sets are
satisfied.
Example:
requiredScopeSets = [
["scopeA", "scopeB"],
["scopeC"]
]
In this case assumed_scopes must contain, either:
"scopeA" AND "scopeB", OR just "scopeC". | f15765:m11 |
def scope_match(assumed_scopes, required_scope_sets): | import warnings<EOL>warnings.warn('<STR_LIT>')<EOL>return scopeMatch(assumed_scopes, required_scope_sets)<EOL> | This is a deprecated form of def scopeMatch(assumedScopes, requiredScopeSets).
That form should be used. | f15765:m12 |
def makeHttpRequest(method, url, payload, headers, retries=MAX_RETRIES, session=None): | retry = -<NUM_LIT:1><EOL>response = None<EOL>while retry < retries:<EOL><INDENT>retry += <NUM_LIT:1><EOL>if retry > <NUM_LIT:0>:<EOL><INDENT>snooze = float(retry * retry) / <NUM_LIT><EOL>log.info('<STR_LIT>', snooze)<EOL>time.sleep(snooze)<EOL><DEDENT>if hasattr(payload, '<STR_LIT>'):<EOL><INDENT>payload.seek(<NUM_LIT:0>)<EOL><DEDENT>log.debug('<STR_LIT>', retry)<EOL>try:<EOL><INDENT>response = makeSingleHttpRequest(method, url, payload, headers, session)<EOL><DEDENT>except requests.exceptions.RequestException as rerr:<EOL><INDENT>if retry < retries:<EOL><INDENT>log.warn('<STR_LIT>' % rerr)<EOL>continue<EOL><DEDENT>raise rerr<EOL><DEDENT>try:<EOL><INDENT>response.raise_for_status()<EOL><DEDENT>except requests.exceptions.RequestException:<EOL><INDENT>pass<EOL><DEDENT>status = response.status_code<EOL>if <NUM_LIT> <= status and status < <NUM_LIT> and retry < retries:<EOL><INDENT>if retry < retries:<EOL><INDENT>log.warn('<STR_LIT>' % status)<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.TaskclusterRestFailure("<STR_LIT>", superExc=None)<EOL><DEDENT><DEDENT>return response<EOL><DEDENT>assert False, "<STR_LIT>"<EOL> | Make an HTTP request and retry it until success, return request | f15765:m13 |
def isExpired(certificate): | if isinstance(certificate, six.string_types):<EOL><INDENT>certificate = json.loads(certificate)<EOL><DEDENT>expiry = certificate.get('<STR_LIT>', <NUM_LIT:0>)<EOL>return expiry < int(time.time() * <NUM_LIT:1000>) + <NUM_LIT:20> * <NUM_LIT><EOL> | Check if certificate is expired | f15765:m18 |
def optionsFromEnvironment(defaults=None): | options = defaults or {}<EOL>credentials = options.get('<STR_LIT>', {})<EOL>rootUrl = os.environ.get('<STR_LIT>')<EOL>if rootUrl:<EOL><INDENT>options['<STR_LIT>'] = rootUrl<EOL><DEDENT>clientId = os.environ.get('<STR_LIT>')<EOL>if clientId:<EOL><INDENT>credentials['<STR_LIT>'] = clientId<EOL><DEDENT>accessToken = os.environ.get('<STR_LIT>')<EOL>if accessToken:<EOL><INDENT>credentials['<STR_LIT>'] = accessToken<EOL><DEDENT>certificate = os.environ.get('<STR_LIT>')<EOL>if certificate:<EOL><INDENT>credentials['<STR_LIT>'] = certificate<EOL><DEDENT>if credentials:<EOL><INDENT>options['<STR_LIT>'] = credentials<EOL><DEDENT>return options<EOL> | Fetch root URL and credentials from the standard TASKCLUSTER_…
environment variables and return them in a format suitable for passing to a
client constructor. | f15765:m19 |
def ping(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Ping Server
Respond without doing anything.
This endpoint is used to check that the service is up.
This method is ``stable`` | f15766:c0:m0 |
def email(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT:email>"], *args, **kwargs)<EOL> | Send an Email
Send an email to `address`. The content is markdown and will be rendered
to HTML, but both the HTML and raw markdown text will be sent in the
email. If a link is included, it will be rendered to a nice button in the
HTML version of the email
This method takes input: ``v1/email-request.json#``
This method is ``experimental`` | f15766:c0:m1 |
def pulse(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Publish a Pulse Message
Publish a message on pulse with the given `routingKey`.
This method takes input: ``v1/pulse-request.json#``
This method is ``experimental`` | f15766:c0:m2 |
def irc(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Post IRC Message
Post a message on IRC to a specific channel or user, or a specific user
on a specific channel.
Success of this API method does not imply the message was successfully
posted. This API method merely inserts the IRC message into a queue
that will be processed by a background process.
This allows us to re-send the message in face of connection issues.
However, if the user isn't online the message will be dropped without
error. We maybe improve this behavior in the future. For now just keep
in mind that IRC is a best-effort service.
This method takes input: ``v1/irc-request.json#``
This method is ``experimental`` | f15766:c0:m3 |
def addDenylistAddress(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Denylist Given Address
Add the given address to the notification denylist. The address
can be of either of the three supported address type namely pulse, email
or IRC(user or channel). Addresses in the denylist will be ignored
by the notification service.
This method takes input: ``v1/notification-address.json#``
This method is ``experimental`` | f15766:c0:m4 |
def deleteDenylistAddress(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Delete Denylisted Address
Delete the specified address from the notification denylist.
This method takes input: ``v1/notification-address.json#``
This method is ``experimental`` | f15766:c0:m5 |
def list(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT:list>"], *args, **kwargs)<EOL> | List Denylisted Notifications
Lists all the denylisted addresses.
By default this end-point will try to return up to 1000 addresses in one
request. But it **may return less**, even if more tasks are available.
It may also return a `continuationToken` even though there are no more
results. However, you can only be sure to have seen all results if you
keep calling `list` with the last `continuationToken` until you
get a result without a `continuationToken`.
If you are not interested in listing all the members at once, you may
use the query-string option `limit` to return fewer.
This method gives output: ``v1/notification-address-list.json#``
This method is ``experimental`` | f15766:c0:m6 |
def ping(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Ping Server
Respond without doing anything.
This endpoint is used to check that the service is up.
This method is ``stable`` | f15767:c0:m0 |
def oidcCredentials(self, *args, **kwargs): | return self._makeApiCall(self.funcinfo["<STR_LIT>"], *args, **kwargs)<EOL> | Get Taskcluster credentials given a suitable `access_token`
Given an OIDC `access_token` from a trusted OpenID provider, return a
set of Taskcluster credentials for use on behalf of the identified
user.
This method is typically not called with a Taskcluster client library
and does not accept Hawk credentials. The `access_token` should be
given in an `Authorization` header:
```
Authorization: Bearer abc.xyz
```
The `access_token` is first verified against the named
:provider, then passed to the provider's APIBuilder to retrieve a user
profile. That profile is then used to generate Taskcluster credentials
appropriate to the user. Note that the resulting credentials may or may
not include a `certificate` property. Callers should be prepared for either
alternative.
The given credentials will expire in a relatively short time. Callers should
monitor this expiration and refresh the credentials if necessary, by calling
this endpoint again, if they have expired.
This method gives output: ``v1/oidc-credentials-response.json#``
This method is ``experimental`` | f15767:c0:m1 |
def clientCreated(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Client Created Messages
Message that a new client has been created.
This exchange outputs: ``v1/client-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m0 |
def clientUpdated(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Client Updated Messages
Message that a new client has been updated.
This exchange outputs: ``v1/client-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m1 |
def clientDeleted(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Client Deleted Messages
Message that a new client has been deleted.
This exchange outputs: ``v1/client-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m2 |
def roleCreated(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Role Created Messages
Message that a new role has been created.
This exchange outputs: ``v1/role-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m3 |
def roleUpdated(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Role Updated Messages
Message that a new role has been updated.
This exchange outputs: ``v1/role-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m4 |
def roleDeleted(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Role Deleted Messages
Message that a new role has been deleted.
This exchange outputs: ``v1/role-message.json#``This exchange takes the following keys:
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15769:c0:m5 |
def pullRequest(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT:action>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | GitHub Pull Request Event
When a GitHub pull request event is posted it will be broadcast on this
exchange with the designated `organization` and `repository`
in the routing-key along with event specific metadata in the payload.
This exchange outputs: ``v1/github-pull-request-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `"primary"` for the formalized routing key. (required)
* organization: The GitHub `organization` which had an event. All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required)
* repository: The GitHub `repository` which had an event.All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required)
* action: The GitHub `action` which triggered an event. See for possible values see the payload actions property. (required) | f15770:c0:m0 |
def push(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | GitHub push Event
When a GitHub push event is posted it will be broadcast on this
exchange with the designated `organization` and `repository`
in the routing-key along with event specific metadata in the payload.
This exchange outputs: ``v1/github-push-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `"primary"` for the formalized routing key. (required)
* organization: The GitHub `organization` which had an event. All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required)
* repository: The GitHub `repository` which had an event.All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required) | f15770:c0:m1 |
def release(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | GitHub release Event
When a GitHub release event is posted it will be broadcast on this
exchange with the designated `organization` and `repository`
in the routing-key along with event specific metadata in the payload.
This exchange outputs: ``v1/github-release-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `"primary"` for the formalized routing key. (required)
* organization: The GitHub `organization` which had an event. All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required)
* repository: The GitHub `repository` which had an event.All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required) | f15770:c0:m2 |
def taskGroupCreationRequested(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | tc-gh requested the Queue service to create all the tasks in a group
supposed to signal that taskCreate API has been called for every task in the task group
for this particular repo and this particular organization
currently used for creating initial status indicators in GitHub UI using Statuses API.
This particular exchange can also be bound to RabbitMQ queues by custom routes - for that,
Pass in the array of routes as a second argument to the publish method. Currently, we do
use the statuses routes to bind the handler that creates the initial status.
This exchange outputs: ``v1/task-group-creation-requested.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `"primary"` for the formalized routing key. (required)
* organization: The GitHub `organization` which had an event. All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required)
* repository: The GitHub `repository` which had an event.All periods have been replaced by % - such that foo.bar becomes foo%bar - and all other special characters aside from - and _ have been stripped. (required) | f15770:c0:m3 |
def taskDefined(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Defined Messages
When a task is created or just defined a message is posted to this
exchange.
This message exchange is mainly useful when tasks are scheduled by a
scheduler that uses `defineTask` as this does not make the task
`pending`. Thus, no `taskPending` message is published.
Please, note that messages are also published on this exchange if defined
using `createTask`.
This exchange outputs: ``v1/task-defined-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task.
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task.
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task.
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m0 |
def taskPending(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Pending Messages
When a task becomes `pending` a message is posted to this exchange.
This is useful for workers who doesn't want to constantly poll the queue
for new tasks. The queue will also be authority for task states and
claims. But using this exchange workers should be able to distribute work
efficiently and they would be able to reduce their polling interval
significantly without affecting general responsiveness.
This exchange outputs: ``v1/task-pending-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task. (required)
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task.
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task.
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m1 |
def taskRunning(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Running Messages
Whenever a task is claimed by a worker, a run is started on the worker,
and a message is posted on this exchange.
This exchange outputs: ``v1/task-running-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task. (required)
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task. (required)
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task. (required)
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m2 |
def artifactCreated(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Artifact Creation Messages
Whenever the `createArtifact` end-point is called, the queue will create
a record of the artifact and post a message on this exchange. All of this
happens before the queue returns a signed URL for the caller to upload
the actual artifact with (pending on `storageType`).
This means that the actual artifact is rarely available when this message
is posted. But it is not unreasonable to assume that the artifact will
will become available at some point later. Most signatures will expire in
30 minutes or so, forcing the uploader to call `createArtifact` with
the same payload again in-order to continue uploading the artifact.
However, in most cases (especially for small artifacts) it's very
reasonable assume the artifact will be available within a few minutes.
This property means that this exchange is mostly useful for tools
monitoring task evaluation. One could also use it count number of
artifacts per task, or _index_ artifacts though in most cases it'll be
smarter to index artifacts after the task in question have completed
successfully.
This exchange outputs: ``v1/artifact-created-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task. (required)
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task. (required)
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task. (required)
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m3 |
def taskCompleted(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Completed Messages
When a task is successfully completed by a worker a message is posted
this exchange.
This message is routed using the `runId`, `workerGroup` and `workerId`
that completed the task. But information about additional runs is also
available from the task status structure.
This exchange outputs: ``v1/task-completed-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task. (required)
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task. (required)
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task. (required)
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m4 |
def taskFailed(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Failed Messages
When a task ran, but failed to complete successfully a message is posted
to this exchange. This is same as worker ran task-specific code, but the
task specific code exited non-zero.
This exchange outputs: ``v1/task-failed-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task.
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task.
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task.
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m5 |
def taskException(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Exception Messages
Whenever Taskcluster fails to run a message is posted to this exchange.
This happens if the task isn't completed before its `deadlìne`,
all retries failed (i.e. workers stopped responding), the task was
canceled by another entity, or the task carried a malformed payload.
The specific _reason_ is evident from that task status structure, refer
to the `reasonResolved` property for the last run.
This exchange outputs: ``v1/task-exception-message.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskId: `taskId` for the task this message concerns (required)
* runId: `runId` of latest run for the task, `_` if no run is exists for the task.
* workerGroup: `workerGroup` of latest run for the task, `_` if no run is exists for the task.
* workerId: `workerId` of latest run for the task, `_` if no run is exists for the task.
* provisionerId: `provisionerId` this task is targeted at. (required)
* workerType: `workerType` this task must run on. (required)
* schedulerId: `schedulerId` this task was created by. (required)
* taskGroupId: `taskGroupId` this task was created in. (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m6 |
def taskGroupResolved(self, *args, **kwargs): | ref = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>'<STR_LIT>': [<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>{<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:name>': '<STR_LIT>',<EOL>},<EOL>],<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return self._makeTopicExchange(ref, *args, **kwargs)<EOL> | Task Group Resolved Messages
A message is published on task-group-resolved whenever all submitted
tasks (whether scheduled or unscheduled) for a given task group have
been resolved, regardless of whether they resolved as successful or
not. A task group may be resolved multiple times, since new tasks may
be submitted against an already resolved task group.
This exchange outputs: ``v1/task-group-resolved.json#``This exchange takes the following keys:
* routingKeyKind: Identifier for the routing-key kind. This is always `'primary'` for the formalized routing key. (required)
* taskGroupId: `taskGroupId` for the task-group this message concerns (required)
* schedulerId: `schedulerId` for the task-group this message concerns (required)
* reserved: Space reserved for future routing-key entries, you should always match this entry with `#`. As automatically done by our tooling, if not specified. | f15771:c0:m7 |
def parse_auth_token_from_request(self, auth_header): | if not auth_header:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>parts = auth_header.split()<EOL>if parts[<NUM_LIT:0>].lower() != self.auth_header_prefix.lower():<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>'<EOL>'<STR_LIT>'.format(self.auth_header_prefix))<EOL><DEDENT>elif len(parts) == <NUM_LIT:1>:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>elif len(parts) > <NUM_LIT:2>:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>return parts[<NUM_LIT:1>]<EOL> | Parses and returns Auth token from the request header. Raises
`falcon.HTTPUnauthoried exception` with proper error message | f15780:c0:m1 |
def authenticate(self, req, resp, resource): | raise NotImplementedError("<STR_LIT>")<EOL> | Authenticate the request and return the authenticated user. Must return
`None` if authentication fails, or raise an exception | f15780:c0:m2 |
def get_auth_token(self, user_payload): | raise NotImplementedError("<STR_LIT>")<EOL> | Returns a authentication token created using the provided user details
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token | f15780:c0:m3 |
def get_auth_header(self, user_payload): | auth_token = self.get_auth_token(user_payload)<EOL>return '<STR_LIT>'.format(<EOL>auth_header_prefix=self.auth_header_prefix, auth_token=auth_token<EOL>)<EOL> | Returns the value for authorization header
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token | f15780:c0:m4 |
def authenticate(self, req, resp, resource): | payload = self._decode_jwt_token(req)<EOL>user = self.user_loader(payload)<EOL>if not user:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>return user<EOL> | Extract auth token from request `authorization` header, decode jwt token,
verify configured claims and return either a ``user``
object if successful else raise an `falcon.HTTPUnauthoried exception` | f15780:c1:m2 |
def get_auth_token(self, user_payload): | now = datetime.utcnow()<EOL>payload = {<EOL>'<STR_LIT:user>': user_payload<EOL>}<EOL>if '<STR_LIT>' in self.verify_claims:<EOL><INDENT>payload['<STR_LIT>'] = now<EOL><DEDENT>if '<STR_LIT>' in self.verify_claims:<EOL><INDENT>payload['<STR_LIT>'] = now + self.leeway<EOL><DEDENT>if '<STR_LIT>' in self.verify_claims:<EOL><INDENT>payload['<STR_LIT>'] = now + self.expiration_delta<EOL><DEDENT>if self.audience is not None:<EOL><INDENT>payload['<STR_LIT>'] = self.audience<EOL><DEDENT>if self.issuer is not None:<EOL><INDENT>payload['<STR_LIT>'] = self.issuer<EOL><DEDENT>return jwt.encode(<EOL>payload,<EOL>self.secret_key,<EOL>algorithm=self.algorithm,<EOL>json_encoder=ExtendedJSONEncoder).decode('<STR_LIT:utf-8>')<EOL> | Create a JWT authentication token from ``user_payload``
Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token | f15780:c1:m3 |
def authenticate(self, req, resp, resource): | username, password = self._extract_credentials(req)<EOL>user = self.user_loader(username, password)<EOL>if not user:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>return user<EOL> | Extract basic auth token from request `authorization` header, deocode the
token, verifies the username/password and return either a ``user``
object if successful else raise an `falcon.HTTPUnauthoried exception` | f15780:c2:m2 |
def get_auth_token(self, user_payload): | username = user_payload.get('<STR_LIT:username>') or None<EOL>password = user_payload.get('<STR_LIT:password>') or None<EOL>if not username or not password:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>token = '<STR_LIT>'.format(<EOL>username=username, password=password).encode('<STR_LIT:utf-8>')<EOL>token_b64 = base64.b64encode(token).decode('<STR_LIT:utf-8>', '<STR_LIT:ignore>')<EOL>return '<STR_LIT>'.format(<EOL>auth_header_prefix=self.auth_header_prefix, token_b64=token_b64)<EOL> | Extracts username, password from the `user_payload` and encode the
credentials `username:password` in `base64` form | f15780:c2:m3 |
def get_auth_token(self, user_payload): | token = user_payload.get('<STR_LIT>') or None<EOL>if not token:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return '<STR_LIT>'.format(<EOL>auth_header_prefix=self.auth_header_prefix, token=token)<EOL> | Extracts token from the `user_payload` | f15780:c3:m3 |
def parse_auth_token_from_request(self, auth_header): | if not auth_header:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>auth_header_prefix, _ = auth_header.split('<STR_LIT:U+0020>', <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>')<EOL><DEDENT>if auth_header_prefix.lower() != self.auth_header_prefix.lower():<EOL><INDENT>raise falcon.HTTPUnauthorized(<EOL>description='<STR_LIT>'<EOL>'<STR_LIT>'.format(self.auth_header_prefix))<EOL><DEDENT>return auth_header<EOL> | Parses and returns the Hawk Authorization header if it is present and well-formed.
Raises `falcon.HTTPUnauthoried exception` with proper error message | f15780:c5:m1 |
def __init__(<EOL>self,<EOL>login=None,<EOL>password=None,<EOL>cookie=None,<EOL>**kwargs<EOL>): | self._login = kwargs.get('<STR_LIT>', login)<EOL>password = kwargs.get('<STR_LIT:password>', password)<EOL>self._retries = kwargs.get('<STR_LIT>', <NUM_LIT:5>)<EOL>self._cookie = kwargs.get('<STR_LIT>', cookie)<EOL>self._last_result = None<EOL>ids = [self._login, password, self._cookie]<EOL>if all(val is None for val in ids):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if self._cookie is None:<EOL><INDENT>self._get_cookie(password)<EOL><DEDENT> | Initialise the EtnaWrapper.
Make a call to AUTH_URL, store the login and dump the password away.
Store a cookie.
:param str login: Login of the user
:param str password: Password of the user
:param int retries: Number of time to retry while requesting a cookie | f15787:c2:m0 |
def _request_api(self, **kwargs): | _url = kwargs.get('<STR_LIT:url>')<EOL>_method = kwargs.get('<STR_LIT>', '<STR_LIT:GET>')<EOL>_status = kwargs.get('<STR_LIT:status>', <NUM_LIT:200>)<EOL>counter = <NUM_LIT:0><EOL>if _method not in ['<STR_LIT:GET>', '<STR_LIT:POST>']:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>res = REQ[_method](_url, cookies=self._cookie)<EOL>if res.status_code == _status:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>raise BadStatusException(res.content)<EOL><DEDENT><DEDENT>except requests.exceptions.BaseHTTPError:<EOL><INDENT>if counter < self._retries:<EOL><INDENT>counter += <NUM_LIT:1><EOL>continue<EOL><DEDENT>raise MaxRetryError<EOL><DEDENT><DEDENT>self._last_result = res<EOL>return res<EOL> | Wrap the calls the url, with the given arguments.
:param str url: Url to call with the given arguments
:param str method: [POST | GET] Method to use on the request
:param int status: Expected status code | f15787:c2:m2 |
def get_infos(self): | return self._request_api(url=IDENTITY_URL).json()<EOL> | Get info about the current user.
:return: JSON | f15787:c2:m3 |
def get_infos_with_id(self, uid): | _logid = uid<EOL>_user_info_url = USER_INFO_URL.format(logid=_logid)<EOL>return self._request_api(url=_user_info_url).json()<EOL> | Get info about a user based on his id.
:return: JSON | f15787:c2:m4 |
def get_promos(self): | return self._request_api(url=USER_PROMO_URL).json()<EOL> | Get informations about the user's promotion.
:return: JSON | f15787:c2:m5 |
def get_current_activities(self, login=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login or self._login<EOL>)<EOL>_activity_url = ACTIVITY_URL.format(login=_login)<EOL>return self._request_api(url=_activity_url).json()<EOL> | Get the current activities of user.
Either use the `login` param, or the client's login if unset.
:return: JSON | f15787:c2:m6 |
def get_notifications(self, login=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login or self._login<EOL>)<EOL>_notif_url = NOTIF_URL.format(login=_login)<EOL>return self._request_api(url=_notif_url).json()<EOL> | Get the current notifications of a user.
:return: JSON | f15787:c2:m7 |
def get_grades(self, login=None, promotion=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login or self._login<EOL>)<EOL>_promotion_id = kwargs.get('<STR_LIT>', promotion)<EOL>_grades_url = GRADES_URL.format(login=_login, promo_id=_promotion_id)<EOL>return self._request_api(url=_grades_url).json()<EOL> | Get a user's grades on a single promotion based on his login.
Either use the `login` param, or the client's login if unset.
:return: JSON | f15787:c2:m8 |
def get_picture(self, login=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login or self._login<EOL>)<EOL>_activities_url = PICTURE_URL.format(login=_login)<EOL>return self._request_api(url=_activities_url).content<EOL> | Get a user's picture.
:param str login: Login of the user to check
:return: JSON | f15787:c2:m9 |
def get_projects(self, **kwargs): | _login = kwargs.get('<STR_LIT>', self._login)<EOL>search_url = SEARCH_URL.format(login=_login)<EOL>return self._request_api(url=search_url).json()<EOL> | Get a user's project.
:param str login: User's login (Default: self._login)
:return: JSON | f15787:c2:m10 |
def get_activities_for_project(self, module=None, **kwargs): | _module_id = kwargs.get('<STR_LIT>', module)<EOL>_activities_url = ACTIVITIES_URL.format(module_id=_module_id)<EOL>return self._request_api(url=_activities_url).json()<EOL> | Get the related activities of a project.
:param str module: Stages of a given module
:return: JSON | f15787:c2:m11 |
def get_group_for_activity(self, module=None, project=None, **kwargs): | _module_id = kwargs.get('<STR_LIT>', module)<EOL>_project_id = kwargs.get('<STR_LIT>', project)<EOL>_url = GROUPS_URL.format(module_id=_module_id, project_id=_project_id)<EOL>return self._request_api(url=_url).json()<EOL> | Get groups for activity.
:param str module: Base module
:param str module: Project which contains the group requested
:return: JSON | f15787:c2:m12 |
def get_students(self, **kwargs): | _promotion_id = kwargs.get('<STR_LIT>')<EOL>_url = PROMOTION_URL.format(promo_id=_promotion_id)<EOL>return self._request_api(url=_url).json()<EOL> | Get users by promotion id.
:param int promotion: Promotion ID
:return: JSON | f15787:c2:m13 |
def get_log_events(self, login=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login<EOL>)<EOL>log_events_url = GSA_EVENTS_URL.format(login=_login)<EOL>return self._request_api(url=log_events_url).json()<EOL> | Get a user's log events.
:param str login: User's login (Default: self._login)
:return: JSON | f15787:c2:m14 |
def get_events(self, login=None, start_date=None, end_date=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login<EOL>)<EOL>log_events_url = EVENTS_URL.format(<EOL>login=_login,<EOL>start_date=start_date,<EOL>end_date=end_date,<EOL>)<EOL>return self._request_api(url=log_events_url).json()<EOL> | Get a user's events.
:param str login: User's login (Default: self._login)
:param str start_date: Start date
:param str end_date: To date
:return: JSON | f15787:c2:m15 |
def get_logs(self, login=None, **kwargs): | _login = kwargs.get(<EOL>'<STR_LIT>',<EOL>login<EOL>)<EOL>log_events_url = GSA_LOGS_URL.format(login=_login)<EOL>return self._request_api(url=log_events_url).json()<EOL> | Get a user's logs.
:param str login: User's login (Default: self._login)
:return: JSON | f15787:c2:m16 |
def main(): | parser = argparse.ArgumentParser()<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>", default=None)<EOL>parser.add_argument("<STR_LIT>", "<STR_LIT>", help="<STR_LIT>", default=os.getcwd())<EOL>options = parser.parse_args()<EOL>try:<EOL><INDENT>scanner = Scanner(path=options.path, output=options.out)<EOL>scanner.run()<EOL>scanner.output()<EOL><DEDENT>except ScannerException as e:<EOL><INDENT>print("<STR_LIT>" % str(e))<EOL>exit(<NUM_LIT:1>)<EOL><DEDENT> | Main entry point of the scanner
:return: void | f15793:m0 |
def run(self): | <EOL>self.path = os.path.expanduser(self.path)<EOL>if os.path.isdir(self.path):<EOL><INDENT>self.search_script_directory(self.path)<EOL>return self<EOL><DEDENT>else:<EOL><INDENT>raise ScannerException("<STR_LIT>" % self.path)<EOL><DEDENT> | Runs the scanner
:return: self | f15796:c0:m1 |
def output(self): | if not self.path_output:<EOL><INDENT>self.output_to_fd(sys.stdout)<EOL><DEDENT>else:<EOL><INDENT>with open(self.path_output, "<STR_LIT:w>") as out:<EOL><INDENT>self.output_to_fd(out)<EOL><DEDENT><DEDENT> | Output the results to either STDOUT or
:return: | f15796:c0:m2 |
def output_to_fd(self, fd): | for library in self.libraries_found:<EOL><INDENT>fd.write("<STR_LIT>" % (library.key, library.version))<EOL><DEDENT> | Outputs the results of the scanner to a file descriptor (stdout counts :)
:param fd: file
:return: void | f15796:c0:m3 |
def search_script_directory(self, path): | for subdir, dirs, files in os.walk(path):<EOL><INDENT>for file_name in files:<EOL><INDENT>if file_name.endswith("<STR_LIT>"):<EOL><INDENT>self.search_script_file(subdir, file_name)<EOL><DEDENT><DEDENT><DEDENT> | Recursively loop through a directory to find all python
script files. When one is found, it is analyzed for import statements
:param path: string
:return: generator | f15796:c0:m4 |
def search_script_file(self, path, file_name): | with open(os.path.join(path, file_name), "<STR_LIT:r>") as script:<EOL><INDENT>self.search_script(script.read())<EOL><DEDENT> | Open a script file and search it for library references
:param path:
:param file_name:
:return: void | f15796:c0:m5 |
def search_script(self, script): | if self.import_statement.search(script):<EOL><INDENT>for installed in self.libraries_installed:<EOL><INDENT>for found in set(self.import_statement.findall(script)):<EOL><INDENT>if found == installed.key:<EOL><INDENT>self.libraries_installed.remove(installed)<EOL>self.libraries_found.append(installed)<EOL><DEDENT><DEDENT><DEDENT><DEDENT> | Search a script's contents for import statements and check
if they're currently prevent in the list of all installed
pip modules.
:param script: string
:return: void | f15796:c0:m6 |
@staticmethod<EOL><INDENT>def status(s):<DEDENT> | print('<STR_LIT>'.format(s))<EOL> | Prints things in bold. | f15797:c0:m0 |
def get_schema(self, schema_id): | res = requests.get(self._url('<STR_LIT>', schema_id))<EOL>raise_if_failed(res)<EOL>return json.loads(res.json()['<STR_LIT>'])<EOL> | Retrieves the schema with the given schema_id from the registry
and returns it as a `dict`. | f15799:c2:m2 |
def get_subjects(self): | res = requests.get(self._url('<STR_LIT>'))<EOL>raise_if_failed(res)<EOL>return res.json()<EOL> | Returns the list of subject names present in the schema registry. | f15799:c2:m3 |
def get_subject_version_ids(self, subject): | res = requests.get(self._url('<STR_LIT>', subject))<EOL>raise_if_failed(res)<EOL>return res.json()<EOL> | Return the list of schema version ids which have been registered
under the given subject. | f15799:c2:m4 |
def get_subject_version(self, subject, version_id): | res = requests.get(self._url('<STR_LIT>', subject, version_id))<EOL>raise_if_failed(res)<EOL>return json.loads(res.json()['<STR_LIT>'])<EOL> | Retrieves the schema registered under the given subject with
the given version id. Returns the schema as a `dict`. | f15799:c2:m5 |
def register_subject_version(self, subject, schema): | data = json.dumps({'<STR_LIT>': json.dumps(schema)})<EOL>res = requests.post(self._url('<STR_LIT>', subject), data=data, headers=HEADERS)<EOL>raise_if_failed(res)<EOL>return res.json()['<STR_LIT:id>']<EOL> | Registers the given schema (provided as a `dict`) to the given
subject. Returns the id allocated to the schema in the registry. | f15799:c2:m7 |
def schema_registration_for_subject(self, subject, schema): | data = json.dumps({'<STR_LIT>': json.dumps(schema)})<EOL>res = requests.post(self._url('<STR_LIT>', subject), data=data, headers=HEADERS)<EOL>raise_if_failed(res)<EOL>res_data = res.json()<EOL>return res_data['<STR_LIT:id>'], res_data['<STR_LIT:version>']<EOL> | Returns the registration information for the given schema in the
registry under the given subject. The registration information
is returned as (schema_id, version_id) pair in a tuple. | f15799:c2:m8 |
def schema_is_registered_for_subject(self, subject, schema): | data = json.dumps({'<STR_LIT>': json.dumps(schema)})<EOL>res = requests.post(self._url('<STR_LIT>', subject), data=data, headers=HEADERS)<EOL>if res.status_code == <NUM_LIT>:<EOL><INDENT>return False<EOL><DEDENT>raise_if_failed(res)<EOL>return True<EOL> | Returns True if the given schema is already registered under the
given subject. | f15799:c2:m9 |
def schema_is_compatible_with_subject_version(self, subject, version_id, schema): | data = json.dumps({'<STR_LIT>': json.dumps(schema)})<EOL>res = requests.post(<EOL>self._url('<STR_LIT>', subject, version_id),<EOL>data=data, headers=HEADERS)<EOL>raise_if_failed(res)<EOL>return res.json()['<STR_LIT>']<EOL> | Returns True if the given schema is compatible with the schema
already registered under the given subject and version id.
Compatibility is determined based on the compatibility level
configured either globally or specifically for the subject
(whichever is more specific). | f15799:c2:m10 |
def set_global_compatibility_level(self, level): | res = requests.put(<EOL>self._url('<STR_LIT>'),<EOL>data=json.dumps({'<STR_LIT>': level}),<EOL>headers=HEADERS)<EOL>raise_if_failed(res)<EOL> | Sets the global compatibility level. | f15799:c2:m11 |
def get_global_compatibility_level(self): | res = requests.get(self._url('<STR_LIT>'), headers=HEADERS)<EOL>raise_if_failed(res)<EOL>return res.json()['<STR_LIT>']<EOL> | Gets the global compatibility level. | f15799:c2:m12 |
def set_subject_compatibility_level(self, subject, level): | res = requests.put(<EOL>self._url('<STR_LIT>', subject),<EOL>data=json.dumps({'<STR_LIT>': level}),<EOL>headers=HEADERS)<EOL>raise_if_failed(res)<EOL> | Sets the compatibility level for the given subject. | f15799:c2:m13 |
def get_subject_compatibility_level(self, subject): | res = requests.get(self._url('<STR_LIT>', subject), headers=HEADERS)<EOL>raise_if_failed(res)<EOL>return res.json()['<STR_LIT>']<EOL> | Gets the compatibility level for the given subject. | f15799:c2:m14 |
def get_table(ports): | table = PrettyTable(["<STR_LIT:Name>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>table.align["<STR_LIT:Name>"] = "<STR_LIT:l>"<EOL>table.align["<STR_LIT>"] = "<STR_LIT:l>"<EOL>table.padding_width = <NUM_LIT:1><EOL>for port in ports:<EOL><INDENT>table.add_row(port)<EOL><DEDENT>return table<EOL> | This function returns a pretty table used to display the port results.
:param ports: list of found ports
:return: the table to display | f15801:m0 |
@click.command()<EOL>@click.version_option()<EOL>@click.argument('<STR_LIT>', required=False)<EOL>@click.option('<STR_LIT>', is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', "<STR_LIT>", is_flag=True, default=False,<EOL>help='<STR_LIT>')<EOL>@click.option("<STR_LIT>", type=(str, int), default=(None, None),<EOL>help="<STR_LIT>")<EOL>def run(port, like, use_json, server): | if not port and not server[<NUM_LIT:0>]:<EOL><INDENT>raise click.UsageError("<STR_LIT>")<EOL><DEDENT>if server[<NUM_LIT:0>]:<EOL><INDENT>app.run(host=server[<NUM_LIT:0>], port=server[<NUM_LIT:1>])<EOL>return<EOL><DEDENT>ports = get_ports(port, like)<EOL>if not ports:<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(port))<EOL>return<EOL><DEDENT>if use_json:<EOL><INDENT>print(json.dumps(ports, indent=<NUM_LIT:4>))<EOL><DEDENT>else:<EOL><INDENT>table = get_table(ports)<EOL>print(table)<EOL><DEDENT> | Search port names and numbers. | f15801:m1 |
@app.route("<STR_LIT>", methods=["<STR_LIT:GET>"])<EOL>def all_ports(): | return jsonify({"<STR_LIT>": __DB__.all()})<EOL> | Returns all ports | f15802:m0 |
@app.route("<STR_LIT>", methods=["<STR_LIT:GET>"])<EOL>def specific_ports(pattern): | like = "<STR_LIT>" in request.args<EOL>return jsonify({"<STR_LIT>": get_ports(pattern, like)})<EOL> | Returns all ports matching the given pattern | f15802:m1 |
def get_ports(port, like=False): | where_field = "<STR_LIT:port>" if port.isdigit() else "<STR_LIT:name>"<EOL>if like:<EOL><INDENT>ports = __DB__.search(where(where_field).search(port))<EOL><DEDENT>else:<EOL><INDENT>ports = __DB__.search(where(where_field) == port)<EOL><DEDENT>return [Port(**port) for port in ports]<EOL> | This function creates the SQL query depending on the specified port and
the --like option.
:param port: the specified port
:param like: the --like option
:return: all ports matching the given ``port``
:rtype: list | f15804:m0 |
def fill_model(self, model=None): | normalized_dct = self.normalize()<EOL>if model:<EOL><INDENT>if not isinstance(model, self._model_class):<EOL><INDENT>raise ModelFormSecurityError('<STR_LIT>' % (model, self._model_class.__name__))<EOL><DEDENT>model.populate(**normalized_dct)<EOL>return model<EOL><DEDENT>return self._model_class(**normalized_dct)<EOL> | Populates a model with normalized properties. If no model is provided (None) a new one will be created.
:param model: model to be populade
:return: populated model | f15816:c4:m0 |
def fill_with_model(self, model, *fields): | model_dct = model.to_dict(include=self._fields.keys())<EOL>localized_dct = self.localize(*fields, **model_dct)<EOL>if model.key:<EOL><INDENT>localized_dct['<STR_LIT:id>'] = model.key.id()<EOL><DEDENT>return localized_dct<EOL> | Populates this form with localized properties from model.
:param fields: string list indicating the fields to include. If None, all fields defined on form will be used
:param model: model
:return: dict with localized properties | f15816:c4:m1 |
def validate_field(self, value): | if self.choices:<EOL><INDENT>value = self.normalize_field(value)<EOL>if value in self.choices:<EOL><INDENT>return None<EOL><DEDENT>return _('<STR_LIT>') % {'<STR_LIT>': '<STR_LIT>'.join(self.choices)}<EOL><DEDENT>if self.default is not None:<EOL><INDENT>if value is None or value == '<STR_LIT>':<EOL><INDENT>value = self.default<EOL><DEDENT><DEDENT>if self.required and (value is None or value == '<STR_LIT>'):<EOL><INDENT>return _('<STR_LIT>')<EOL><DEDENT> | Method that must validate the value
It must return None if the value is valid and a error msg otherelse.
Ex: If expected input must be int, validate should a return a msg like
"The filed must be a integer value" | f15818:c0:m4 |
def normalize(self, value): | return self._execute_one_or_repeated(self.normalize_field, value)<EOL> | Normalizes a value to be stored on db. Transforms string from web requests on db object, removing any
localization
:param value: value to be normalize
:return: a normalized value | f15818:c0:m8 |
def normalize_field(self, value): | if self.default is not None:<EOL><INDENT>if value is None or value == '<STR_LIT>':<EOL><INDENT>value = self.default<EOL><DEDENT><DEDENT>return value<EOL> | Method that must transform the value from string
Ex: if the expected type is int, it should return int(self._attr) | f15818:c0:m9 |
def localize(self, value): | return self._execute_one_or_repeated(self.localize_field, value)<EOL> | Localizes a value to be sent to clients. Transforms object on localized strings. Must make the opposite of
normalizes
:param value: value to be localized
:return: a localized value | f15818:c0:m10 |
def localize_field(self, value): | if self.default is not None:<EOL><INDENT>if value is None or value == '<STR_LIT>':<EOL><INDENT>value = self.default<EOL><DEDENT><DEDENT>return value or '<STR_LIT>'<EOL> | Method that must transform the value from object to localized string | f15818:c0:m11 |
def _get_tz(): | return '<STR_LIT>'<EOL> | Factory that returns forms's timezone
:return: | f15820:m1 |
def locale_factory(factory): | global _get_locale<EOL>_get_locale = factory<EOL>return factory<EOL> | Decorator which defines a factory function which
set forms locale. If not defined locale 'en_US' is used
:param factory: function
:return: str with locale | f15820:m2 |
def tz_factory(factory): | global _get_tz<EOL>_get_tz = factory<EOL>return factory<EOL> | Decorator which defines a factory function which
set forms timezone. If not defined tz 'UTC' is used
:param factory: function
:return: str: with timezone | f15820:m3 |
def get_locale(): | return babel.Locale.parse(_get_locale())<EOL> | Build a ``babel.Locale`` based on locale factory
:return: ``babel.Locale`` | f15820:m4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.