forked from uncloud/uncloud
Move all files to _etc_based
This commit is contained in:
parent
10f09c7115
commit
3cf3439f1c
116 changed files with 1 additions and 0 deletions
26
uncloud_etcd_based/uncloud/common/cli.py
Normal file
26
uncloud_etcd_based/uncloud/common/cli.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from uncloud.common.shared import shared
|
||||
from pyotp import TOTP
|
||||
|
||||
|
||||
def get_token(seed):
|
||||
if seed is not None:
|
||||
try:
|
||||
token = TOTP(seed).now()
|
||||
except Exception:
|
||||
raise Exception('Invalid seed')
|
||||
else:
|
||||
return token
|
||||
|
||||
|
||||
def resolve_otp_credentials(kwargs):
|
||||
d = {
|
||||
'name': shared.settings['client']['name'],
|
||||
'realm': shared.settings['client']['realm'],
|
||||
'token': get_token(shared.settings['client']['seed'])
|
||||
}
|
||||
|
||||
for k, v in d.items():
|
||||
if k in kwargs and kwargs[k] is None:
|
||||
kwargs.update({k: v})
|
||||
|
||||
return d
|
||||
Loading…
Add table
Add a link
Reference in a new issue