@@ -43,7 +43,8 @@ def __init__(self,
43
43
log_file : str = None ,
44
44
debug : bool = False ,
45
45
logger : logging .Logger = None ,
46
- proxy : str = None ):
46
+ proxy : str = None ,
47
+ gateway : str = "gateway" ):
47
48
"""Initialize an instance of organization."""
48
49
# set debug and file if specified and let the calling application dictate logging handlers
49
50
self .log_file = log_file
@@ -79,6 +80,14 @@ def __init__(self,
79
80
else :
80
81
self .verify = False
81
82
83
+ # users of older versions of nfsupport-cli will send literal None until they upgrade to a version that provides the --gateway option
84
+ if gateway is None :
85
+ self .gateway = "gateway"
86
+ else :
87
+ self .gateway = gateway
88
+
89
+ self .logger .debug (f"got 'gateway' param { self .gateway } " )
90
+
82
91
epoch = round (time .time ())
83
92
self .expiry_seconds = 0 # initialize a placeholder for remaining seconds until expiry
84
93
client_id = None
@@ -249,12 +258,15 @@ def __init__(self,
249
258
self .logger .warning (f"unexpected environment '{ self .environment } '" )
250
259
251
260
if self .environment and not self .audience :
252
- self .audience = f'https://gateway.{ self .environment } .netfoundry.io/'
261
+ self .audience = f'https://{ self .gateway } .{ self .environment } .netfoundry.io/'
262
+ self .logger .debug (f"computed audience URL from gateway and environment: { self .audience } " )
253
263
254
264
if self .environment and self .audience :
255
265
if not re .search (self .environment , self .audience ):
256
266
self .logger .error (f"mismatched audience URL '{ self .audience } ' and environment '{ self .environment } '" )
257
267
exit (1 )
268
+ else :
269
+ self .logger .debug (f"found audience already computed '{ self .audience } ' and matching environment '{ self .environment } '" )
258
270
259
271
# the purpose of this try-except block is to soft-fail all attempts
260
272
# to parse the JWT, which is intended for the API, not this
@@ -284,15 +296,18 @@ def __init__(self,
284
296
# extract the environment name from the authorization URL aka token API endpoint
285
297
if self .environment is None :
286
298
self .environment = re .sub (r'https://netfoundry-([^-]+)-.*' , r'\1' , token_endpoint , re .IGNORECASE )
287
- self .logger .debug (f"using environment parsed from token_endpoint URL { self .environment } " )
299
+ self .logger .debug (f"using environment parsed from authenticationUrl: { self .environment } " )
288
300
# re: scope: we're not using scopes with Cognito, but a non-empty value is required;
289
301
# hence "/ignore-scope"
290
- scope = "https://gateway." + self .environment + ".netfoundry.io//ignore-scope"
302
+ scope = f"https://gateway.{ self .environment } .netfoundry.io//ignore-scope"
303
+ self .logger .debug (f"computed scope URL from 'gateway' and environment: { scope } " )
291
304
# we can gather the URL of the API from the first part of the scope string by
292
305
# dropping the scope suffix
293
306
self .audience = scope .replace (r'/ignore-scope' , '' )
294
- self .logger .debug (f"using audience parsed from token_endpoint URL { self .audience } " )
295
- # e.g. https://gateway.production.netfoundry.io/
307
+ self .logger .debug (f"computed audience from authenticationUrl sans the trailing '/ignore-scope': { self .audience } " )
308
+ audience_parts = self .audience .split ('.' )
309
+ self .audience = '.' .join ([f"https://{ self .gateway } " ]+ audience_parts [1 :])
310
+ self .logger .debug (f"computed audience with substituted param 'gateway': { self .audience } " )
296
311
assertion = {
297
312
"scope" : scope ,
298
313
"grant_type" : "client_credentials"
@@ -544,7 +559,7 @@ def get_network_group(self, network_group_id):
544
559
545
560
:param network_group_id: the UUID of the network group
546
561
"""
547
- url = self .audience + 'rest/v1 /network-groups/' + network_group_id
562
+ url = self .audience + 'core/v2 /network-groups/' + network_group_id
548
563
try :
549
564
network_group , status_symbol = get_generic_resource_by_url (setup = self , url = url )
550
565
except Exception as e :
@@ -585,7 +600,7 @@ def find_network_groups_by_organization(self, **kwargs):
585
600
586
601
:param str kwargs: filter results by any supported query param
587
602
"""
588
- url = self .audience + 'rest/v1 /network-groups'
603
+ url = self .audience + 'core/v2 /network-groups'
589
604
network_groups = list ()
590
605
for i in find_generic_resources (setup = self , url = url , embedded = RESOURCES ['network-groups' ]._embedded , ** kwargs ):
591
606
network_groups .extend (i )
0 commit comments