Skip to main content

source_token

Function source_token 

Source
fn source_token(
    source_id: Option<&str>,
    labjack_name: Option<&str>,
    asset: Option<u32>,
) -> String
Expand description

Picks the source token shared by every structured subject.

The first of source_id, labjack_name and asset<NNN> that is present is used, passed through sanitize_token. Live channel subjects, the stream wildcard and the export request subject all go through this function, so a config without identity fields still produces a stream that matches its own channels and an export subject that the webapp can find. The webapp (webapp/src/lib/subjects.ts) uses the same order. unknown-source is only used when there is no asset number either, which can happen for the exporter when neither SOURCE_ID, LABJACK_NAME nor ASSET_NUMBER is set.

§Arguments

  • source_id - Configured source ID, if any.
  • labjack_name - LabJack name, if any.
  • asset - Asset number, if known.

§Examples

(Some("i69-lj2"), Some("Unit A"), Some(42)) -> "i69-lj2"
(None, Some("Unit A"), Some(42))            -> "unit-a"
(None, None, Some(42))                      -> "asset042"
(None, None, None)                          -> "unknown-source"