예제 #1
0
 def __init__(self, user, command, settings, streams, root_patterns):
     self.user = user
     self.command = command
     self.settings = settings
     self.stdin, self.stdout, self.stderr = streams
     self.root_patterns = root_patterns 
     self.auth_backend = auth.get_auth_backend_from_settings(settings)
예제 #2
0
    def test_loads_auth_from_settings(self):
        settings_str = """
[kittyconfig]
auth=tests.auth.StubbedAuthTest
        """.strip()
        config = ConfigParser.ConfigParser()
        config.readfp(StringIO.StringIO(settings_str))
        results = auth.get_auth_backend_from_settings(config)
        self.assertTrue(isinstance(results, StubbedAuthTest))
        self.assertTrue(isinstance(results.settings, ConfigParser.ConfigParser))
def main(name=None, key=None):
    name = sys.argv[1] if name is None else name
    key = sys.stdin.read() if key is None else key
    settings = build_settings()
    auth = get_auth_backend_from_settings(settings)
    pubkey_handler = dict(settings.items(SECTION_NAME)).get('public_key_handler', 'nappingcat.pubkey_handlers.AuthorizedKeysFile')
    pubkey_handler = import_class_from_module(pubkey_handler)()

    auth.add_user(name)
    auth.add_key_to_user(name, key)
    auth.add_permission(
        name,
        ('auth', 'adduser'),
    )
    auth.add_permission(
        name,
        ('auth', 'modifyuser'),
    )
    auth.finish(pubkey_handler)
    print "\033[0;32m%s\033[0m\n" % """
    You just created a super great super user!
    """.strip()