Class ApiKey
- Namespace
- DatabentoDotNet
- Assembly
- DatabentoDotNet.Dbn.dll
A validated Databento API key: exactly 32 ASCII characters, whose last five are the bucket id the gateway uses to look the key up.
public sealed class ApiKey
- Inheritance
-
ApiKey
- Inherited Members
Examples
var key = new ApiKey(Environment.GetEnvironmentVariable("DATABENTO_API_KEY")!);
Console.WriteLine(key.BucketId); // the last five characters, which the gateway looks the key up by
Console.WriteLine(key); // …bcdef — ToString is redacted, and that is load-bearing
// Length, character set and the documentation placeholder are all checked here, at the point the
// key is supplied, rather than in the middle of a handshake.
new ApiKey("$YOUR_API_KEY"); // throws ArgumentException, naming the placeholder
Remarks
Port of upstream's ApiKey (lib.rs:217-272). A type rather than a
string parameter for two reasons: it moves the length and character checks to
the moment the key is supplied, rather than to the middle of a handshake, and it gives the key
a ToString() that cannot leak it.
ToString() is redacted, and that is load-bearing. An API key reaches a log,
an exception message, or a crash dump through exactly one route: something formatted the
object that holds it. Upstream redacts its Debug impl for the same reason — though it
then interpolates the whole key into an error! line when the key is not ASCII
(lib.rs:250). That one is not ported: an invalid key is still a key, and it is very
often a valid key for a different account.
Constructors
ApiKey(string)
Validates key and wraps it.
public ApiKey(string key)
Parameters
keystringThe API key.
Exceptions
- ArgumentNullException
keyis null.- ArgumentException
The key is the documentation placeholder, is not exactly Length characters, or contains a non-ASCII character. The message never contains the key itself.
Fields
BucketIdLength
The number of trailing characters of a key that form its bucket id.
public const int BucketIdLength = 5
Field Value
Length
The exact length of a Databento API key, in ASCII characters.
public const int Length = 32
Field Value
Placeholder
The placeholder that appears in Databento's own documentation and sample code. Rejected by name, because "expected 32 characters, got 13" would send a reader looking for a typo rather than for the line they forgot to fill in.
public const string Placeholder = "$YOUR_API_KEY"
Field Value
Properties
BucketId
The last BucketIdLength characters of the key, which the gateway uses to find it. Safe to log: it identifies the key without being usable as one.
public string BucketId { get; }
Property Value
Value
The key itself. Only the CRAM handshake needs this — everything else should use BucketId or ToString().
public string Value { get; }
Property Value
Methods
ToString()
The key with everything but its bucket id elided — …iller. Never the whole key.
public override string ToString()
Returns
- string
The redacted form.