@@ -43,7 +43,8 @@ def __init__(self,
4343 log_file : str = None ,
4444 debug : bool = False ,
4545 logger : logging .Logger = None ,
46- proxy : str = None ):
46+ proxy : str = None ,
47+ gateway : str = "gateway" ):
4748 """Initialize an instance of organization."""
4849 # set debug and file if specified and let the calling application dictate logging handlers
4950 self .log_file = log_file
@@ -79,6 +80,14 @@ def __init__(self,
7980 else :
8081 self .verify = False
8182
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+
8291 epoch = round (time .time ())
8392 self .expiry_seconds = 0 # initialize a placeholder for remaining seconds until expiry
8493 client_id = None
@@ -249,12 +258,15 @@ def __init__(self,
249258 self .logger .warning (f"unexpected environment '{ self .environment } '" )
250259
251260 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 } " )
253263
254264 if self .environment and self .audience :
255265 if not re .search (self .environment , self .audience ):
256266 self .logger .error (f"mismatched audience URL '{ self .audience } ' and environment '{ self .environment } '" )
257267 exit (1 )
268+ else :
269+ self .logger .debug (f"found audience already computed '{ self .audience } ' and matching environment '{ self .environment } '" )
258270
259271 # the purpose of this try-except block is to soft-fail all attempts
260272 # to parse the JWT, which is intended for the API, not this
@@ -284,15 +296,18 @@ def __init__(self,
284296 # extract the environment name from the authorization URL aka token API endpoint
285297 if self .environment is None :
286298 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 } " )
288300 # re: scope: we're not using scopes with Cognito, but a non-empty value is required;
289301 # 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 } " )
291304 # we can gather the URL of the API from the first part of the scope string by
292305 # dropping the scope suffix
293306 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 } " )
296311 assertion = {
297312 "scope" : scope ,
298313 "grant_type" : "client_credentials"
@@ -544,7 +559,7 @@ def get_network_group(self, network_group_id):
544559
545560 :param network_group_id: the UUID of the network group
546561 """
547- url = self .audience + 'rest/v1 /network-groups/' + network_group_id
562+ url = self .audience + 'core/v2 /network-groups/' + network_group_id
548563 try :
549564 network_group , status_symbol = get_generic_resource_by_url (setup = self , url = url )
550565 except Exception as e :
@@ -585,7 +600,7 @@ def find_network_groups_by_organization(self, **kwargs):
585600
586601 :param str kwargs: filter results by any supported query param
587602 """
588- url = self .audience + 'rest/v1 /network-groups'
603+ url = self .audience + 'core/v2 /network-groups'
589604 network_groups = list ()
590605 for i in find_generic_resources (setup = self , url = url , embedded = RESOURCES ['network-groups' ]._embedded , ** kwargs ):
591606 network_groups .extend (i )
0 commit comments