def hasDataContext(): import geni._coreutil as GCU path = GCU.getDefaultContextPath() return os.path.exists(path)
def loadContext(path=None, key_passphrase=None): import geni._coreutil as GCU from geni.aggregate import FrameworkRegistry from geni.aggregate.context import Context from geni.aggregate.user import User if path is None: path = GCU.getDefaultContextPath() else: path = os.path.expanduser(path) obj = json.load(open(path, "r")) version = _getdefault(obj, "version", 1) if key_passphrase is True: import getpass key_passphrase = getpass.getpass("Private key passphrase: ") if version == 1: cf = FrameworkRegistry.get(obj["framework"])() cf.cert = obj["cert-path"] if key_passphrase: if six.PY3: key_passphrase = bytes(key_passphrase, "utf-8") cf.setKey(obj["key-path"], key_passphrase) else: cf.key = obj["key-path"] user = User() user.name = obj["user-name"] user.urn = obj["user-urn"] user.addKey(obj["user-pubkeypath"]) context = Context() context.addUser(user) context.cf = cf context.project = obj["project"] context.path = path elif version == 2: context = Context() fobj = obj["framework-info"] cf = FrameworkRegistry.get(fobj["type"])() cf.cert = fobj["cert-path"] if key_passphrase: cf.setKey(fobj["key-path"], key_passphrase) else: cf.key = fobj["key-path"] context.cf = cf context.project = fobj["project"] context.path = path ulist = obj["users"] for uobj in ulist: user = User() user.name = uobj["username"] user.urn = _getdefault(uobj, "urn", None) klist = uobj["keys"] for keypath in klist: user.addKey(keypath) context.addUser(user) from cryptography import x509 from cryptography.hazmat.backends import default_backend cert = x509.load_pem_x509_certificate( open(context._cf.cert, "rb").read(), default_backend()) if cert.not_valid_after < datetime.datetime.now(): print( "***WARNING*** Client SSL certificate supplied in this context is expired" ) return context