Skip to main content

Platform

Enum Platform 

Source
#[non_exhaustive]
pub enum Platform { Prod, ProdAz, ProdLz, NpLz, Poc, Custom { realm: String, endpoint_management_api: String, endpoint_management_api_token: String, endpoint_protocol_access_token: String, endpoint_protocol_rest_token: String, }, }
Expand description

Represents an available DSH platform and its related metadata.

The platform defined are:

  • Prod (kpn-dsh.com)
  • ProdAz (az.kpn-dsh.com)
  • ProdLz (dsh-prod.dsh.prod.aws.kpn.com)
  • NpLz (dsh-dev.dsh.np.aws.kpn.com)
  • Poc (poc.kpn-dsh.com)
  • Custom (for user-defined platforms)

Each platform has it’s own realm, endpoint for the DSH Rest API and endpoint for the DSH Rest API access token.

§Usage

Use a Platform variant to generate appropriate URLs and client IDs for your environment. For example, you might select Platform::NpLz when deploying a service to the development landing zone.

You can also create a Platform::Custom by providing the necessary endpoints and realm.

Use the from_env method to automatically determine the platform based on the DSH_PLATFORM environment variable, which can be configured in a DSH Service Confifguration like this:

{
...
   "env": {
     "DSH_ENVIRONMENT": "{ variables('DSH_ENVIRONMENT')}"
   },
...
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Prod

Production platform (kpn-dsh.com).

§

ProdAz

Production platform on Azure (az.kpn-dsh.com).

§

ProdLz

Production Landing Zone on AWS (dsh-prod.dsh.prod.aws.kpn.com).

§

NpLz

Non-Production (Dev) Landing Zone on AWS (dsh-dev.dsh.np.aws.kpn.com).

§

Poc

Proof of Concept platform (poc.kpn-dsh.com).

§

Custom

Custom platform, not predefined.

Fields

§realm: String

Realm name for the platform (e.g.“poc-dsh”).

§endpoint_management_api: String

Endpoint for the DSH Management API (e.g. “https://api.poc.kpn-dsh.com/resources/v0”).

§endpoint_management_api_token: String

Endpoint for fetching a DSH Management API authentication token. (e.g. “https://auth.prod.cp.kpn-dsh.com/auth/realms/poc-dsh/protocol/openid-connect/token”).

§endpoint_protocol_access_token: String

Endpoint for fetching DSH protocol Access Tokens (e.g. “https://api.poc.kpn-dsh.com/datastreams/v0/mqtt/token”).

§endpoint_protocol_rest_token: String

Endpoint for retrieving Protocol Rest Tokens which is needed to request Access Tokens (e.g. “https://api.poc.kpn-dsh.com/auth/v0/token”).

Implementations§

Source§

impl Platform

Source

pub fn management_api_client_id(&self, tenant: impl AsRef<str>) -> String

Returns a properly formatted client ID for the DSH Management API, given a tenant name.

The format is:
[ "robot:{realm}:{tenant_name}" ]

§Example
let platform = Platform::NpLz;
let client_id = platform.management_api_client_id("my-tenant");
assert_eq!(client_id, "robot:dev-lz-dsh:my-tenant");
Source

pub fn endpoint_management_api(&self) -> &str

Returns the endpoint for the DSH Management API

It will return the endpoint for the DSH Rest API based on the platform

§Example
let platform = Platform::NpLz;
let endpoint = platform.endpoint_management_api();
assert_eq!(endpoint, "https://api.dsh-dev.dsh.np.aws.kpn.com/resources/v0");
Source

pub fn http_protocol_base_url(&self) -> String

Returns the base URL for the platform, stripping /resources/v0 if present.

Source

pub fn endpoint_management_api_token(&self) -> &str

Returns the endpoint for fetching a DSH Management API authentication token.

This endpoint is typically used to authenticate requests to certain management or admin-level DSH services.

§Example
let platform = Platform::NpLz;
let mgmt_token_url = platform.endpoint_management_api_token();
assert_eq!(mgmt_token_url, "https://auth.prod.cp-prod.dsh.prod.aws.kpn.com/auth/realms/dev-lz-dsh/protocol/openid-connect/token");
Source

pub fn endpoint_protocol_access_token(&self) -> &str

Returns the endpoint for fetching DSH protocol Data Access Tokens (e.g., for MQTT).

§Example
let platform = Platform::Prod;
let protocol_token_url = platform.endpoint_protocol_access_token();
assert_eq!(protocol_token_url, "https://api.kpn-dsh.com/datastreams/v0/mqtt/token");
Source

pub fn endpoint_protocol_rest_token(&self) -> &str

Returns the URL endpoint for retrieving DSH REST API OAuth tokens to fetch Data Access Tokens.

§Example
let platform = Platform::NpLz;
let token_url = platform.endpoint_protocol_rest_token();
assert_eq!(token_url, "https://api.dsh-dev.dsh.np.aws.kpn.com/auth/v0/token");
Source

pub fn realm(&self) -> &str

Returns the Keycloak realm string associated with this platform.

This is used to construct OpenID Connect tokens (e.g., for Kafka or REST API authentication).

§Example
let realm = Platform::Prod.realm();
assert_eq!(realm, "prod-dsh");
Source

pub fn from_env() -> Result<Self, UtilsError>

Creates a Platform instance based on the DSH_ENVIRONMENT environment variable.

In you DSH Service Configuration, you can set the DSH_ENVIRONMENT variable like this

{
...
  "env": {
    "DSH_ENVIRONMENT": "{ variables('DSH_ENVIRONMENT')}"
  },
...
}
§Custom Platform

If you want to use a custom platform, you can set the DSH_ENVIRONMENT to custom which whill try to instantiate a Platform::Custom. Set the following environment variables to set the endpoints and realm:

Variable NameDescriptionRequired
DSH_ENVIRONMENTSet to customYes
DSH_REALMThe realm name for the to be used platformYes
DSH_ENDPOINT_MANAGEMENT_APIThe endpoint for the DSH Management APINo
DSH_ENDPOINT_MANAGEMENT_API_TOKENThe endpoint for fetching a DSH Management API authentication tokenNo
DSH_ENDPOINT_PROTOCOL_ACCESS_TOKENThe endpoint for fetching DSH protocol Access TokensNo
DSH_ENDPOINT_PROTOCOL_REST_TOKENThe endpoint for retrieving Protocol Rest Tokens which is needed to request Access TokensNo

The endpoint variables are optional, if not set, the related token fetchers will not work.

Trait Implementations§

Source§

impl Clone for Platform

Source§

fn clone(&self) -> Platform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Platform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Platform

Source§

fn eq(&self, other: &Platform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for Platform

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Platform

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for Platform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,