[api] config updates and add default values
This commit is contained in:
parent
a4bedb01f6
commit
cdbfb96e71
3 changed files with 21 additions and 16 deletions
|
@ -1,8 +1,14 @@
|
|||
# This section contains default values for all other sections
|
||||
[DEFAULT]
|
||||
|
||||
AUTH_NAME = "replace me"
|
||||
AUTH_SEED = "replace me"
|
||||
AUTH_REALM = "replace me"
|
||||
|
||||
NETWORK_PREFIX = moo
|
||||
|
||||
OTP_VERIFY_ENDPOINT = verify/
|
||||
|
||||
[api]
|
||||
NETWORK_PREFIX = foo
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
|
||||
from ucloud.config import etcd_client, env_vars
|
||||
|
||||
from ucloud.config import etcd_client, config
|
||||
|
||||
class Optional:
|
||||
pass
|
||||
|
@ -48,6 +47,6 @@ class VmUUIDField(Field):
|
|||
self.validation = self.vm_uuid_validation
|
||||
|
||||
def vm_uuid_validation(self):
|
||||
r = etcd_client.get(os.path.join(env_vars.get('VM_PREFIX'), self.uuid))
|
||||
r = etcd_client.get(os.path.join(config['api']['VM_PREFIX'], self.uuid))
|
||||
if not r:
|
||||
self.add_error("VM with uuid {} does not exists".format(self.uuid))
|
||||
|
|
|
@ -7,15 +7,15 @@ import requests
|
|||
|
||||
from pyotp import TOTP
|
||||
|
||||
from ucloud.config import vm_pool, env_vars
|
||||
from ucloud.config import vm_pool, config
|
||||
|
||||
|
||||
def check_otp(name, realm, token):
|
||||
try:
|
||||
data = {
|
||||
"auth_name": env_vars.get("AUTH_NAME"),
|
||||
"auth_token": TOTP(env_vars.get("AUTH_SEED")).now(),
|
||||
"auth_realm": env_vars.get("AUTH_REALM"),
|
||||
"auth_name": config['api']["AUTH_NAME"],
|
||||
"auth_token": TOTP(config['api']["AUTH_SEED"]).now(),
|
||||
"auth_realm": config['api']["AUTH_REALM"],
|
||||
"name": name,
|
||||
"realm": realm,
|
||||
"token": token,
|
||||
|
@ -25,8 +25,8 @@ def check_otp(name, realm, token):
|
|||
|
||||
response = requests.post(
|
||||
"{OTP_SERVER}{OTP_VERIFY_ENDPOINT}".format(
|
||||
OTP_SERVER=env_vars.get("OTP_SERVER", ""),
|
||||
OTP_VERIFY_ENDPOINT=env_vars.get("OTP_VERIFY_ENDPOINT", "verify/"),
|
||||
OTP_SERVER=config['api']["OTP_SERVER"],
|
||||
OTP_VERIFY_ENDPOINT=config['api']["OTP_VERIFY_ENDPOINT"]
|
||||
),
|
||||
json=data,
|
||||
)
|
||||
|
@ -80,7 +80,7 @@ def resolve_image_name(name, etcd_client):
|
|||
except Exception:
|
||||
raise ValueError("Image name not in correct format i.e {store_name}:{image_name}")
|
||||
|
||||
images = etcd_client.get_prefix(env_vars.get('IMAGE_PREFIX'), value_in_json=True)
|
||||
images = etcd_client.get_prefix(config['api']['IMAGE_PREFIX'], value_in_json=True)
|
||||
|
||||
# Try to find image with name == image_name and store_name == store_name
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue