#[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
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
endpoint_management_api: StringEndpoint for the DSH Management API (e.g. “https://api.poc.kpn-dsh.com/resources/v0”).
endpoint_management_api_token: StringEndpoint 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: StringEndpoint for fetching DSH protocol Access Tokens (e.g. “https://api.poc.kpn-dsh.com/datastreams/v0/mqtt/token”).
endpoint_protocol_rest_token: StringEndpoint 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
impl Platform
Sourcepub fn management_api_client_id(&self, tenant: impl AsRef<str>) -> String
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");Sourcepub fn endpoint_management_api(&self) -> &str
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");Sourcepub fn http_protocol_base_url(&self) -> String
pub fn http_protocol_base_url(&self) -> String
Returns the base URL for the platform, stripping /resources/v0 if present.
Sourcepub fn endpoint_management_api_token(&self) -> &str
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");Sourcepub fn endpoint_protocol_access_token(&self) -> &str
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");Sourcepub fn endpoint_protocol_rest_token(&self) -> &str
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");Sourcepub fn realm(&self) -> &str
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");Sourcepub fn from_env() -> Result<Self, UtilsError>
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 Name | Description | Required |
|---|---|---|
DSH_ENVIRONMENT | Set to custom | Yes |
DSH_REALM | The realm name for the to be used platform | Yes |
DSH_ENDPOINT_MANAGEMENT_API | The endpoint for the DSH Management API | No |
DSH_ENDPOINT_MANAGEMENT_API_TOKEN | The endpoint for fetching a DSH Management API authentication token | No |
DSH_ENDPOINT_PROTOCOL_ACCESS_TOKEN | The endpoint for fetching DSH protocol Access Tokens | No |
DSH_ENDPOINT_PROTOCOL_REST_TOKEN | The endpoint for retrieving Protocol Rest Tokens which is needed to request Access Tokens | No |
The endpoint variables are optional, if not set, the related token fetchers will not work.