Cloud Request Engine
Python Pipeline Cloud Request Engine
Introduction
The Pipeline is a generic web request intelligence and data processing solution with the ability to add a range of 51Degrees and/or custom plug ins (Engines)
Requirements
- Python 3.8+
This package fiftyone_pipeline_cloudrequestengine
This package uses the engines class created by the fiftyone-pipeline-engines. It makes available:
- A
Cloud Request Enginewhich calls the 51Degrees cloud service to fetch properties and metadata about them based on a provided resource key. Get a resource key at https://51degrees.com/configure/?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine&utm_term=this-package-fiftyone_pipeline_cloudrequestengine - A
Cloud Enginetemplate which reads data from the Cloud Request Engine.
Credentials
The engine authenticates with a resource key, a licence key, or both, set
as resource_key and license_key in its settings. Which one is set
decides whether requested_properties, the list of fully qualified
property names to ask for, is also needed:
resource_key |
license_key |
requested_properties |
Accepted |
|---|---|---|---|
| Yes | No | No | Yes. The resource key states which properties it carries. |
| Yes | Yes | No | Yes. The answer holds what the resource key carries. |
| Yes | Yes | Yes | Yes. The service adds the listed properties the licence key grants. |
| Yes | No | Yes | Yes. The service adds the listed properties, as null with a reason where no licence grants one. |
| No | Yes | Yes | Yes. A licence key names no properties, so the list says which are wanted. |
| No | Yes | No | No. The service answers 400 to every such request. |
| No | No | Either | No. There is nothing to authenticate with. |
A combination that is not accepted raises ValueError when the engine is
built, so a deployment sees one configuration error rather than a failure
on every request. A value that is empty or only whitespace counts as
absent, and each value is trimmed, so a key read from an environment
variable with a trailing newline still works.
A resource key is public by design, because it travels to the browser in a script URL. A caller that runs only on the server should use a licence key and name the properties it wants, so the credential stays on the server and each answer carries only what that caller needs. A licence key is sent in the body of every request, never in a URL. Where a request named properties and the answer left some out, the engine warns once that they are not covered by the keys in use, and the properties that came back are usable as normal. With a resource key and no licence key, a property no licence grants comes back as null with a reason, so the warning says instead that every property is answered and these names are not properties, and asks the caller to check the spelling of each one.
See the Credentials section of the cloud request engine specification
and the rules in
cloudrequestengine.py.
When the engine is built
The engine asks the cloud service for the properties the key carries and
the evidence keys the service accepts when it is constructed, so a
pipeline built with it has both before the first request. When the cloud
service refuses either request, with an answer from 400 to 499 such as
the one for a resource key that is not valid, the constructor raises
CloudRequestException. Any other failure, such as the service being
unreachable, a timeout or an answer of 500 or more, gives a warning and
the engine is still built, so a cloud outage does not stop the
application starting. The engine then asks again when it is first used,
and a failure at that point is an error of that request, which
suppress_process_exceptions decides whether to raise. Until then the
cloud engines after it have no property metadata.
Each entry in the warnings list of an answer from the cloud service is
given as a warning, with any licence key masked.
A cloud engine takes its properties from the Cloud Request Engine in its pipeline. It can be in several pipelines that share one Cloud Request Engine, and a pipeline with a different Cloud Request Engine refuses it, so build a cloud engine for each Cloud Request Engine.
An engine whose discovery has completed gives what it discovered with
discovery_state(), as one JSON document. Keep it, and give it as the
discovery_state setting of an engine with the same credentials, for
example on the next start of a short-lived host, and that engine is built
without asking the cloud service. The document is the one the Java
package's CloudDiscoveryState writes.
See the Start-up activity section of the cloud request engine specification.
Timeout
Each request to the cloud service waits at most timeout_seconds to
connect, and at most that long again for each part of the answer, before it
fails with a timeout. The default is 2 seconds, as the
configuration options of the cloud request engine specification
give. A value that is not a finite number above zero raises ValueError when the
engine is built. A request that times out while the engine is built is a
failure that may pass, so the engine is built with a warning and asks
again when it is first used.
A client given as http_client is passed the timeout when its request
method has a timeout_seconds parameter, as RequestClient.request does,
and is called without it otherwise.
Redirects
No request to the cloud service follows a redirect, whatever credential it
carries. An answer of 301, 302, 303, 307 or 308 fails with a
CloudRequestException that names the endpoint and the status code and
shows no key. A client given as http_client should not follow redirects
either.
Reading the answer
The engine's data holds the raw JSON answer of the cloud service as its
cloud property, and is read under cloud-response, the key the
Element Data section of the cloud request engine specification
gives, as in flowdata.get("cloud-response").get("cloud"). The old key,
cloud, gives the same data and is deprecated, so read under
cloud-response instead. The old key will be removed in a later release.
The engine's own data key is still cloud, so
pipeline.get_element("cloud") still finds the engine, and the JSON for the
browser leaves the engine's data out as before.
Human Confidence from a sealed result
Add DerivedCloud after the engine to read HumanConfidence and
HumanConfidenceSource as flowdata.derived. On a request whose evidence
holds a non-empty query.humanconfidence, the engine redeems that sealed
result in its one call, asking for both properties, and DerivedCloud
gives the value and the source, Passive or Active, that the cloud
service's response holds. Where the sealed result isn't redeemed, it gives
Medium, and HumanConfidenceSource has no value, with a message that says
why. It adds no error of its own, and a read doesn't raise.
DerivedCloud also works in a pipeline with no Cloud Request Engine, such
as an on-premise one. There, nothing is redeemed: a request carrying a
sealed result gives Medium and no source, and any other request gives the
two properties with no value and a reason. DerivedCloud is in
fiftyone_pipeline_cloudrequestengine.humanconfidence, and is added as any
other element, e.g. PipelineBuilder().add(DerivedCloud()).build().
The page loads the client script from the address the package gives it,
page.script_url(...) from HumanConfidenceTransactions.issue(), and its
own code always sends the sealed result and the page id back to the
server, whatever HumanConfidenceSource is. These are the lines a consumer
writes, where PAGE is the page's id:
fod.complete(function (data) {
var body = new URLSearchParams();
body.set("humanconfidence", data.derived.humanconfidence || "");
body.set("humanconfidencepage", PAGE);
fetch("humanconfidence", { method: "POST", body: body });
});
The server adds both as query. evidence and reads the two properties
from flowdata.derived. A server that works outside a Pipeline can redeem
a sealed result with HumanConfidenceClient in fiftyone_pipeline_did
instead.
A page whose request names HumanConfidence also gets the browser tests, so the client script's complete handlers run later than they otherwise would, by the time the tests take and one more request. A page can read the first response's properties sooner through its change handlers.
Where a page sets a Content Security Policy, it must allow these for the
browser tests to run. Otherwise HumanConfidenceSource stays Passive.
| Directive | Must allow |
|---|---|
script-src |
The cloud service's host, and 'unsafe-eval' |
connect-src |
The cloud service's host |
worker-src |
blob: |
The rules are on the Human Confidence page of the pipeline specification.
Pointing the engine at another host
The engine calls https://cloud.51degrees.com/api/v4/ unless told
otherwise. Set the _51DEGREES_CLOUD_ENDPOINT environment variable, or pass
cloud_endpoint in the engine settings, to the API base of another
host including the /api/v4/ segment. Constants.CLOUD_ENDPOINT holds
the name of that variable. A host other than
cloud.51degrees.com would be used to (a) use an on premise web server,
or (b) use a privately hosted version of the 51Degrees cloud for
performance reasons. This is the private hosting option of the cloud
service, and both run the same service, so code written against one
works unchanged against the other.
Examples
The examples folder holds examples that use this engine to get device detection and IP intelligence results from one request to the 51Degrees cloud service, with a resource key or a licence key. Its readme says how to run them.
Engines that use it
It is used by the cloud versions of the following 51Degrees engines:
- fiftyone_devicedetection - Get details about the devices accessing your web page
- fiftyone_location - Get postal address details from the location of devices accessing your web page
Find out more
Metadata
Release files for fiftyone-pipeline-cloudrequestengine 4.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fiftyone_pipeline_cloudrequestengine-4.6.2.tar.gz | 81.5 kB | Without provenance | Details for fiftyone_pipeline_cloudrequestengine-4.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fiftyone_pipeline_cloudrequestengine-4.6.2-py3-none-any.whl | Python 3 | none | any | Details for fiftyone_pipeline_cloudrequestengine-4.6.2-py3-none-any.whl |
Total release size: 122.4 kB
Release files / fiftyone_pipeline_cloudrequestengine-4.6.2.tar.gz
| Download URL | fiftyone_pipeline_cloudrequestengine-4.6.2.tar.gz |
|---|---|
| Size | 81.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9af879c727cba61ddb72f44ab0bfc4c35af903d270a6517b8638a6fc081d55f
|
|
BLAKE2b-256 checksum How to use checksums |
c4586ead1b0814c637c71ff587749f00d900beab5e6c22ee0aef48aa5a2ba926
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / fiftyone_pipeline_cloudrequestengine-4.6.2-py3-none-any.whl
| Download URL | fiftyone_pipeline_cloudrequestengine-4.6.2-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26e3d3dd1ef290a5765209a5cff9c9071e735ac0120fa88a729ee75f60cd6334
|
|
BLAKE2b-256 checksum How to use checksums |
2220d941c2123e33a0e3035eaf08298fec01afeb31e56b06aa04e961e37ff162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for fiftyone-pipeline-cloudrequestengine 4.6.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.