Skip to content

Commit

Permalink
[gcp] Allow updating config
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Jul 29, 2021
1 parent f8c3843 commit f23f64e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
22 changes: 18 additions & 4 deletions sebs/gcp/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import cast
from typing import cast, List, Tuple

from sebs.cache import Cache
from sebs.faas.config import Config, Credentials, Resources
Expand Down Expand Up @@ -177,13 +177,27 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> "Confi
config_obj = GCPConfig(credentials, resources)
config_obj.logging_handlers = handlers
if cached_config:
config_obj.logging.info("Using cached config for GCP")
config_obj.logging.info("Loading cached config for GCP")
GCPConfig.initialize(config_obj, cached_config)
else:
config_obj.logging.info("Using user-provided config for GCP")
GCPConfig.initialize(config_obj, config)
cache.update_config(val=config_obj.region, keys=["gcp", "region"])
cache.update_config(val=config_obj.project_name, keys=["gcp", "project_name"])

# mypy makes a mistake here
updated_keys: List[Tuple[str, Tuple[str]]] = [
["region", ["gcp", "region"]], # type: ignore
["project_name", ["gcp", "project_name"]], # type: ignore
]
for config_key, keys in updated_keys:

old_value = getattr(config_obj, config_key)
if getattr(config_obj, config_key) != config[config_key]:
config_obj.logging.info(
f"Updating cached key {config_key} with {old_value} "
f"to user-provided value {config[config_key]}."
)
setattr(config_obj, f"_{config_key}", config[config_key])
cache.update_config(val=getattr(config_obj, config_key), keys=keys)

return config_obj

Expand Down
2 changes: 1 addition & 1 deletion sebs/gcp/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_storage(
buckets=None,
) -> PersistentStorage:
if not self.storage:
self.storage = GCPStorage(self.cache_client, replace_existing)
self.storage = GCPStorage(self.config.region, self.cache_client, replace_existing)
self.storage.logging_handlers = self.logging_handlers
else:
self.storage.replace_existing = replace_existing
Expand Down
4 changes: 2 additions & 2 deletions sebs/gcp/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def replace_existing(self) -> bool:
def replace_existing(self, val: bool):
self._replace_existing = val

def __init__(self, cache_client: Cache, replace_existing: bool):
super().__init__(cache_client, replace_existing)
def __init__(self, region: str, cache_client: Cache, replace_existing: bool):
super().__init__(region, cache_client, replace_existing)
self.replace_existing = replace_existing
self.client = gcp_storage.Client()
self.cached = False
Expand Down

0 comments on commit f23f64e

Please sign in to comment.