Example #1
0
    def setup(self, args):
        user_config = get_user_config(self.settings)
        ssh_key_path = self._get_setup_ssh_key_path(user_config, args)
        if not is_key_valid(ssh_key_path):
            # If given key path is not default and does not exist
            # we raise an error
            if ssh_key_path != get_default_ssh_key_path():
                raise InputErrorException('WrongPublicKey')

            # If given key path was the default one, we create the key
            # pair for the user
            print >> sys.stderr, "Key '{0}' seems to not be a RSA public key or not found!".format(ssh_key_path)
            create_new_default_ssh_keys()

        ssh_key_content = readContentOf(ssh_key_path)

        ssh_auth = self._get_setup_ssh_auth(self.settings, user_config, args)

        if args.email:
            set_user_config(self.settings, email=args.email)

        try:
            users = self.api.read_users()
            self.api.create_user_key(
                users[0]['username'],
                ssh_key_content)

        except ConflictDuplicateError:
            # Key already added, nothing to do.
            pass

        set_user_config(self.settings,
                        ssh_auth=ssh_auth,
                        ssh_path=ssh_key_path)
Example #2
0
    def setup(self, args):
        user_config = get_user_config(self.settings)
        ssh_key_path = self._get_setup_ssh_key_path(user_config, args)
        if not is_key_valid(ssh_key_path):
            # If given key path is not default and does not exist
            # we raise an error
            if ssh_key_path != get_default_ssh_key_path():
                raise InputErrorException('WrongPublicKey')

            # If given key path was the default one, we create the key
            # pair for the user
            print >> sys.stderr, "Key '{0}' seems to not be a RSA public key or not found!".format(
                ssh_key_path)
            create_new_default_ssh_keys()

        ssh_key_content = readContentOf(ssh_key_path)

        ssh_auth = self._get_setup_ssh_auth(self.settings, user_config, args)

        if args.email:
            set_user_config(self.settings, email=args.email)

        try:
            users = self.api.read_users()
            self.api.create_user_key(users[0]['username'], ssh_key_content)

        except ConflictDuplicateError:
            # Key already added, nothing to do.
            pass

        set_user_config(self.settings,
                        ssh_auth=ssh_auth,
                        ssh_path=ssh_key_path)
Example #3
0
    def addKey(self, args):
        """
            Add a given public key to cloudControl user account.
        """
        default_key_path = get_default_ssh_key_path()

        # Possibility #1: User is providing a non-default SSH key
        key_to_read = args.public_key
        if not is_key_valid(key_to_read):

            # Possibility #2: Try the default RSA public key
            print >> sys.stderr, "Key '{0}' seems to not be a RSA public key or not found!".format(key_to_read)
            ask_user_to_use_default_ssh_public_key()

            # Possibility #3: All failed! Let's just create new keys for user!
            if not is_key_valid(default_key_path):
                if key_to_read != default_key_path:
                    print >> sys.stderr, "Default key '{0}' seems to not be a RSA public key or not found!".format(default_key_path)
                create_new_default_ssh_keys()

            # We've filtered all cases: the key must be the default one!
            key_to_read = default_key_path

        # Good, we have the key! Now, read the content of the key!
        public_rsa_key_content = readContentOf(key_to_read)

        # Add public RSA-key to cloudControl user account
        try:
            users = self.api.read_users()
            self.api.create_user_key(
                users[0]['username'],
                public_rsa_key_content)

        except ConflictDuplicateError:
            raise InputErrorException('KeyDuplicate')
Example #4
0
 def registerAddon(self, args):
     file_content = readContentOf(args.manifest)
     email, password = get_email_and_password(self.settings)
     try:
         self.api.register_addon(email, password, json.loads(file_content))
     except cclib.UnauthorizedError:
         sys.exit(messages['NotAuthorized'])
     except cclib.ForbiddenError, e:
         sys.exit(messages['NotAllowed'])
Example #5
0
 def registerAddon(self, args):
     file_content = readContentOf(args.manifest)
     email, password = get_email_and_password(self.settings)
     try:
         self.api.register_addon(email, password, json.loads(file_content))
     except cclib.UnauthorizedError:
         sys.exit(messages['NotAuthorized'])
     except cclib.ForbiddenError, e:
         sys.exit(messages['NotAllowed'])
Example #6
0
def is_key_valid(key):
    """
        Is the given key a valid SSH-key with RSA encryption?
    """
    if not isValidFile(key):
        return False

    file_content = readContentOf(key)
    if file_content == None:
        return False

    # File read! Now check if it's RSA encrypted ...
    if file_content[:8] != 'ssh-rsa ':
        return False

    return True
Example #7
0
def is_key_valid(key):
    """
        Is the given key a valid SSH-key with RSA encryption?
    """
    if not isValidFile(key):
        return False

    file_content = readContentOf(key)
    if not file_content:
        return False

    # File read! Now check if it's RSA encrypted ...
    if file_content[:8] != 'ssh-rsa ':
        return False

    return True
Example #8
0
    def addKey(self, args):
        """
            Add a given public key to cloudControl user account.
        """
        if sys.platform == 'win32':
            default_key_path = os.path.expanduser('~') + "/.ssh/id_rsa.pub"
        else:
            default_key_path = os.getenv("HOME") + "/.ssh/id_rsa.pub"

        # Possibility #1: User is providing a non-default SSH key
        key_to_read = args.public_key
        if not is_key_valid(key_to_read):

            # Possibility #2: Try the default RSA public key
            print "Key '{0}' seems to be invalid or not found!".format(key_to_read)
            ask_user_to_use_default_ssh_public_key()

            # Possibility #3: All failed! Let's just create new keys for user!
            if not is_key_valid(default_key_path):
                if key_to_read != default_key_path:
                    print "Default key '{0}' seems to be invalid or not found!".format(default_key_path)
                create_new_default_ssh_keys()

            # We've filtered all cases: the key must be the default one!
            key_to_read = default_key_path

        # Good, we have the key! Now, read the content of the key!
        public_rsa_key_content = readContentOf(key_to_read)

        # Add public RSA-key to cloudControl user account
        try:
            users = self.api.read_users()
            self.api.create_user_key(
                users[0]['username'],
                public_rsa_key_content)

        except ConflictDuplicateError:
            raise InputErrorException('KeyDuplicate')