Skip to content

Commit

Permalink
⚫ Fade to black.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Feb 11, 2021
1 parent f2b1706 commit 41f356b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
41 changes: 21 additions & 20 deletions jaraco/keyring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@


class RemoteAgent(keyring.backend.KeyringBackend):
"""
>>> agent = RemoteAgent()
"""
path = '/tmp/keyring.sock'
path_enc = urllib.parse.quote(path, safe='')
_url_tmpl = 'http+unix://%(path_enc)s/{service}/{username}' % locals()

priority = 0

def get_password(self, service, username):
url = self._url_tmpl.format(**locals())
return session.get(url).text

def set_password(self, service, username, password):
url = self._url_tmpl.format(**locals())
session.post(url, data=password)

def delete_password(self, service, username):
url = self._url_tmpl.format(**locals())
session.delete(url).raise_for_status()
"""
>>> agent = RemoteAgent()
"""

path = '/tmp/keyring.sock'
path_enc = urllib.parse.quote(path, safe='')
_url_tmpl = 'http+unix://%(path_enc)s/{service}/{username}' % locals()

priority = 0

def get_password(self, service, username):
url = self._url_tmpl.format(**locals())
return session.get(url).text

def set_password(self, service, username, password):
url = self._url_tmpl.format(**locals())
session.post(url, data=password)

def delete_password(self, service, username):
url = self._url_tmpl.format(**locals())
session.delete(url).raise_for_status()
54 changes: 27 additions & 27 deletions jaraco/keyring/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@


class Keyring:
exposed = True

def GET(self, service, username):
return keyring.get_password(service, username)

def PUT(self, service, username):
password = cherrypy.request.body
keyring.set_password(service, username, password)
return 'OK'

def DELETE(self, service, username):
keyring.delete_password(service, username)
return 'OK'

@classmethod
def run(cls):
config = {
'global': {
'server.socket_host': '::1',
'server.socket_port': int(os.environ.get('PORT', 4273)),
},
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
},
}
cherrypy.quickstart(cls(), config=config)
exposed = True

def GET(self, service, username):
return keyring.get_password(service, username)

def PUT(self, service, username):
password = cherrypy.request.body
keyring.set_password(service, username, password)
return 'OK'

def DELETE(self, service, username):
keyring.delete_password(service, username)
return 'OK'

@classmethod
def run(cls):
config = {
'global': {
'server.socket_host': '::1',
'server.socket_port': int(os.environ.get('PORT', 4273)),
},
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
},
}
cherrypy.quickstart(cls(), config=config)


if __name__ == '__main__':
Keyring.run()
Keyring.run()

0 comments on commit 41f356b

Please sign in to comment.