예제 #1
0
def update(name, connection_uri="", id_file="", o=[]):
    """
    Enhanced version of the edit command featuring multiple edits using regular expressions to match entries
    """
    try:
        user, host, port = parse(connection_uri)

        settings = {}
        settings.setdefault('port', port)
        settings.setdefault('user', user)

        if host != "":
            settings['hostname'] = host

        if id_file != "":
            settings['identityfile'] = id_file

        for option in o:
            k, v = option.split("=")
            settings[k] = v

        storm_.update_entry(name, **settings)
        print get_formatted_message('"{0}" updated successfully.'.format(name),
                                    'success')
    except StormValueError as error:
        print get_formatted_message(error, 'error')
예제 #2
0
def update(name, connection_uri="", id_file="", o=[]):
    """
    Enhanced version of the edit command featuring multiple edits using regular expressions to match entries
    """
    try:
        user, host, port = parse(connection_uri)

        settings = {}
        settings.setdefault('port', port)
        settings.setdefault('user', user)
        
        if host != "":
            settings['hostname'] = host

        if id_file != "": 
            settings['identityfile'] = id_file

        for option in o:
            k,v = option.split("=")
            settings[k] = v

        storm_.update_entry(name, **settings)
        print(get_formatted_message(
            '"{0}" updated successfully.'.format(
                name
            ), 'success'))
    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
예제 #3
0
    def test_uri_parser(self):
        user = getpass.getuser()
        TEST_STRINGS = [('[email protected]:22', ('root', 'emreyilmaz.me',
                                                   22)),
                        ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)),
                        ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)),
                        ('*****@*****.**', ('root', 'emreyilmaz.me', 22))]

        for uri in TEST_STRINGS:
            self.assertEqual(parse(uri[0]), uri[1])

        # false strings
        self.assertRaises(StormInvalidPortError, parse,
                          '[email protected]:string-port')
예제 #4
0
    def test_uri_parser(self):
        user = getpass.getuser()
        TEST_STRINGS = [
            ('[email protected]:22', ('root', 'emreyilmaz.me', 22)),
            ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)),
            ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)),
            ('*****@*****.**', ('root', 'emreyilmaz.me', 22))
        ]

        for uri in TEST_STRINGS:
            self.assertEqual(parse(uri[0]), uri[1])

        # false strings
        self.assertRaises(StormInvalidPortError, parse, '[email protected]:string-port')
예제 #5
0
def edit(name, connection_uri, id_file="", o=[]):
    """
    Edits the related entry in ssh config.
    """
    try:
        if "," in name:
            name = " ".join(name.split(","))

        user, host, port = parse(connection_uri)

        storm_.edit_entry(name, host, user, port, id_file, o)
        print get_formatted_message('"{0}" updated successfully.'.format(name), "success")
    except StormValueError as error:
        print get_formatted_message(error, "error")
예제 #6
0
def edit(name, connection_uri, id_file="", o=[]):
    """
    Edits the related entry in ssh config.
    """
    try:
        if ',' in name:
            name = " ".join(name.split(","))

        user, host, port = parse(connection_uri)

        storm_.edit_entry(name, host, user, port, id_file, o)
        print get_formatted_message('"{0}" updated successfully.'.format(name),
                                    'success')
    except StormValueError as error:
        print get_formatted_message(error, 'error')
예제 #7
0
def edit():
    storm_ = app.get_storm()

    try:
        name = request.json['name']
        connection_uri = request.json['connection_uri']
        if 'id_file' in request.json:
            id_file = request.json['id_file']
        else:
            id_file = ''

        user, host, port = parse(connection_uri)
        storm_.edit_entry(name, host, user, port, id_file)
        return response()
    except StormValueError as exc:
        return jsonify(message=exc.message), 404
    except (KeyError, TypeError):
        return response(status=400)
예제 #8
0
파일: web.py 프로젝트: aleno/storm
def edit():
    storm_ = get_storm()

    try:
        name = request.json['name']
        connection_uri = request.json['connection_uri']
        if 'id_file' in request.json:
            id_file = request.json['id_file']
        else:
            id_file = ''

        user, host, port = parse(connection_uri)
        storm_.edit_entry(name, host, user, port, id_file)
        return response()
    except StormValueError as exc:
        return jsonify(message=exc.message), 404
    except (KeyError, TypeError):
        return response(status=400)
