Esempio 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))
Esempio 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
Esempio 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"))
Esempio n. 4
0
File: ui.py Progetto: 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))
Esempio 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"))
Esempio 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"))
Esempio n. 7
0
File: ui.py Progetto: 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))
Esempio n. 8
0
File: ui.py Progetto: 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))
Esempio n. 9
0
File: ui.py Progetto: 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]))
Esempio n. 10
0
File: ui.py Progetto: pboyd/passwdr
 def _command_list(self, args):
     kernel.queue(events.GetAccountList())
Esempio n. 11
0
 def _handle_GetAccountList(self, event):
     accounts = self._load()
     kernel.queue(events.AccountList(accounts))