mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-29 14:57:15 +08:00
upgrade_server: Fix permission system
This commit is contained in:
parent
6d2dbea6e9
commit
3b4d64f85c
3 changed files with 21 additions and 21 deletions
|
|
@ -4,22 +4,18 @@ http_server:
|
|||
listen: 0.0.0.0
|
||||
port: 8080
|
||||
users:
|
||||
- upgrade_client:
|
||||
- username: upgrade_client_user
|
||||
password: super_secret_password
|
||||
permissions:
|
||||
- audience:
|
||||
audience:
|
||||
- private
|
||||
- public
|
||||
|
||||
|
||||
upgrades:
|
||||
# Build dir should contain the following structure
|
||||
# /VERSION
|
||||
# VERSION is a file containing a single line with the currently built NPBackup version, example: 2.2.0
|
||||
# /{platform}/{arch}/{binary}/{audience}
|
||||
# Current platforms are 'windows', 'linux'
|
||||
# Current arches are 'x64', 'x86', 'arm' and 'arm64'
|
||||
# In each folder there should be a npbackup or npbackup.exe binary depending on the platform
|
||||
data_root: /var/npbackup_upgrade_server/dist
|
||||
# We'll store a CSV containing backup clients that upgrade here
|
||||
statistics_file: /var/npbackup_upgrade_server/stats.csv
|
||||
|
||||
# See github wiki for more explanation of the contents of data_root dir
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
|
|||
for user in config_dict["http_server"]["users"]:
|
||||
try:
|
||||
if secrets.compare_digest(
|
||||
credentials.username.encode("utf-8"), user.encode("utf-8")
|
||||
credentials.username.encode("utf-8"), user.get("username").encode("utf-8")
|
||||
):
|
||||
if secrets.compare_digest(
|
||||
credentials.password.encode("utf-8"),
|
||||
config_dict["http_server"]["users"]["user"]["password"].encode(
|
||||
user.get("password").encode(
|
||||
"utf-8"
|
||||
),
|
||||
):
|
||||
|
|
@ -92,10 +92,14 @@ def get_user_permissions(username: str):
|
|||
Returns a list of permissions
|
||||
"""
|
||||
try:
|
||||
return config_dict["http_server"]["users"][username]["permissions"]
|
||||
for user in config_dict["http_server"]["users"]:
|
||||
if user.get("username") == username:
|
||||
return user.get("permissions")
|
||||
except Exception as exc:
|
||||
logger.error(f"Failed to get user permissions: {exc}")
|
||||
return []
|
||||
logger.error(f"Failed to get user permissions from configuration file: {exc}")
|
||||
logger.debug("Trace", exc_info=True)
|
||||
return []
|
||||
|
||||
|
||||
|
||||
@app.get("/")
|
||||
|
|
@ -161,10 +165,10 @@ async def current_version(
|
|||
|
||||
try:
|
||||
has_permission = (
|
||||
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||
True if audience.value in get_user_permissions(auth).get("audience") else False
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(f"Failed to get user permissions: {exc}")
|
||||
logger.error(f"Failed to get user permissions (1): {exc}")
|
||||
has_permission = False
|
||||
|
||||
data = {
|
||||
|
|
@ -261,10 +265,10 @@ async def upgrades(
|
|||
|
||||
try:
|
||||
has_permission = (
|
||||
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||
True if audience.value in get_user_permissions(auth).get("audience") else False
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(f"Failed to get user permissions: {exc}")
|
||||
logger.error(f"Failed to get user permissions (2): {exc}")
|
||||
has_permission = False
|
||||
|
||||
data = {
|
||||
|
|
@ -363,10 +367,10 @@ async def download(
|
|||
|
||||
try:
|
||||
has_permission = (
|
||||
True if audience.value in get_user_permissions(auth)["audience"] else False
|
||||
True if audience.value in get_user_permissions(auth).get("audience") else False
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(f"Failed to get user permissions: {exc}")
|
||||
logger.error(f"Failed to get user permissions (3): {exc}")
|
||||
has_permission = False
|
||||
|
||||
data = {
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ def store_host_info(destination: str, host_id: dict) -> None:
|
|||
data = (
|
||||
datetime.now(timezone.utc).isoformat()
|
||||
+ ","
|
||||
+ ",".join([value if value else "" for value in host_id.values()])
|
||||
+ ",".join([str(value) if value else "" for value in host_id.values()])
|
||||
+ "\n"
|
||||
)
|
||||
with open(destination, "a", encoding="utf-8") as fpw:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue