here.platform.environment

Source code for here.platform.environment

Copyright (C) 2020-2022 HERE Global B.V. and its affiliate(s).

All rights reserved.

This software and other materials contain proprietary information

controlled by HERE and are protected by applicable copyright legislation.

Any use and utilization of this software and other materials and

disclosure to any third parties is conditional upon having a separate

agreement with HERE for the access, use, utilization or disclosure of this

software. In the absence of such agreement, the use of the software is not

allowed.

"""Environment module

This module defines the different platform environments supported.
Users can select the platform environment using enum, or by setting environment variable.
"""

import enum
import os

from here.platform.exceptions import ConfigException

[docs]
class Environment(enum.Enum):
"""
Environment enum defines the different platform environment supported.
Environment: Default, Local.

Private environments are provided for eu-west-1 and us-west-2 AWS regions. These may be used
when available, such as through VPC peering or Aether firewall rules, for less expensive data
transfer compared to the public endpoints which will be routed as public Internet traffic.
Note that only catalogs hosted in the same region will be accessible.
"""

DEFAULT = 1

INTERNAL = 2 # former SIT env is decommissioned

CHINA = 3 # HERE stopped China offering

LOCAL = 4
PRIVATE_EU_WEST_1 = 5 # Private endpoint in eu-west-1 AWS region.
PRIVATE_US_WEST_2 = 6 # Private endpoint in us-west-2 AWS region.

[docs]
@classmethod
def from_default(cls) -> "Environment":
"""
Return the Environment from default.

If environmental variable is set, this value will override the default value.

:return: environment
"""
try:
environment = cls.from_env_variable()
except ConfigException:
environment = Environment.DEFAULT
return environment

[docs]
@classmethod
def from_env_variable(cls) -> "Environment":
"""
Return the Environment from environment variable.

Expected variable name: HERE_ENVIRONMENT.
:return: environment
:raises ConfigException: Missing environmental variable
"""
env_variable_key = "HERE_ENVIRONMENT"
environment = os.environ.get(env_variable_key)
if environment:
try:
return Environment[environment.upper()]
except KeyError:
raise ConfigException(
"Erroneous environmental variable: ".format(",".join(env_variable_key))
)
else:
raise ConfigException(
"Environmental variable not set: ".format(",".join(env_variable_key))
)