Ejemplo n.º 1
0
def getusercred(geni_api=3):
    """Retrieve your user credential. Useful for debugging.

    If you specify the -o option, the credential is saved to a file.
    If you specify --usercredfile:
       First, it tries to read the user cred from that file.
       Second, it saves the user cred to a file by that name
       (but with the appropriate extension)
    Otherwise, the filename is <username>-<framework nickname from
    config file>-usercred.[xml or json, depending on AM API version].
    If you specify the --prefix option then that string starts the filename.

    If instead of the -o option, you supply the --tostdout option,
    then the usercred is printed to STDOUT.
    Otherwise the usercred is logged.

    The usercred is returned for use by calling scripts.

    e.g.:
      Get user credential, save to a file:
        omni.py -o getusercred

      Get user credential, save to a file with filename prefix mystuff:
        omni.py -o -p mystuff getusercred
    """
    from core.config import FullConfParser
    fcp = FullConfParser()
    username = fcp.get("auth.conf").get("certificates").get("username")
    creds_path = os.path.normpath(
        os.path.join(os.path.dirname(__file__), "../../..", "cert"))
    cert_path = os.path.join(creds_path, "%s-cert.pem" % username)
    # Retrieve new credential by contacting with GCF CH
    try:
        user_cert = open(cert_path, "r").read()
        cred = ch_call("CreateUserCredential", params=[user_cert])
    # Exception? -> Retrieve already existing credential from disk (CBAS)
    except:
        cred_path = os.path.join(creds_path, "%s-cred.xml" % username)
        cred = open(cred_path).read()
    if geni_api >= 3:
        if cred:
            cred = credentials.wrap_cred(cred)
    credxml = credentials.get_cred_xml(cred)
    # pull the username out of the cred
    # <owner_urn>urn:publicid:IDN+geni:gpo:gcf+user+alice</owner_urn>
    user = ""
    usermatch = re.search(
        r"\<owner_urn>urn:publicid:IDN\+.+\+user\+(\w+)\<\/owner_urn\>",
        credxml)
    if usermatch:
        user = usermatch.group(1)
    return ("Retrieved %s user credential" % user, cred)
Ejemplo n.º 2
0
def getusercred(geni_api = 3):
    """Retrieve your user credential. Useful for debugging.

    If you specify the -o option, the credential is saved to a file.
    If you specify --usercredfile:
       First, it tries to read the user cred from that file.
       Second, it saves the user cred to a file by that name (but with the appropriate extension)
    Otherwise, the filename is <username>-<framework nickname from config file>-usercred.[xml or json, depending on AM API version].
    If you specify the --prefix option then that string starts the filename.

    If instead of the -o option, you supply the --tostdout option, then the usercred is printed to STDOUT.
    Otherwise the usercred is logged.

    The usercred is returned for use by calling scripts.

    e.g.:
      Get user credential, save to a file:
        omni.py -o getusercred

      Get user credential, save to a file with filename prefix mystuff:
        omni.py -o -p mystuff getusercred
    """
    from core.config import FullConfParser
    fcp = FullConfParser()
    username = fcp.get("auth.conf").get("certificates").get("username")
    creds_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "../../..", "cert"))
    cert_path = os.path.join(creds_path, "%s-cert.pem" % username)
    # Retrieve new credential by contacting with GCF CH
    try:
        user_cert = open(cert_path, "r").read()
        cred = ch_call("CreateUserCredential", params = [user_cert])
    # Exception? -> Retrieve already existing credential from disk (CBAS)
    except:
        cred_path = os.path.join(creds_path, "%s-cred.xml" % username)
        cred = open(cred_path).read()
    if geni_api >= 3:
        if cred:
            cred = credentials.wrap_cred(cred)
    credxml = credentials.get_cred_xml(cred)
    # pull the username out of the cred
    # <owner_urn>urn:publicid:IDN+geni:gpo:gcf+user+alice</owner_urn>
    user = ""
    usermatch = re.search(r"\<owner_urn>urn:publicid:IDN\+.+\+user\+(\w+)\<\/owner_urn\>", credxml)
    if usermatch:
        user = usermatch.group(1)
    return ("Retrieved %s user credential" % user, cred)
