@@ -25,11 +25,21 @@ def apigee_apps_to_product_map(apps_list: List[dict], product_filter: str = None
2525 if api_product not in result :
2626 result [api_product ] = []
2727
28+ company_exists = "companyName" in app .keys ()
29+ developer_exists = "developerId" in app .keys ()
30+ if developer_exists and not company_exists :
31+ owner = app ["developerId" ]
32+ elif company_exists and not developer_exists :
33+ owner = app ["companyName" ]
34+ else :
35+ raise RuntimeError (f"Invalid owner for app { app ['appId' ]} " )
36+
2837 result [api_product ].append (
2938 dict (
3039 appId = app ["appId" ],
3140 appName = app ["name" ],
32- developerId = app ["developerId" ],
41+ owner = owner ,
42+ ownerEndpoint = "companies" if company_exists else "developers" ,
3343 consumerKey = cred ["consumerKey" ],
3444 apiproduct = api_product
3545 )
@@ -39,6 +49,13 @@ def apigee_apps_to_product_map(apps_list: List[dict], product_filter: str = None
3949 return result
4050
4151
52+ def product_app_mapping_to_owner_display (dev_id_to_email : dict , product_app : dict ):
53+ if product_app ['ownerEndpoint' ] == 'developers' :
54+ return dev_id_to_email [product_app ['owner' ]]
55+ else :
56+ return product_app ['owner' ]
57+
58+
4259def apigee_products_to_api_map (products : List [dict ], proxy_filter : str = None ):
4360
4461 result = dict ()
@@ -73,28 +90,34 @@ def apigee_remove_proxy_from_product(product: dict, proxy_to_remove):
7390 return product
7491
7592
76- def apigee_teams_map (teams : List [dict ]):
93+ def apigee_team_to_admin (team ):
94+ return next ((attr .get ('value' ) for attr in team ['attributes' ] if attr ['name' ] == 'ADMIN_EMAIL' ), None )
95+
96+
97+ def apigee_teams_map (team_members : List [dict ], teams : List [dict ]):
98+ from collections import defaultdict
99+ joined = defaultdict (dict )
100+ for item in team_members + teams :
101+ joined [item ['name' ]].update (item )
102+ full_teams = list (joined .values ())
77103
78104 return {
79- f" { team ['id' ] } @devteam.apigee.io" : {
80- "contact" : team [ 'pointOfContact' ] ,
81- "members" : list ( mem [ 'userId' ] for mem in team . get ( 'memberships' , []))
105+ team ['name' ] : {
106+ "contact" : apigee_team_to_admin ( team ) ,
107+ "members" : team [ 'members' ]
82108 }
83- for team in teams
109+ for team in full_teams
84110 }
85111
86112
87113def apigee_teams_to_point_of_contact (teams : List [dict ]):
88-
89- return {
90- f"{ team ['id' ]} @devteam.apigee.io" : team ['pointOfContact' ] for team in teams
91- }
114+ return {apigee_team_to_admin (team ) for team in teams }
92115
93116
94117def apigee_teams_to_members (teams : List [dict ]):
95118
96119 return {
97- f" { team ['id' ] } @devteam.apigee.io" : list ( mem [ 'userId' ] for mem in team .get ('memberships ' , []) ) for team in teams
120+ team ['owner' ]: team .get ('members ' , []) for team in teams
98121 }
99122
100123
@@ -116,18 +139,16 @@ def apigee_product_developers(
116139 result [product_name ] = []
117140
118141 for app in apps :
119- developer = dev_id_to_email [app ["developerId" ]]
120-
121- team = teams_map .get (developer , {})
122-
123142 entry = {
124- "app" : app ["appName" ],
125- "developer" : developer
143+ "app" : app ["appName" ]
126144 }
127145
128- if team :
146+ if app ['ownerEndpoint' ] == 'companies' :
147+ team = teams_map .get (app .get ("owner" ), {})
129148 entry ['developer' ] = team ['contact' ]
130149 entry ['team' ] = team ['members' ]
150+ else :
151+ entry ['developer' ] = dev_id_to_email [app ["owner" ]]
131152
132153 result [product_name ].append (entry )
133154
@@ -137,10 +158,6 @@ def apigee_product_developers(
137158
138159 return result
139160
140- # return {
141- # f"{team['id']}@devteam.apigee.io": list(mem['userId'] for mem in team.get('memberships', [])) for team in teams
142- # }
143-
144161
145162class FilterModule :
146163
@@ -154,5 +171,6 @@ def filters():
154171 'apigee_teams_to_point_of_contact' : apigee_teams_to_point_of_contact ,
155172 'apigee_teams_to_members' : apigee_teams_to_members ,
156173 'apigee_teams_map' : apigee_teams_map ,
157- 'apigee_product_developers' : apigee_product_developers
174+ 'apigee_product_developers' : apigee_product_developers ,
175+ 'product_app_mapping_to_owner_display' : product_app_mapping_to_owner_display
158176 }
0 commit comments