Skip to content

Commit 1683c3b

Browse files
committed
make the Gateway Service domain name configurable
1 parent 0492e58 commit 1683c3b

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

netfoundry/ctl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __call__(self, parser, namespace, values, option_string=None):
9494
@cli.argument('-Y', '--yes', action='store_true', arg_only=True, help='answer yes to potentially-destructive operations')
9595
@cli.argument('-W', '--wait', help='seconds to wait for long-running processes to finish', default=900)
9696
@cli.argument('--proxy', help=argparse.SUPPRESS)
97+
@cli.argument('--gateway', default="gateway", help=argparse.SUPPRESS)
9798
@cli.entrypoint('configure the CLI to manage a network')
9899
def main(cli):
99100
"""Configure the CLI to manage a network."""
@@ -1153,7 +1154,7 @@ def use_organization(cli, spinner: object = None, prompt: bool = True):
11531154
expiry_minimum=0,
11541155
proxy=cli.config.general.proxy,
11551156
logger=cli.log,
1156-
gateway="gatewayv2",
1157+
gateway=cli.config.general.gateway,
11571158
)
11581159
except NFAPINoCredentials:
11591160
if prompt:
@@ -1178,7 +1179,7 @@ def use_organization(cli, spinner: object = None, prompt: bool = True):
11781179
expiry_minimum=0,
11791180
proxy=cli.config.general.proxy,
11801181
logger=cli.log,
1181-
gateway="gatewayv2",
1182+
gateway=cli.config.general.gateway,
11821183
)
11831184
except PyJWTError:
11841185
spinner.fail("Not a valid token")

netfoundry/organization.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def __init__(self,
4646
proxy: str = None,
4747
gateway: str = "gateway"):
4848
"""Initialize an instance of organization."""
49-
self.gateway = gateway
5049
# set debug and file if specified and let the calling application dictate logging handlers
5150
self.log_file = log_file
5251
self.debug = debug
@@ -81,6 +80,9 @@ def __init__(self,
8180
else:
8281
self.verify = False
8382

83+
self.gateway = gateway
84+
self.logger.debug(f"got 'gateway' param {self.gateway}")
85+
8486
epoch = round(time.time())
8587
self.expiry_seconds = 0 # initialize a placeholder for remaining seconds until expiry
8688
client_id = None
@@ -258,6 +260,8 @@ def __init__(self,
258260
if not re.search(self.environment, self.audience):
259261
self.logger.error(f"mismatched audience URL '{self.audience}' and environment '{self.environment}'")
260262
exit(1)
263+
else:
264+
self.logger.debug(f"found audience already computed '{self.audience}' and matching environment '{self.environment}'")
261265

262266
# the purpose of this try-except block is to soft-fail all attempts
263267
# to parse the JWT, which is intended for the API, not this
@@ -290,12 +294,15 @@ def __init__(self,
290294
self.logger.debug(f"using environment parsed from authenticationUrl: {self.environment}")
291295
# re: scope: we're not using scopes with Cognito, but a non-empty value is required;
292296
# hence "/ignore-scope"
293-
scope = f"https://{self.gateway}.{self.environment}.netfoundry.io//ignore-scope"
294-
self.logger.debug(f"computed scope URL from gateway and environment: {scope}")
297+
scope = f"https://gateway.{self.environment}.netfoundry.io//ignore-scope"
298+
self.logger.debug(f"computed scope URL from 'gateway' and environment: {scope}")
295299
# we can gather the URL of the API from the first part of the scope string by
296300
# dropping the scope suffix
297301
self.audience = scope.replace(r'/ignore-scope', '')
298-
self.logger.debug(f"using audience parsed from authenticationUrl: {self.audience}")
302+
self.logger.debug(f"computed audience from authenticationUrl sans the trailing '/ignore-scope': {self.audience}")
303+
audience_parts = self.audience.split('.')
304+
self.audience = '.'.join([f"https://{self.gateway}"]+audience_parts[1:])
305+
self.logger.debug(f"computed audience with substituted param 'gateway': {self.audience}")
299306
assertion = {
300307
"scope": scope,
301308
"grant_type": "client_credentials"

netfoundry/utility.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def jwt_environment(setup: object):
185185

186186
else:
187187
if re.match(r'https://cognito-', iss):
188-
environment = re.sub(f'https://{setup.gateway}\.([^.]+)\.netfoundry\.io.*', r'\1', claim['scope'])
188+
environment = re.sub(r'https://gateway\.([^.]+)\.netfoundry\.io.*', r'\1', claim['scope'])
189189
setup.logger.debug(f"matched Cognito issuer URL convention, found environment '{environment}'")
190190
elif re.match(r'.*\.auth0\.com', iss):
191191
environment = re.sub(r'https://netfoundry-([^.]+)\.auth0\.com.*', r'\1', claim['iss'])
@@ -319,6 +319,8 @@ def create_generic_resource(setup: object, url: str, body: dict, headers: dict =
319319
proxies=setup.proxies,
320320
verify=setup.verify,
321321
)
322+
if response.status_code in range(400, 600):
323+
setup.logger.debug(response.request)
322324
response.raise_for_status()
323325
resource = response.json()
324326

0 commit comments

Comments
 (0)