Example #1
0
def pcsd_certkey(dummy_lib, argv, modifiers):
    """
    Options:
      * --force - overwrite existing file
    """
    modifiers.ensure_only_supported("--force")
    if len(argv) != 2:
        raise CmdLineInputError()

    certfile = argv[0]
    keyfile = argv[1]

    try:
        with open(certfile, 'r') as myfile:
            cert = myfile.read()
        with open(keyfile, 'r') as myfile:
            key = myfile.read()
    except IOError as e:
        utils.err(e)
    errors = utils.verify_cert_key_pair(cert, key)
    if errors:
        for err in errors:
            utils.err(err, False)
        sys.exit(1)

    if (not modifiers.get("--force")
            and (os.path.exists(settings.pcsd_cert_location)
                 or os.path.exists(settings.pcsd_key_location))):
        utils.err(
            "certificate and/or key already exists, use --force to overwrite")

    try:
        try:
            os.chmod(settings.pcsd_cert_location, 0o700)
        except OSError:  # If the file doesn't exist, we don't care
            pass

        try:
            os.chmod(settings.pcsd_key_location, 0o700)
        except OSError:  # If the file doesn't exist, we don't care
            pass

        with os.fdopen(
                os.open(settings.pcsd_cert_location,
                        os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700),
                'w') as myfile:
            myfile.write(cert)

        with os.fdopen(
                os.open(settings.pcsd_key_location,
                        os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700),
                'w') as myfile:
            myfile.write(key)

    except IOError as e:
        utils.err(e)

    print(
        "Certificate and key updated, you may need to restart pcsd (service pcsd restart) for new settings to take effect"
    )
Example #2
0
def pcsd_certkey(argv):
    if len(argv) != 2:
        usage.pcsd(["certkey"])
        exit(1)

    certfile = argv[0]
    keyfile = argv[1]

    try:
        with open(certfile, 'r') as myfile:
            cert = myfile.read()
        with open(keyfile, 'r') as myfile:
            key = myfile.read()
    except IOError as e:
        utils.err(e)
    errors = utils.verify_cert_key_pair(cert, key)
    if errors:
        for err in errors:
            utils.err(err, False)
        sys.exit(1)

    if "--force" not in utils.pcs_options and (
            os.path.exists(settings.pcsd_cert_location)
            or os.path.exists(settings.pcsd_key_location)):
        utils.err(
            "certificate and/or key already exists, your must use --force to overwrite"
        )

    try:
        try:
            os.chmod(settings.pcsd_cert_location, 0o700)
        except OSError:  # If the file doesn't exist, we don't care
            pass

        try:
            os.chmod(settings.pcsd_key_location, 0o700)
        except OSError:  # If the file doesn't exist, we don't care
            pass

        with os.fdopen(
                os.open(settings.pcsd_cert_location,
                        os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700),
                'w') as myfile:
            myfile.write(cert)

        with os.fdopen(
                os.open(settings.pcsd_key_location,
                        os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700),
                'w') as myfile:
            myfile.write(key)

    except IOError as e:
        utils.err(e)

    print(
        "Certificate and key updated, you may need to restart pcsd (service pcsd restart) for new settings to take effect"
    )
Example #3
0
def pcsd_certkey(argv):
    if len(argv) != 2:
        usage.pcsd(["certkey"])
        exit(1)

    certfile = argv[0]
    keyfile = argv[1]

    try:
        with open(certfile, 'r') as myfile:
            cert = myfile.read()
        with open(keyfile, 'r') as myfile:
            key = myfile.read()
    except IOError as e:
        utils.err(e)
    errors = utils.verify_cert_key_pair(cert, key)
    if errors:
        for err in errors:
            utils.err(err, False)
        sys.exit(1)

    if "--force" not in utils.pcs_options and (os.path.exists(settings.pcsd_cert_location) or os.path.exists(settings.pcsd_key_location)):
        utils.err("certificate and/or key already exists, your must use --force to overwrite")

    try:
        try:
            os.chmod(settings.pcsd_cert_location, 0o700)
        except OSError: # If the file doesn't exist, we don't care
            pass

        try:
            os.chmod(settings.pcsd_key_location, 0o700)
        except OSError: # If the file doesn't exist, we don't care
            pass

        with os.fdopen(os.open(settings.pcsd_cert_location, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700), 'w') as myfile:
            myfile.write(cert)

        with os.fdopen(os.open(settings.pcsd_key_location, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o700), 'w') as myfile:
            myfile.write(key)

    except IOError as e:
        utils.err(e)

    print("Certificate and key updated, you may need to restart pcsd (service pcsd restart) for new settings to take effect")
Example #4
0
def pcsd_certkey(lib, argv, modifiers):
    """
    Options:
      * --force - overwrite existing file
    """
    del lib
    modifiers.ensure_only_supported("--force")
    if len(argv) != 2:
        raise CmdLineInputError()

    certfile = argv[0]
    keyfile = argv[1]

    try:
        with open(certfile, 'r') as myfile:
            cert = myfile.read()
        with open(keyfile, 'r') as myfile:
            key = myfile.read()
    except IOError as e:
        utils.err(e)
    errors = utils.verify_cert_key_pair(cert, key)
    if errors:
        for err in errors:
            utils.err(err, False)
        sys.exit(1)

    if (
        not modifiers.get("--force")
        and
        (
            os.path.exists(settings.pcsd_cert_location)
            or
            os.path.exists(settings.pcsd_key_location)
        )
    ):
        utils.err(
            "certificate and/or key already exists, use --force to overwrite"
        )

    try:
        try:
            os.chmod(settings.pcsd_cert_location, 0o700)
        except OSError: # If the file doesn't exist, we don't care
            pass

        try:
            os.chmod(settings.pcsd_key_location, 0o700)
        except OSError: # If the file doesn't exist, we don't care
            pass

        with os.fdopen(
            os.open(
                settings.pcsd_cert_location,
                os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
                0o700
            ),
            'w'
        ) as myfile:
            myfile.write(cert)

        with os.fdopen(
            os.open(
                settings.pcsd_key_location,
                os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
                0o700
            ),
            'w'
        ) as myfile:
            myfile.write(key)

    except IOError as e:
        utils.err(e)

    print(
        "Certificate and key updated, you may need to restart pcsd for new "
            "settings to take effect"
    )