Exemplo n.º 1
0
    def _handle_FindAccountByKey(self, event):
        accounts = self._load()

        a = self._find_by_key(accounts, event.key)
        if a == None:
            kernel.queue(events.NotFound())
        else:
            a.setEncryptionKey(event.encryption_key)
            kernel.queue(events.AccountFound(a))
Exemplo n.º 2
0
    def _has_duplicate_keys(self, accounts):
        keys = {}
        for acct in accounts:
            if acct.key() in keys:
                kernel.queue(events.DuplicateKeyError(acct.key()))
                return True

            keys[acct.key()] = 1

        return False
Exemplo n.º 3
0
    def _handle_NewAccount(self, event):
        accounts = self._load()
        accounts.append(event.account)

        if self._has_duplicate_keys(accounts):
            return

        persistance.write(self._path, accounts)

        kernel.queue(events.Success("Account created"))
Exemplo n.º 4
0
Arquivo: ui.py Projeto: pboyd/passwdr
    def _command_add(self, args):
        if len(args.args) < 3:
            print "usage: add account_key username password [note]"
            return

        account = Account(args.args[0], args.key)
        account.setUsername(args.args[1])
        account.setPassword(args.args[2])
        if len(args.args) > 3:
            account.setNote(args.args[3])

        kernel.queue(events.NewAccount(account))
Exemplo n.º 5
0
    def _handle_DeleteAccount(self, event):
        accounts = self._load()
        a = self._find_by_key(accounts, event.key)

        if a == None:
            kernel.queue(events.NotFound())
            return

        accounts.remove(a)
        persistance.write(self._path, accounts)

        kernel.queue(events.Success("Account removed"))
Exemplo n.º 6
0
    def _handle_UpdateAccountField(self, event):
        accounts = self._load()
        a = self._find_by_key(accounts, event.key)

        if a == None:
            kernel.queue(events.NotFound())
            return

        if event.field == "password":
            a.setEncryptionKey(event.encryption_key)
            a.setPassword(event.value)
        else:
            setter = "set%s" % (event.field.title())
            if hasattr(a, setter):
                method = getattr(a, setter)
                method(event.value)

        if self._has_duplicate_keys(accounts):
            return

        persistance.write(self._path, accounts)

        kernel.queue(events.Success("Account updated"))
Exemplo n.º 7
0
Arquivo: ui.py Projeto: pboyd/passwdr
    def _command_set(self, args):
        if len(args.args) != 3:
            print "usage: set account_key field new_value"
            return

        kernel.queue(events.UpdateAccountField(args.args[0], args.args[1], args.args[2], args.key))
Exemplo n.º 8
0
Arquivo: ui.py Projeto: pboyd/passwdr
    def _command_show(self, args):
        if len(args.args) == 0:
            print "usage: show account_key"
            return

        kernel.queue(events.FindAccountByKey(args.args[0], args.key))
Exemplo n.º 9
0
Arquivo: ui.py Projeto: pboyd/passwdr
    def _command_rm(self, args):
        if len(args.args) == 0:
            print "usage: rm account_key"
            return

        kernel.queue(events.DeleteAccount(args.args[0]))
Exemplo n.º 10
0
Arquivo: ui.py Projeto: pboyd/passwdr
 def _command_list(self, args):
     kernel.queue(events.GetAccountList())
Exemplo n.º 11
0
 def _handle_GetAccountList(self, event):
     accounts = self._load()
     kernel.queue(events.AccountList(accounts))