예제 #9
0
def add(name, connection_uri, id_file="", o=[]):
    """
    Adds a new entry to sshconfig.
    """
    try:

        # validate name
        if "@" in name:
            raise StormValueError('invalid value: "@" cannot be used in name.')
        user, host, port = parse(connection_uri)

        storm_.add_entry(name, host, user, port, id_file, o)

        print get_formatted_message(
            '{0} added to your ssh config. you can connect it by typing "ssh {0}".'.format(name), "success"
        )

    except StormValueError as error:
        print get_formatted_message(error, "error")
예제 #10
0
def edit(name, connection_uri, id_file="", o=[], config=None):
    """
    Edits the related entry in ssh config.
    """
    storm_ = get_storm_instance(config)

    try:
        if ',' in name:
            name = " ".join(name.split(","))

        user, host, port = parse(connection_uri)

        storm_.edit_entry(name, host, user, port, id_file, o)
        print(get_formatted_message(
            '"{0}" updated successfully.'.format(
                name
            ), 'success'))
    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
예제 #11
0
def add(name, connection_uri, id_file="", o=[]):
    """
    Adds a new entry to sshconfig.
    """
    try:

        # validate name
        if '@' in name:
            raise StormValueError('invalid value: "@" cannot be used in name.')
        user, host, port = parse(connection_uri)

        storm_.add_entry(name, host, user, port, id_file, o)

        print get_formatted_message(
            '{0} added to your ssh config. you can connect it by typing "ssh {0}".'
            .format(name), 'success')

    except StormValueError as error:
        print get_formatted_message(error, 'error')
예제 #12
0
def add(name, connection_uri, id_file="", o=[], config=None):
    """
    Adds a new entry to sshconfig.
    """
    storm_ = get_storm_instance(config)

    try:

        # validate name
        if '@' in name:
            raise StormValueError('invalid value: "@" cannot be used in name.')
        user, host, port = parse(connection_uri)
        storm_.add_entry(name, host, user, port, id_file, o)

        print(get_formatted_message('{0} added to your ssh config. you can connect it by typing "ssh {0}".'.format(

            name
        ), 'success'))

    except StormValueError as error:
        print(get_formatted_message(error, 'error'), file=sys.stderr)
예제 #13
0
def add():
    storm_ = app.get_storm()

    try:
        name = request.json['name']
        connection_uri = request.json['connection_uri']
        if 'id_file' in request.json:
            id_file = request.json['id_file']
        else:
            id_file = ''

        if '@' in name:
            msg = 'invalid value: "@" cannot be used in name.'
            return jsonify(message=msg), 400

        user, host, port = parse(connection_uri)
        storm_.add_entry(name, host, user, port, id_file)
        return response(status=201)
    except StormValueError as exc:
        return jsonify(message=exc.message)
    except (KeyError, TypeError):
        return response(status=400)
예제 #14
0
파일: web.py 프로젝트: aleno/storm
def add():
    storm_ = get_storm()

    try:
        name = request.json['name']
        connection_uri = request.json['connection_uri']
        if 'id_file' in request.json:
            id_file = request.json['id_file']
        else:
            id_file = ''

        if '@' in name:
            msg = 'invalid value: "@" cannot be used in name.'
            return jsonify(message=msg), 400

        user, host, port = parse(connection_uri)
        storm_.add_entry(name, host, user, port, id_file)
        return response(status=201)
    except StormValueError as exc:
        return jsonify(message=exc.message)
    except (KeyError, TypeError):
        return response(status=400)
예제 #15
0
 def parse_connection_uri(self, connection_uri):
     options = dict()
     options["user"], options["hostname"], options["port"] = parse(
         connection_uri)
     return options
예제 #16
0
 def parse_connection_uri(self, connection_uri):
     options = {}
     options["user"], options["hostname"], options["port"] = parse(connection_uri)
     return options