]>
git.mar77i.info Git - hublib/blob - hub/utils.py
ae1fd1242684f692ccec08e4293fcaba6807214e
1 from base64
import urlsafe_b64encode
2 from hashlib
import pbkdf2_hmac
3 from pathlib
import Path
5 from jinja2_simple_tags
import StandaloneTag
8 class StaticTag(StandaloneTag
):
11 def render(self
, filename
="/", hubapp
=None):
13 hubapp
= self
.context
["hubapp"]
14 elif isinstance(hubapp
, str):
15 hubapp
= self
.context
["hubapp"].app
.get_hubapp_by_name(hubapp
)
16 return hubapp
.uri_from(Path(filename
))
19 def scramble(secret
, value
):
20 if isinstance(value
, str):
21 value
= value
.encode()
22 if isinstance(secret
, str):
23 secret
= secret
.encode()
24 return urlsafe_b64encode(
25 pbkdf2_hmac("sha512", value
, secret
, 221100)
26 ).rstrip(b
"=").decode("ascii")
29 def get_redis_pass(redis_conf
):
30 prefix
= "requirepass "
31 with open(redis_conf
, "rt") as fh
:
33 if not line
.startswith(prefix
):
35 return line
[len(prefix
) :].rstrip()