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

ipi-onprem-getting-started.rs File Reference

Classes

struct  ExampleOptions
 Options the example runs with. More...

Functions

const pub struct ExampleOptions with_files (data_files:Vec< PathBuf >) -> Self
 Build options that look [IPS] up in each of data_files.
pub fn from_env () -> Option< Self >
 Build the default options through the shared resolver.
pub fn for_tier (tier:examples_shared::IpiTier) -> Option< Self >
 Build options pinned to a specific data-file tier.
const pub fn run (options:&ExampleOptions, out:&mut dyn Write) -> anyhow::Result<()>
 Run the getting-started example against the supplied options, writing all output to out.
fn look_up (data_file:&std::path::Path, ips:&[String], available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Build a pipeline over data_file, whose properties are available, and look each of ips up in it.
fn analyse_ip (pipeline:&Arc< Pipeline >, ip:&str, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Look one IP address up and print its properties.
fn needs_enterprise (name:&str, available:&[String]) -> bool
 Whether name is an Enterprise property the data file in use does not carry, in which case its line says so in place of a value.
fn output_string (name:&str, property:&AspectPropertyValue< String >, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Print a plain string property, or the no-value message when it is absent.
fn output_float (name:&str, property:&AspectPropertyValue< f32 >, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Print a plain floating-point property (latitude, longitude).
fn output_integer (name:&str, property:&AspectPropertyValue< i32 >, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Print a plain integer property (time-zone offset, accuracy radius).
fn output_bool (name:&str, property:&AspectPropertyValue< bool >, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Print a plain boolean property (the network flags), as true/false.
fn output_weighted (name:&str, property:&AspectPropertyValue< Vec< WeightedValue< String > > >, available:&[String], out:&mut dyn Write,) -> anyhow::Result<()>
 Print a weighted property (the country-code distributions, Mcc) as a comma-separated list of value (weight) candidates ordered most probable first, or the no-value message when it is absent.
fn main () -> anyhow::Result<()>
 Read the data file, then run the example, writing to standard output.
fn getting_started_runs_against_the_asn_file ()
 The example runs end to end against the real ASN data file and prints at least one autonomous-system value.

Variables

const CONTACT_US_URL
 Where to ask about a copy of the Enterprise data file.
const & str
const IPS
 The addresses the example looks up, a public Cloudflare IPv4 and IPv6.
pub data_files
 The full paths to the .ipi data files to open, each looked up in turn.
pub pub ips
 The IP addresses to look up, as client-IP evidence values.
const DISPLAYED_PROPERTIES
 Every property this example reads back and prints.
const AsnName
const RegisteredName
const RegisteredOwner
const RegisteredCountry
const IpRangeStart
const IpRangeEnd
const Country
const CountryCode
const State
const Town
const Latitude
const Longitude
const TimeZoneOffset
const AccuracyRadiusMin
const IsHosted
const IsVPN
const CountryCodesGeographical
const CountryCodesPopulation
const Mcc
mod tests

Function Documentation

◆ analyse_ip()

fn analyse_ip ( pipeline:&Arc< Pipeline > ,
ip:& str,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Look one IP address up and print its properties.

available holds the properties the data file carries.

◆ for_tier()

pub fn for_tier ( tier:examples_shared::IpiTier ) -> Option< Self >

Build options pinned to a specific data-file tier.

main reads the Enterprise file or both free files, while the test pins to the ASN tier so it runs deterministically against the small, current, always-loadable ASN file rather than depending on the production Enterprise share being mounted.

◆ from_env()

pub fn from_env ( ) -> Option< Self >

Build the default options through the shared resolver.

A file named by _51DEGREES_IPI_PATH, or the Enterprise file when its share is reachable, is read alone. Otherwise both free files from the data repository are read, each downloaded when it is missing, being the ASN file for Asn and AsnName and the Lite file for the registered properties.

Returns [None] when no usable data file can be located, so the caller can report it rather than panicking.

◆ getting_started_runs_against_the_asn_file()

fn getting_started_runs_against_the_asn_file ( )

The example runs end to end against the real ASN data file and prints at least one autonomous-system value.

It skips cleanly when no data file is present, so a plain cargo test stays green offline.

The test pins the ASN tier so it always exercises the small, current, always-loadable ASN file, independent of whether the production Enterprise share happens to be mounted on the build machine.

◆ look_up()

fn look_up ( data_file:&std::path::Path ,
ips:& [String],
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Build a pipeline over data_file, whose properties are available, and look each of ips up in it.

◆ main()

fn main ( ) -> anyhow::Result<()>

Read the data file, then run the example, writing to standard output.

An optional command-line argument overrides the data-file path the shared resolver would otherwise pick.

◆ needs_enterprise()

fn needs_enterprise ( name:& str,
available:& [String] ) -> bool

Whether name is an Enterprise property the data file in use does not carry, in which case its line says so in place of a value.

◆ output_bool()

fn output_bool ( name:& str,
property:&AspectPropertyValue< bool > ,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Print a plain boolean property (the network flags), as true/false.

◆ output_float()

fn output_float ( name:& str,
property:&AspectPropertyValue< f32 > ,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Print a plain floating-point property (latitude, longitude).

◆ output_integer()

fn output_integer ( name:& str,
property:&AspectPropertyValue< i32 > ,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Print a plain integer property (time-zone offset, accuracy radius).

◆ output_string()

fn output_string ( name:& str,
property:&AspectPropertyValue< String > ,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Print a plain string property, or the no-value message when it is absent.

◆ output_weighted()

fn output_weighted ( name:& str,
property:&AspectPropertyValue< Vec< WeightedValue< String > > > ,
available:& [String],
out:&mut dyn Write ) -> anyhow::Result<()>

Print a weighted property (the country-code distributions, Mcc) as a comma-separated list of value (weight) candidates ordered most probable first, or the no-value message when it is absent.

◆ run()

const pub fn run ( options:& ExampleOptions,
out:&mut dyn Write ) -> anyhow::Result<()>

Run the getting-started example against the supplied options, writing all output to out.

Builds an on-premise IP Intelligence pipeline for each data file, looks up each IP and prints the results. The pipeline is built with usage sharing left off, because this is a console example. A production deployment that wants to help improve the data should enable it (see the engine builder's share_usage equivalent on the cloud/web side). The output ends with the Enterprise properties no file carried, where to ask about a copy of the Enterprise data file, and the "Find out more" links.

◆ with_files()

const pub struct ExampleOptions with_files ( data_files:Vec< PathBuf > ) -> Self

Build options that look [IPS] up in each of data_files.

Variable Documentation

◆ AccuracyRadiusMin

const AccuracyRadiusMin

◆ AsnName

const AsnName

◆ CONTACT_US_URL

const CONTACT_US_URL

Where to ask about a copy of the Enterprise data file.

◆ Country

const Country

◆ CountryCode

const const CountryCode

◆ CountryCodesGeographical

const CountryCodesGeographical

◆ CountryCodesPopulation

const CountryCodesPopulation

◆ data_files

pub data_files

The full paths to the .ipi data files to open, each looked up in turn.

◆ DISPLAYED_PROPERTIES

const DISPLAYED_PROPERTIES

Every property this example reads back and prints.

The on-premise engine narrows itself to the properties it is asked for, so the example must request the whole set it displays. Requesting only Asn and AsnName (which an ASN file carries beyond the curated typed set) would drop the registered-range and location properties, leaving them unset even with an Enterprise data file that carries them. Listing them all keeps every column populated when the data file has the value.

◆ IpRangeEnd

const IpRangeEnd

◆ IpRangeStart

const IpRangeStart

◆ IPS

const IPS

The addresses the example looks up, a public Cloudflare IPv4 and IPv6.

Both resolve to a real autonomous system in the ASN data file, so the example always has something to print.

◆ ips

pub pub ips

The IP addresses to look up, as client-IP evidence values.

◆ IsHosted

const IsHosted

◆ IsVPN

const IsVPN

◆ Latitude

const Latitude

◆ Longitude

const Longitude

◆ Mcc

const Mcc

◆ RegisteredCountry

const RegisteredCountry

◆ RegisteredName

const RegisteredName

◆ RegisteredOwner

const RegisteredOwner

◆ State

use axum::extract::State

◆ str

const & str
Initial value:
= &[
("IP Intelligence", "/ip-intelligence?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-getting-started.rs&utm_term=find-out-more"),
("Pricing", "/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-getting-started.rs&utm_term=find-out-more"),
("Documentation", "/documentation/index.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-ip-intelligence-examples-src-bin-ipi-onprem-getting-started.rs&utm_term=find-out-more"),
]

◆ tests

mod tests
Initial value:
{
use super::*

◆ TimeZoneOffset

const TimeZoneOffset

◆ Town

const Town