Add in the unpackage function and tie to it

This commit is contained in:
Thomas S Hatch 2011-03-04 11:49:12 -07:00
parent 077386b3c4
commit 26b4aa45b7
2 changed files with 18 additions and 1 deletions

View File

@ -105,7 +105,7 @@ class Auth(object):
socket.connect(self.opts['master_uri'])
payload = salt.payload.package(self.minion_sign_in_payload())
socket.send(payload)
ret = salt.utils.unpackage(socket.recv())
ret = salt.payload.unpackage(socket.recv())
if not self.verify_master(ret['pub_key'], ret['token']):
return auth
auth['aes'] = self.decrypt_master_aes(ret['aes'])

View File

@ -20,6 +20,23 @@ def package(payload, form='pickle', protocol=2):
package = pickle.dumps(payload, protocol)
return package
def unpackage(package):
'''
Unpackages a payload
'''
# yes, this is dirty for json support, I know it needs some love
payload = None
try:
payload = pickle.loads(package)
except:
pass
if not payload:
try:
payload = json.loads(package)
except ValueError:
pass
return payload
def aes(payload, key):
'''
Encrypt the payload with AES encryption.