Skip to content

Commit

Permalink
Add setting to enable atomic deployment; by default dont send header
Browse files Browse the repository at this point in the history
  • Loading branch information
emdoyle committed Aug 20, 2024
1 parent cce88e3 commit d4282ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
13 changes: 3 additions & 10 deletions pkg/pare/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions pkg/pare/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 3 additions & 9 deletions pkg/pare/sdk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions pkg/pare/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit d4282ed

Please sign in to comment.