Parameters
typestringrequireddatabase or object.
providerstringrequiredWhich one — see the pairs below.
labelstringThe display name. Derived from the provider by default.
endpoint.credentialsobject|stringWhere the secret goes. Encrypted at rest.
endpoint.optionsobjectAnything else the provider needs.
The pairs that are accepted
| type | provider | Is |
|---|---|---|
| database | mongodb | A MongoDB database. |
| database | d1 | A Cloudflare D1 database. |
| object | r2 | A Cloudflare R2 bucket. |
| object | s3 | An S3 bucket. |
Anything else is refused with invalid_external_type_provider_combination — before anything is stored.
Put the secret in credentials
const mongo = await api.storage.connect({
label: "Prod",
type: "database",
provider: "mongodb",
endpoint: { credentials: { uri: "mongodb+srv://user:password@host/mydb" } },
});mongo = api.storage.connect(
label="Prod",
type="database",
provider="mongodb",
endpoint={"credentials": {"uri": "mongodb+srv://user:password@host/mydb"}},
)A connection URI usually carries the password, so it belongs there and nowhere else. Nothing about a storage hands its endpoint back afterwards — the server uses it to connect, and you are the one who supplied it.
For MongoDB, the database is read from the path of the URI — …/mydb. Leave it out and the connection lands on a default database, which will look empty and is the usual explanation for « my collections are missing ».
It is registered, not tested
connect() succeeds without opening the connection. A wrong URI, a revoked password, a firewall — none of it surfaces here; it surfaces on the first run().
const mongo = await api.storage.connect({ label, type: "database", provider: "mongodb",
endpoint: { credentials: { uri } } });
// Prove it works now, rather than at the worst moment later
try {
await mongo.run({ action: "collections" });
} catch (err) {
await api.storage.remove(mongo.id);
throw new Error(`that connection does not work: ${err.message}`);
}from iagenify import IaGenifyError
mongo = api.storage.connect(label=label, type="database", provider="mongodb",
endpoint={"credentials": {"uri": uri}})
# Prove it works now, rather than at the worst moment later
try:
mongo.run(action="collections")
except IaGenifyError as error:
api.storage.remove(mongo.id)
raise RuntimeError(f"that connection does not work: {error}") from errorReturns
mongo.id;
mongo.label; // "Prod"
mongo.type; // "database"
mongo.provider; // "mongodb"
mongo.managedBy; // who operates it
mongo.isDefault;
mongo.createdAt;mongo.id
mongo.label # "Prod"
mongo.type # "database"
mongo.provider # "mongodb"
mongo.managed_by # who operates it
mongo.is_default
mongo.created_atGive it the narrowest credential that works
- A user that can read what you need and nothing else, rather than an administrator.
- A separate credential per connection, so revoking one does not break the others.
- Something you can rotate without us: to change it, connect again and remove the old one.
Reading is one permission category and writing is another, both asked before anything happens. Decide what the credential allows as well as what the mode allows — the credential is the harder boundary.
Errors
| Code | Status | When |
|---|---|---|
| — (thrown locally) | — | type or provider missing. |
| invalid_external_type_provider_combination | 400 | That pair is not one of the four. |
| credentials_encryption_failed | 500 | The secret could not be encrypted — nothing was stored. |