jaraco / keyring

MIT License
1.24k stars 152 forks source link

return value is none #654

Closed prasaanth2k closed 9 months ago

prasaanth2k commented 10 months ago

when we run this code a sudo it is retuning none why?

class Store:
    def __init__(self):
        self.servicename = "your_service_name"
        self.username = "your_username"

    def setkey(self, password):
        keyring.set_password(self.servicename, self.username, password)

    def getkey(self):
        return keyring.get_password(self.servicename, self.username)

    def getsess(self):
        sess = keyring.get_password(self.servicename, self.username)
        return sess

    def deletekey(self):
        if keyring.get_password(self.servicename, self.username):
            if keyring.delete_password(self.servicename, self.username):
                return True
        return False

ob = Store()
print(ob.getkey())
# ob.deletekey()`
jaraco commented 9 months ago

Probably something about running under sudo changes the assumptions, such as what settings are in $HOME or what backends are available or what credentials are readable.

prasaanth2k commented 9 months ago

Yes, bro, that's correct. This keyring works on user basics. When we store the value in the keyring, it also stores it with the current user's name. There are some conditions:

When we store with sudo, and we need to fetch the data with sudo, a normal user can't fetch it. When we store as a normal user, we can fetch it with sudo. So, it's our decision whether we go with sudo or a normal user.