File tree Expand file tree Collapse file tree 2 files changed +35
-11
lines changed
src/databricks/labs/ucx/aws Expand file tree Collapse file tree 2 files changed +35
-11
lines changed Original file line number Diff line number Diff line change 1010 Privilege ,
1111 StorageCredentialInfo ,
1212 ValidationResultResult ,
13+ CredentialPurpose ,
1314)
1415
1516from databricks .labs .ucx .assessment .aws import (
@@ -62,19 +63,19 @@ def list_glue(self) -> dict[str, str]:
6263 try :
6364 credential_response = self ._ws .credentials .list_credentials ()
6465 except NotFound :
65- logger .info ('Could not retrieve credentials for Glue access. ' )
66- return {}
67- if not credential_response or not isinstance (credential_response , dict ):
68- logger .info ('Could not retrieve credentials for Glue access. ' )
69- return {}
70- credential_list = credential_response .get ("credentials" )
71- if not credential_list or not isinstance (credential_list , list ):
72- logger .info ('Could not retrieve credentials for Glue access. ' )
66+ logger .info ('Could not retrieve credentials for Glue access. (NotFound)' )
7367 return {}
68+
7469 credentials = {
75- credential .get ("name" ): credential .get ("aws_iam_role" ).get ("role_arn" )
76- for credential in credential_list
77- if credential .get ("purpose" ) == "SERVICE"
70+ credential .name : credential .aws_iam_role .role_arn
71+ for credential in credential_response
72+ if (
73+ credential
74+ and credential .name
75+ and credential .aws_iam_role
76+ and credential .aws_iam_role .role_arn
77+ and credential .purpose == CredentialPurpose .SERVICE
78+ )
7879 }
7980
8081 logger .info (f"Found { len (credentials )} distinct IAM roles used in UC service credentials" )
Original file line number Diff line number Diff line change 1212 AzureServicePrincipal ,
1313 Privilege ,
1414 StorageCredentialInfo ,
15+ CredentialInfo ,
16+ AwsIamRole ,
17+ CredentialPurpose ,
1518)
1619
1720from databricks .labs .ucx .assessment .aws import AWSRoleAction , AWSCredentialCandidate , AWSResourceType
@@ -49,6 +52,20 @@ def credential_manager():
4952 ws .storage_credentials .create .side_effect = side_effect_create_aws_storage_credential
5053 ws .storage_credentials .validate .side_effect = side_effect_validate_storage_credential
5154
55+ credentials = [
56+ CredentialInfo (
57+ name = "storage-credential-1" ,
58+ aws_iam_role = AwsIamRole (role_arn = "arn:aws:iam::123456789012:role/example-role-name" ),
59+ purpose = CredentialPurpose .STORAGE ,
60+ ),
61+ CredentialInfo (
62+ name = "glue-credential-1" ,
63+ aws_iam_role = AwsIamRole (role_arn = "arn:aws:iam::123456789012:role/glue-role" ),
64+ purpose = CredentialPurpose .SERVICE ,
65+ ),
66+ ]
67+ ws .credentials .list_credentials .return_value = credentials
68+
5269 return CredentialManager (ws )
5370
5471
@@ -220,3 +237,9 @@ def test_validate_storage_credentials_failed_operation(credential_manager):
220237
221238 validation = credential_manager .validate (permission_mapping )
222239 assert validation .failures == ["LIST validation failed with message: fail" ]
240+
241+
242+ def test_list_glue_credentials (credential_manager ):
243+ glue_credentials = credential_manager .list_glue ()
244+ assert len (glue_credentials ) == 1
245+ assert glue_credentials ['glue-credential-1' ] == "arn:aws:iam::123456789012:role/glue-role"
You can’t perform that action at this time.
0 commit comments