Skip to content

Commit 0427f63

Browse files
shifengbinCendioOssman
authored andcommitted
feat: TokenFileName
1 parent 43c371f commit 0427f63

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

websockify/token_plugins.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ def lookup(self, token):
6565

6666
return super().lookup(token)
6767

68+
class TokenFileName(BasePlugin):
69+
# source is a directory
70+
# token is filename
71+
# contents of file is host:port
72+
def __init__(self, src):
73+
super().__init__(src)
74+
if not os.path.isdir(src):
75+
raise Exception("TokenFileName plugin requires a directory")
76+
77+
def lookup(self, token):
78+
token = os.path.basename(token)
79+
path = os.path.join(self.source, token)
80+
if os.path.exists(path):
81+
return open(path).read().strip().split(':')
82+
else:
83+
return None
84+
6885

6986
class BaseTokenAPI(BasePlugin):
7087
# source is a url with a '%s' in it where the token

0 commit comments

Comments
 (0)