Skip to content

Commit

Permalink
refactor(parameters): Consistently reference env (#319)
Browse files Browse the repository at this point in the history
* refactor(parameters): Contistently reference env

Use the defined constants to look up service name environment varialbe

NOTE: This does not default to `service_undefined`

* chore: bump ci

* refactor: Apply suggestions from code review

Co-authored-by: Heitor Lessa <[email protected]>

* fix: Add missing import

* refactor: Use resolve_env_var_choice

Co-authored-by: Heitor Lessa <[email protected]>
  • Loading branch information
Michael Brewer and heitorlessa authored Mar 9, 2021
1 parent e961906 commit bc0b9cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions aws_lambda_powertools/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

from ..shared import constants
from ..shared.functions import resolve_truthy_env_var_choice
from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
from ..shared.lazy_import import LazyLoader
from .base import BaseProvider, BaseSegment

Expand Down Expand Up @@ -720,7 +720,7 @@ def __build_config(
):
""" Populates Tracer config for new and existing initializations """
is_disabled = disabled if disabled is not None else self._is_tracer_disabled()
is_service = service if service is not None else os.getenv(constants.SERVICE_NAME_ENV)
is_service = resolve_env_var_choice(choice=service, env=os.getenv(constants.SERVICE_NAME_ENV))

self._config["provider"] = provider or self._config["provider"] or aws_xray_sdk.core.xray_recorder
self._config["auto_patch"] = auto_patch if auto_patch is not None else self._config["auto_patch"]
Expand Down
7 changes: 6 additions & 1 deletion aws_lambda_powertools/utilities/parameters/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import boto3
from botocore.config import Config

from ...shared import constants
from ...shared.functions import resolve_env_var_choice
from .base import DEFAULT_PROVIDERS, BaseProvider

CLIENT_ID = str(uuid4())
Expand All @@ -33,6 +35,7 @@ class AppConfigProvider(BaseProvider):
**Retrieves the latest configuration value from App Config**
>>> from aws_lambda_powertools.utilities import parameters
>>>
>>> appconf_provider = parameters.AppConfigProvider(environment="my_env", application="my_app")
>>>
>>> value : bytes = appconf_provider.get("my_conf")
Expand Down Expand Up @@ -66,7 +69,9 @@ def __init__(

config = config or Config()
self.client = boto3.client("appconfig", config=config)
self.application = application or os.getenv("POWERTOOLS_SERVICE_NAME") or "application_undefined"
self.application = resolve_env_var_choice(
choice=application, env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined")
)
self.environment = environment
self.current_version = ""

Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ Here is the mapping between this utility's functions and methods and the underly
| Secrets Manager | `SecretsManager.get` | `secretsmanager` | [get_secret_value](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.get_secret_value) |
| DynamoDB | `DynamoDBProvider.get` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table)) | [get_item](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.get_item)
| DynamoDB | `DynamoDBProvider.get_multiple` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table)) | [query](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.query)
| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) |
| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) |

0 comments on commit bc0b9cc

Please sign in to comment.