Device Detection and IP Intelligence for the 51Degrees Pipeline, in Rust

keys.rs File Reference

Functions

pub fn resource_key_from_env () -> Option< String >
 Read a cloud resource key from the environment.
pub fn license_key_from_env () -> Option< String >
 Read a licence key from [LICENSE_KEY_ENV_VAR], trimmed of surrounding whitespace.
fn non_blank_env (name:&str) -> Option< String >
 Read name from the environment, returning the trimmed value only when it is present and not blank (a null-or-whitespace value is rejected).
pub fn is_invalid_key (key:&str) -> bool
 Report whether key is definitely an invalid resource or license key.
fn clear_all ()
fn returns_none_when_unset ()
fn aligned_name_wins_over_tiered ()
fn a_license_key_is_read_trimmed ()
fn a_license_key_of_only_spaces_is_unset ()
fn the_name_checked_first_can_be_exported ()
fn falls_back_through_the_chain ()
fn blank_value_is_skipped ()
fn obvious_placeholders_are_invalid ()
fn plausible_key_is_not_flagged_invalid ()

Variables

use base64::Engine as _
pub const RESOURCE_KEY_ENV_VAR
 The resource-key environment variable, checked first.
pub const LICENSE_KEY_ENV_VAR
 The licence-key environment variable.
pub const CI_RESOURCE_KEY_BESPOKE_ENV_VAR
 The CI-exported bespoke-tier resource-key environment variable, checked second.
pub const CI_RESOURCE_KEY_BASIC_ENV_VAR
 The CI-exported basic-tier resource-key environment variable, checked last.
pub const RESOURCE_KEY_ENV_VARS
 The order in which the resource-key environment variables are consulted.
mod tests
static ENV_LOCK

Function Documentation

◆ a_license_key_is_read_trimmed()

fn a_license_key_is_read_trimmed ( )

◆ a_license_key_of_only_spaces_is_unset()

fn a_license_key_of_only_spaces_is_unset ( )

◆ aligned_name_wins_over_tiered()

fn aligned_name_wins_over_tiered ( )

◆ blank_value_is_skipped()

fn blank_value_is_skipped ( )

◆ clear_all()

fn clear_all ( )

◆ falls_back_through_the_chain()

fn falls_back_through_the_chain ( )

◆ is_invalid_key()

pub fn is_invalid_key ( key:& str) -> bool

Report whether key is definitely an invalid resource or license key.

This cannot confirm a key is valid, only that it is obviously not. A key is treated as invalid when any of the following holds:

  • it is empty or only whitespace,
  • its trimmed length is shorter than 19 characters,
  • it is not valid base64, or
  • its base64-decoded form is shorter than 14 bytes.

These catch the common placeholder cases (an empty value, a truncated paste, the literal text "!!YOUR_RESOURCE_KEY!!") before a request is attempted.

◆ license_key_from_env()

pub fn license_key_from_env ( ) -> Option< String >

Read a licence key from [LICENSE_KEY_ENV_VAR], trimmed of surrounding whitespace.

Returns None when the variable is unset or blank, so a value of only spaces counts as no key.

◆ non_blank_env()

fn non_blank_env ( name:& str) -> Option< String >

Read name from the environment, returning the trimmed value only when it is present and not blank (a null-or-whitespace value is rejected).

A renamed variable is also read under its deprecated name when name is unset or empty.

◆ obvious_placeholders_are_invalid()

fn obvious_placeholders_are_invalid ( )

◆ plausible_key_is_not_flagged_invalid()

fn plausible_key_is_not_flagged_invalid ( )

◆ resource_key_from_env()

pub fn resource_key_from_env ( ) -> Option< String >

Read a cloud resource key from the environment.

The variables in [RESOURCE_KEY_ENV_VARS] are checked in order and the first one set to a non-blank value is returned, trimmed of surrounding whitespace. Returns None when none is set (or all are blank), so a cloud example can print a clear "set a resource key" message rather than failing obscurely.

◆ returns_none_when_unset()

fn returns_none_when_unset ( )

◆ the_name_checked_first_can_be_exported()

fn the_name_checked_first_can_be_exported ( )

Variable Documentation

◆ _

use base64::Engine as _

Resolve a cloud resource key and a licence key from the environment, and the obvious-placeholder check.

Cloud examples and example tests read a 51Degrees resource key from the environment rather than hard-coding it. The resolver also consults the CI-exported tiered names so the same resolver works in a local shell and on the build agents.

Every name starts with an underscore because a POSIX shell cannot set a name that starts with a digit.

◆ CI_RESOURCE_KEY_BASIC_ENV_VAR

pub const CI_RESOURCE_KEY_BASIC_ENV_VAR

The CI-exported basic-tier resource-key environment variable, checked last.

◆ CI_RESOURCE_KEY_BESPOKE_ENV_VAR

pub const CI_RESOURCE_KEY_BESPOKE_ENV_VAR

The CI-exported bespoke-tier resource-key environment variable, checked second.

Preferred over the basic tier because a bespoke key is a superset: it grants the basic-tier properties too, so every cloud example and test resolves a working key from it, whereas a basic key would fail the paid-only examples.

◆ ENV_LOCK

ENV_LOCK
static

◆ LICENSE_KEY_ENV_VAR

pub const LICENSE_KEY_ENV_VAR

The licence-key environment variable.

◆ RESOURCE_KEY_ENV_VAR

pub const RESOURCE_KEY_ENV_VAR

The resource-key environment variable, checked first.

The leading underscore makes the name a valid shell identifier, so export _51DEGREES_RESOURCE_KEY=... works and every 51Degrees language reads the same name. An explicit value here (set by a developer or by CI) overrides every other source.

◆ RESOURCE_KEY_ENV_VARS

pub const RESOURCE_KEY_ENV_VARS

The order in which the resource-key environment variables are consulted.

An explicit _51DEGREES_RESOURCE_KEY wins, then the bespoke CI key (a superset of the basic one), then the basic CI key. The first variable set to a non-blank value supplies the key.

◆ tests

mod tests
Initial value:
{
use super::*