@@ -197,6 +197,13 @@ def __init__(
197197 "authority" : "" ,
198198 }
199199
200+ self .func_name = ""
201+ self .func_id = ""
202+ self .func_key = ""
203+ self .fuzz_name = ""
204+ self .fuzz_id = ""
205+ self .fuzz_key = ""
206+
200207 machine = platform .machine ()
201208 system = platform .system ()
202209
@@ -701,6 +708,7 @@ def deploy_template(self) -> None:
701708 mode = DeploymentMode .incremental , template = template , parameters = params
702709 )
703710 )
711+
704712 count = 0
705713 tries = 10
706714 error : Optional [Exception ] = None
@@ -784,8 +792,8 @@ def assign_user_access(self) -> None:
784792
785793 def apply_migrations (self ) -> None :
786794 logger .info ("applying database migrations" )
787- name = self .results [ "deploy" ][ " func_name" ][ "value" ]
788- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
795+ name = self .func_name
796+ key = self .func_key
789797 table_service = TableService (account_name = name , account_key = key )
790798 migrate (table_service , self .migrations )
791799
@@ -826,8 +834,8 @@ def parse_config(self) -> None:
826834
827835 def set_instance_config (self ) -> None :
828836 logger .info ("setting instance config" )
829- name = self .results [ "deploy" ][ " func_name" ][ "value" ]
830- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
837+ name = self .func_name
838+ key = self .func_key
831839 tenant = UUID (self .results ["deploy" ]["tenant_id" ]["value" ])
832840 table_service = TableService (account_name = name , account_key = key )
833841
@@ -853,30 +861,36 @@ def event_subscription_exists(
853861 except ResourceNotFoundError :
854862 return False
855863
856- @staticmethod
857- def get_storage_account_id (
858- client : StorageManagementClient , resource_group : str , prefix : str
859- ) -> Optional [str ]:
864+ def set_storage_account_key (self ) -> None :
865+ logger .info ("setting storage keys" )
866+ credential = AzureCliCredential ()
867+ client = StorageManagementClient (
868+ credential , subscription_id = self .get_subscription_id ()
869+ )
860870 try :
861871 storage_accounts = client .storage_accounts .list_by_resource_group (
862- resource_group
872+ self . resource_group
863873 )
864874 for storage_account in storage_accounts :
865- if storage_account .name .startswith (prefix ):
866- return str (storage_account .id )
867- return None
875+ keys = client .storage_accounts .list_keys (
876+ self .resource_group , storage_account .name
877+ )
878+ if storage_account .name .startswith ("func" ):
879+ self .func_id = storage_account .id
880+ self .func_name = storage_account .name
881+ self .func_key = keys .keys [0 ].value
882+ if storage_account .name .startswith ("fuzz" ):
883+ self .fuzz_id = storage_account .id
884+ self .fuzz_name = storage_account .name
885+ self .fuzz_key = keys .keys [0 ].value
886+
868887 except ResourceNotFoundError :
869- return None
888+ logger . error ( "failed to retrieve storage account keys" )
870889
871890 def remove_eventgrid (self ) -> None :
872891 credential = AzureCliCredential ()
873- storage_account_client = StorageManagementClient (
874- credential , subscription_id = self .get_subscription_id ()
875- )
876892
877- src_resource_id = Client .get_storage_account_id (
878- storage_account_client , self .resource_group , "fuzz"
879- )
893+ src_resource_id = self .fuzz_id
880894 if not src_resource_id :
881895 return
882896
@@ -903,8 +917,8 @@ def add_instance_id(self) -> None:
903917
904918 container_name = "base-config"
905919 blob_name = "instance_id"
906- account_name = self .results [ "deploy" ][ " func_name" ][ "value" ]
907- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
920+ account_name = self .func_name
921+ key = self .func_key
908922 account_url = "https://%s.blob.core.windows.net" % account_name
909923 client = BlobServiceClient (account_url , credential = key )
910924 if container_name not in [x ["name" ] for x in client .list_containers ()]:
@@ -929,8 +943,8 @@ def add_log_export(self) -> None:
929943 container_name = "app-insights"
930944
931945 logger .info ("adding appinsight log export" )
932- account_name = self .results [ "deploy" ][ " func_name" ][ "value" ]
933- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
946+ account_name = self .func_name
947+ key = self .func_key
934948 account_url = "https://%s.blob.core.windows.net" % account_name
935949 client = BlobServiceClient (account_url , credential = key )
936950 if container_name not in [x ["name" ] for x in client .list_containers ()]:
@@ -989,8 +1003,8 @@ def add_log_export(self) -> None:
9891003
9901004 def upload_tools (self ) -> None :
9911005 logger .info ("uploading tools from %s" , self .tools )
992- account_name = self .results [ "deploy" ][ " func_name" ][ "value" ]
993- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
1006+ account_name = self .func_name
1007+ key = self .func_key
9941008 account_url = "https://%s.blob.core.windows.net" % account_name
9951009 client = BlobServiceClient (account_url , credential = key )
9961010 if "tools" not in [x ["name" ] for x in client .list_containers ()]:
@@ -1026,8 +1040,8 @@ def upload_tools(self) -> None:
10261040
10271041 def upload_instance_setup (self ) -> None :
10281042 logger .info ("uploading instance-specific-setup from %s" , self .instance_specific )
1029- account_name = self .results [ "deploy" ][ " func_name" ][ "value" ]
1030- key = self .results [ "deploy" ][ " func_key" ][ "value" ]
1043+ account_name = self .func_name
1044+ key = self .func_key
10311045 account_url = "https://%s.blob.core.windows.net" % account_name
10321046 client = BlobServiceClient (account_url , credential = key )
10331047 if "instance-specific-setup" not in [
@@ -1072,8 +1086,8 @@ def upload_instance_setup(self) -> None:
10721086
10731087 def upload_third_party (self ) -> None :
10741088 logger .info ("uploading third-party tools from %s" , self .third_party )
1075- account_name = self .results [ "deploy" ][ " fuzz_name" ][ "value" ]
1076- key = self .results [ "deploy" ][ " fuzz_key" ][ "value" ]
1089+ account_name = self .fuzz_name
1090+ key = self .fuzz_key
10771091 account_url = "https://%s.blob.core.windows.net" % account_name
10781092
10791093 client = BlobServiceClient (account_url , credential = key )
@@ -1206,6 +1220,7 @@ def main() -> None:
12061220 ]
12071221
12081222 full_deployment_states = rbac_only_states + [
1223+ ("set_storage_keys" , Client .set_storage_account_key ),
12091224 ("apply_migrations" , Client .apply_migrations ),
12101225 ("set_instance_config" , Client .set_instance_config ),
12111226 ("tools" , Client .upload_tools ),
0 commit comments