Ejemplo n.º 3
0
def getusercred(user_cert_filename="alice-cert.pem", geni_api=3):
    """Retrieve your user credential. Useful for debugging.

    If you specify the -o option, the credential is saved to a file.
    If you specify --usercredfile:
       First, it tries to read the user cred from that file.
       Second, it saves the user cred to a file by that name (but with the appropriate extension)
    Otherwise, the filename is <username>-<framework nickname from config file>-usercred.[xml or json, depending on AM API version].
    If you specify the --prefix option then that string starts the filename.

    If instead of the -o option, you supply the --tostdout option, then the usercred is printed to STDOUT.
    Otherwise the usercred is logged.

    The usercred is returned for use by calling scripts.

    e.g.:
      Get user credential, save to a file:
        omni.py -o getusercred

      Get user credential, save to a file with filename prefix mystuff:
        omni.py -o -p mystuff getusercred
    """
    creds_path = os.path.normpath(
        os.path.join(os.path.dirname(__file__), "../../..", "cert"))
    cert_path = os.path.join(creds_path, user_cert_filename)
    user_cert = open(cert_path, "r").read()
    # Contacting GCH for it by passing the certificate
    cred = ch_call("CreateUserCredential", params=[user_cert])
    #(cred, message) = ch_call(method_name = "CreateUserCredential", endpoint = "", params = {"params": user_cert})
    if geni_api >= 3:
        if cred:
            cred = credentials.wrap_cred(cred)
    credxml = credentials.get_cred_xml(cred)
    # pull the username out of the cred
    # <owner_urn>urn:publicid:IDN+geni:gpo:gcf+user+alice</owner_urn>
    user = ""
    usermatch = re.search(
        r"\<owner_urn>urn:publicid:IDN\+.+\+user\+(\w+)\<\/owner_urn\>",
        credxml)
    if usermatch:
        user = usermatch.group(1)
    return "Retrieved %s user credential" % user, cred
Ejemplo n.º 4
0
def getusercred(user_cert_filename = "alice-cert.pem", geni_api = 3):
    """Retrieve your user credential. Useful for debugging.

    If you specify the -o option, the credential is saved to a file.
    If you specify --usercredfile:
       First, it tries to read the user cred from that file.
       Second, it saves the user cred to a file by that name (but with the appropriate extension)
    Otherwise, the filename is <username>-<framework nickname from config file>-usercred.[xml or json, depending on AM API version].
    If you specify the --prefix option then that string starts the filename.

    If instead of the -o option, you supply the --tostdout option, then the usercred is printed to STDOUT.
    Otherwise the usercred is logged.

    The usercred is returned for use by calling scripts.

    e.g.:
      Get user credential, save to a file:
        omni.py -o getusercred

      Get user credential, save to a file with filename prefix mystuff:
        omni.py -o -p mystuff getusercred
    """
    #TODO: change path dirname to proper certificate direction; ch-cert.pem, alice-cert.pem
    creds_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "../../..", "cert"))
    cert_path = os.path.join(creds_path, user_cert_filename)
    user_cert = open(cert_path, "r").read()
    # Contacting GCH for it by passing the certificate
    cred = ch_call("CreateUserCredential", params = [user_cert])
    #(cred, message) = ch_call(method_name = "CreateUserCredential", endpoint = "", params = {"params": user_cert})
    if geni_api >= 3:
        if cred:
            cred = credentials.wrap_cred(cred)
    credxml = credentials.get_cred_xml(cred)
    # pull the username out of the cred
    # <owner_urn>urn:publicid:IDN+geni:gpo:gcf+user+alice</owner_urn>
    user = ""
    usermatch = re.search(r"\<owner_urn>urn:publicid:IDN\+.+\+user\+(\w+)\<\/owner_urn\>", credxml)
    if usermatch:
        user = usermatch.group(1)
    return "Retrieved %s user credential" % user, cred