The web and keys

3 entries

Markdown

m.fetch

One https request, made by your Ownbox.

Signature
m.fetch(url, *, method='GET', headers=None, body=None, key=None, timeout=20)
Example · Inside a job
try:
    r = m.fetch("https://api.example.com/v1/quotes", key="example")
    quotes = r.json() if r.ok else []
except sdk.BoxRefused as e:
    m.save_setting("last_fetch_error", e.code)

Only to a host the owner allowed. key names a key the owner saved: your Ownbox attaches it, only for that key's own host, and the machine never sees it. A redirect is handed back, not followed. body is text, bytes, or a dict sent as JSON.

Needs in machine.yaml
fetch: [host], and keys: [...] for a key
Returns
A response: .status, .headers (lower-case names), .content (bytes), .text, .json() and .ok.

m.keys_page

The owner's page for this machine's keys.

Signature
m.keys_page
Example · Inside a job
m.save_setting("keys_at", m.keys_page)

Where the owner enters a key the machine named in machine.yaml, and sets its monthly limit for m.spend. Link to it when a key is missing.

Needs in machine.yaml
Nothing
Returns
A path on the Ownbox.

m.secretAlways refused

Never available to a custom machine.

Signature
m.secret(name, *, label=None, help='')

Always refused never_readable. A machine never reads a key: name it on the request, m.fetch(url, key=...).