Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Remove storage key dependency from deployment script (#3574)
Browse files Browse the repository at this point in the history
* add

* Removing storage account key dependency.

* Remove comments.

* lint

* Setting deploy.

* removing static.

* Trying different sort.

* Reordering.

* Resetting.
  • Loading branch information
nharper285 authored Oct 17, 2023
1 parent 7afe06a commit 679309a
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions src/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ def __init__(
"authority": "",
}

self.func_name = ""
self.func_id = ""
self.func_key = ""
self.fuzz_name = ""
self.fuzz_id = ""
self.fuzz_key = ""

machine = platform.machine()
system = platform.system()

Expand Down Expand Up @@ -701,6 +708,7 @@ def deploy_template(self) -> None:
mode=DeploymentMode.incremental, template=template, parameters=params
)
)

count = 0
tries = 10
error: Optional[Exception] = None
Expand Down Expand Up @@ -784,8 +792,8 @@ def assign_user_access(self) -> None:

def apply_migrations(self) -> None:
logger.info("applying database migrations")
name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
name = self.func_name
key = self.func_key
table_service = TableService(account_name=name, account_key=key)
migrate(table_service, self.migrations)

Expand Down Expand Up @@ -826,8 +834,8 @@ def parse_config(self) -> None:

def set_instance_config(self) -> None:
logger.info("setting instance config")
name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
name = self.func_name
key = self.func_key
tenant = UUID(self.results["deploy"]["tenant_id"]["value"])
table_service = TableService(account_name=name, account_key=key)

Expand All @@ -853,30 +861,36 @@ def event_subscription_exists(
except ResourceNotFoundError:
return False

@staticmethod
def get_storage_account_id(
client: StorageManagementClient, resource_group: str, prefix: str
) -> Optional[str]:
def set_storage_account_key(self) -> None:
logger.info("setting storage keys")
credential = AzureCliCredential()
client = StorageManagementClient(
credential, subscription_id=self.get_subscription_id()
)
try:
storage_accounts = client.storage_accounts.list_by_resource_group(
resource_group
self.resource_group
)
for storage_account in storage_accounts:
if storage_account.name.startswith(prefix):
return str(storage_account.id)
return None
keys = client.storage_accounts.list_keys(
self.resource_group, storage_account.name
)
if storage_account.name.startswith("func"):
self.func_id = storage_account.id
self.func_name = storage_account.name
self.func_key = keys.keys[0].value
if storage_account.name.startswith("fuzz"):
self.fuzz_id = storage_account.id
self.fuzz_name = storage_account.name
self.fuzz_key = keys.keys[0].value

except ResourceNotFoundError:
return None
logger.error("failed to retrieve storage account keys")

def remove_eventgrid(self) -> None:
credential = AzureCliCredential()
storage_account_client = StorageManagementClient(
credential, subscription_id=self.get_subscription_id()
)

src_resource_id = Client.get_storage_account_id(
storage_account_client, self.resource_group, "fuzz"
)
src_resource_id = self.fuzz_id
if not src_resource_id:
return

Expand All @@ -903,8 +917,8 @@ def add_instance_id(self) -> None:

container_name = "base-config"
blob_name = "instance_id"
account_name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
account_name = self.func_name
key = self.func_key
account_url = "https://%s.blob.core.windows.net" % account_name
client = BlobServiceClient(account_url, credential=key)
if container_name not in [x["name"] for x in client.list_containers()]:
Expand All @@ -929,8 +943,8 @@ def add_log_export(self) -> None:
container_name = "app-insights"

logger.info("adding appinsight log export")
account_name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
account_name = self.func_name
key = self.func_key
account_url = "https://%s.blob.core.windows.net" % account_name
client = BlobServiceClient(account_url, credential=key)
if container_name not in [x["name"] for x in client.list_containers()]:
Expand Down Expand Up @@ -989,8 +1003,8 @@ def add_log_export(self) -> None:

def upload_tools(self) -> None:
logger.info("uploading tools from %s", self.tools)
account_name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
account_name = self.func_name
key = self.func_key
account_url = "https://%s.blob.core.windows.net" % account_name
client = BlobServiceClient(account_url, credential=key)
if "tools" not in [x["name"] for x in client.list_containers()]:
Expand Down Expand Up @@ -1026,8 +1040,8 @@ def upload_tools(self) -> None:

def upload_instance_setup(self) -> None:
logger.info("uploading instance-specific-setup from %s", self.instance_specific)
account_name = self.results["deploy"]["func_name"]["value"]
key = self.results["deploy"]["func_key"]["value"]
account_name = self.func_name
key = self.func_key
account_url = "https://%s.blob.core.windows.net" % account_name
client = BlobServiceClient(account_url, credential=key)
if "instance-specific-setup" not in [
Expand Down Expand Up @@ -1072,8 +1086,8 @@ def upload_instance_setup(self) -> None:

def upload_third_party(self) -> None:
logger.info("uploading third-party tools from %s", self.third_party)
account_name = self.results["deploy"]["fuzz_name"]["value"]
key = self.results["deploy"]["fuzz_key"]["value"]
account_name = self.fuzz_name
key = self.fuzz_key
account_url = "https://%s.blob.core.windows.net" % account_name

client = BlobServiceClient(account_url, credential=key)
Expand Down Expand Up @@ -1206,6 +1220,7 @@ def main() -> None:
]

full_deployment_states = rbac_only_states + [
("set_storage_keys", Client.set_storage_account_key),
("apply_migrations", Client.apply_migrations),
("set_instance_config", Client.set_instance_config),
("tools", Client.upload_tools),
Expand Down

0 comments on commit 679309a

Please sign in to comment.