Skip to content

Commit 50cffe6

Browse files
committed
enforce network domain boundaries between networks
1 parent c830eec commit 50cffe6

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

netfoundry/ctl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ def use_organization(prompt: bool = True, spinner: object = None):
10341034
sysexit(1)
10351035

10361036
try:
1037-
spinner.text = "Trying token for profile '{:s}'".format(cli.config.general.profile)
1037+
spinner.text = f"Trying token for profile '{cli.config.general.profile}'"
10381038
with spinner:
10391039
organization = Organization(
10401040
token=token_from_prompt,

netfoundry/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ def __str__(self):
5757

5858
class NeedUserInput(NFAPIError):
5959
"""Need user input to confirm action."""
60+
61+
62+
class NetworkBoundaryViolation(NFAPIError):
63+
"""Network domain resource accessed across a network boundary."""

netfoundry/network.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import time
77

8-
from netfoundry.exceptions import UnknownResourceType
8+
from netfoundry.exceptions import UnknownResourceType, NetworkBoundaryViolation
99

1010
from .utility import (DC_PROVIDERS, MUTABLE_NET_RESOURCES, NET_RESOURCES, PROCESS_STATUS_SYMBOLS, RESOURCES, STATUS_CODES, VALID_SEPARATORS, VALID_SERVICE_PROTOCOLS, any_in, docstring_parameters, find_generic_resources, get_generic_resource, http,
1111
is_uuidv4, normalize_caseless, plural, singular)
@@ -375,12 +375,10 @@ def get_resource_by_id(self, type: str, id: str, accept: str = None):
375375

376376
headers = {"authorization": "Bearer " + self.token}
377377
url = self.audience+'core/v2/'+plural(type)+'/'+id
378-
try:
379-
resource, status_symbol = get_generic_resource(url=url, headers=headers, proxies=self.proxies, verify=self.verify)
380-
except Exception as e:
381-
raise RuntimeError(f"failed to get resource from url: '{url}', caught {e}")
382-
else:
383-
return(resource)
378+
resource, status_symbol = get_generic_resource(url=url, headers=headers, proxies=self.proxies, verify=self.verify)
379+
if not resource['networkId'] == self.id:
380+
raise NetworkBoundaryViolation("resource ID is from another network")
381+
return(resource)
384382
get_resource = get_resource_by_id
385383

386384
def find_resources(self, type: str, accept: str = None, deleted: bool = False, **kwargs):

netfoundry/network_group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def create_network(self, name: str, network_group_id: str = None, location: str
248248
resource = self.get_resource_by_id(type="network", id=resource['id'])
249249
return(resource)
250250
else: # only wait for the process to start, not finish, or timeout
251-
self.Networks.wait_for_process(process_id, RESOURCES['process-executions'].status_symbols['progress'] + RESOURCES['process-executions'].status_symbols['complete'], type="process-executions", wait=9, sleep=3)
251+
# FIXME: commented to allow create to succeed to workaround MOP-18095
252+
# self.Networks.wait_for_process(process_id, RESOURCES['process-executions'].status_symbols['progress'] + RESOURCES['process-executions'].status_symbols['complete'], wait=9, sleep=3)
252253
return(resource)
253254
elif wait:
254255
logging.warning("unable to wait for async complete because response did not provide a process execution id")

0 commit comments

Comments
 (0)