Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added in Nuke-side authentication, if the command server was initiali…

…sed to request it
  • Loading branch information...
commit f1b4f8d0a4d863b101e75d448cafd771740081da 1 parent 9b4543b
@HughMacdonald HughMacdonald authored
Showing with 42 additions and 8 deletions.
  1. +18 −4 nukeCommandClient.py
  2. +24 −4 nukeCommandServer.py
View
22 nukeCommandClient.py
@@ -21,12 +21,17 @@ def __init__(self, host = "localhost", instance = 0):
if self._port == -1:
raise NukeConnectionError("Connection with Nuke failed")
+ elif self._port == -2:
+ raise NukeConnectionError("Connection with Nuke denied")
def find_connection_port(self, start_port, end_port):
for port in range(start_port, end_port + 1):
self._port = port
- if self.test_connection():
- return port
+ if self.test_connection() is True:
+ if self.authenticate_connection() is True:
+ return port
+ else:
+ return -2
return -1
def send(self, data):#
@@ -43,10 +48,19 @@ def send(self, data):#
return result
+ def authenticate_connection(self):
+ if self._host == "localhost":
+ host = "localhost"
+ else:
+ host = os.getenv("HOST")
+
+ if self.get("initiate", parameters = host) == "accept":
+ return True
+ return False
+
def test_connection(self):
try:
- self.get("test")
- return True
+ return self.get("test")
except NukeConnectionError, e:
return False
View
28 nukeCommandServer.py
@@ -10,18 +10,23 @@
MAX_SOCKET_BYTES = 16384
+VERIFY_CONNECTION_NONE = 0
+VERIFY_CONNECTION_ALWAYS = 1
+VERIFY_CONNECTION_ONLY_REMOTE = 2
+
class NukeConnectionError(StandardError):
pass
-def nuke_command_server():
- t = threading.Thread(None, NukeInternal)
+def nuke_command_server(verifyConnection = VERIFY_CONNECTION_NONE):
+ t = threading.Thread(None, NukeInternal, args = (verifyConnection,))
t.setDaemon(True)
t.start()
class NukeInternal:
- def __init__(self):
+ def __init__(self, verifyConnection = VERIFY_CONNECTION_NONE):
self._objects = {}
self._next_object_id = 0
+ self._verify_connection = verifyConnection
host = ''
start_port = 54200
@@ -92,12 +97,27 @@ def encode(self, data):
def decode(self, data):
return self.decode_data(pickle.loads(data))
+ def verify_connection(self, host):
+ if self._verify_connection == VERIFY_CONNECTION_NONE or \
+ (self._verify_connection == VERIFY_CONNECTION_ONLY_REMOTE and \
+ host in ["localhost", os.getenv("HOST")]):
+ return True
+
+ return nuke.executeInMainThreadWithResult(nuke.ask, ("Something is trying to connect to Nuke from %s.\nDo you wish to allow this?" % host,))
+
def get(self, data):
obj = self.get_object(data['id'])
params = data['parameters']
result = None
try:
- if data['action'] == "getattr":
+ if data['action'] == "initiate":
+ if self.verify_connection(params):
+ result = "accept"
+ else:
+ result = "deny"
+ elif data['action'] == "test":
+ result = True
+ elif data['action'] == "getattr":
result = getattr(obj, params)
elif data['action'] == "setattr":
setattr(obj, params[0], params[1])
Please sign in to comment.
Something went wrong with that request. Please try again.