diff --git a/pkg/pare/cli/deploy.py b/pkg/pare/cli/deploy.py index c80a889..9633fbd 100644 --- a/pkg/pare/cli/deploy.py +++ b/pkg/pare/cli/deploy.py @@ -24,22 +24,15 @@ def __init__( self, file_paths: list[str], environment_variables: dict[str, str] | None = None, - deploy_url: str | None = None, - api_key: str | None = None, ) -> None: self.file_paths = {Path(file_path) for file_path in file_paths} self.environment_variables = environment_variables or {} - self.deploy_url = deploy_url or ( - f"{settings.PARE_API_URL}/{settings.PARE_API_VERSION}{settings.PARE_API_DEPLOY_URL_PATH}" - ) - self.api_key = api_key or settings.PARE_API_KEY - self.git_hash = get_current_git_hash() + self.deploy_url = f"{settings.PARE_API_URL}/{settings.PARE_API_VERSION}{settings.PARE_API_DEPLOY_URL_PATH}" @property def headers(self) -> dict[str, str]: return { - settings.PARE_API_KEY_HEADER: self.api_key, - settings.PARE_ATOMIC_DEPLOYMENT_HEADER: self.git_hash, + settings.PARE_API_KEY_HEADER: settings.PARE_API_KEY, } def validate_file_paths(self) -> None: @@ -126,7 +119,7 @@ def deploy(self): self.validate_file_paths() services = self.register_services() deploy_config = DeployConfig( - git_hash=self.git_hash, + git_hash=get_current_git_hash(), python_version=PYTHON_VERSION, services=services, environment_variables=self.environment_variables, diff --git a/pkg/pare/client.py b/pkg/pare/client.py index 2d42332..795acf1 100644 --- a/pkg/pare/client.py +++ b/pkg/pare/client.py @@ -33,3 +33,10 @@ def get_current_git_hash() -> str: except subprocess.CalledProcessError: log_error("Pare failed to get the current git hash.") sys.exit(1) + + +def get_client_headers() -> dict[str, str]: + headers = {settings.PARE_API_KEY_HEADER: settings.PARE_API_KEY} + if settings.PARE_ATOMIC_DEPLOYMENT_ENABLED: + headers[settings.PARE_ATOMIC_DEPLOYMENT_HEADER] = get_current_git_hash() + return headers diff --git a/pkg/pare/sdk/main.py b/pkg/pare/sdk/main.py index f27bb63..1c2598b 100644 --- a/pkg/pare/sdk/main.py +++ b/pkg/pare/sdk/main.py @@ -9,7 +9,7 @@ from typing_extensions import ParamSpec from pare import errors, settings -from pare.client import get_current_git_hash +from pare.client import get_client_headers from pare.models import ServiceRegistration @@ -23,10 +23,7 @@ def invoke_endpoint(function_name: str, arguments: RemoteInvocationArguments) -> try: response = requests.post( f"{settings.PARE_API_URL}/{settings.PARE_API_VERSION}{settings.PARE_API_INVOKE_URL_PATH}{function_name}/", - headers={ - settings.PARE_API_KEY_HEADER: settings.PARE_API_KEY, - settings.PARE_ATOMIC_DEPLOYMENT_HEADER: get_current_git_hash(), - }, + headers=get_client_headers(), json=json.dumps(asdict(arguments)), ) response.raise_for_status() @@ -48,10 +45,7 @@ async def async_invoke_endpoint( try: async with session.post( f"{settings.PARE_API_URL}/{settings.PARE_API_VERSION}/invoke/{function_name}/", - headers={ - settings.PARE_API_KEY_HEADER: settings.PARE_API_KEY, - settings.PARE_ATOMIC_DEPLOYMENT_HEADER: get_current_git_hash(), - }, + headers=get_client_headers(), json=json.dumps(asdict(arguments)), ) as response: response.raise_for_status() diff --git a/pkg/pare/settings.py b/pkg/pare/settings.py index 22cc0f1..1fbfd2b 100644 --- a/pkg/pare/settings.py +++ b/pkg/pare/settings.py @@ -24,11 +24,12 @@ PARE_API_KEY = pare_api_key_path.read_text() PARE_API_KEY_HEADER: str = env.str("PARE_API_KEY_HEADER", "X-Pare-API-Key") + + +PARE_ATOMIC_DEPLOYMENT_ENABLED: bool = env.bool("PARE_ATOMIC_DEPLOYMENT_ENABLED", False) PARE_ATOMIC_DEPLOYMENT_HEADER: str = env.str( "PARE_ATOMIC_DEPLOYMENT_HEADER", "X-Pare-Atomic-Deployment" ) - - PARE_GIT_HASH: str = env.str("PARE_GIT_HASH", "") _KNOWN_GIT_HASH_ENV_VARS = [