Commit 360b0dc2 authored by Iustin Pop's avatar Iustin Pop
Browse files

backend: Only build once the list of upload files



The list of upload files is built currently at every UploadFile() call.
This patch moves it to a separate variable which is initialized only
once.

This won't make much difference but I regard it as cleanup.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent b8f31860
......@@ -19,7 +19,12 @@
# 02110-1301, USA.
"""Functions used by the node daemon"""
"""Functions used by the node daemon
@var _ALLOWED_UPLOAD_FILES: denotes which files are accepted in
the L{UploadFile} function
"""
import os
......@@ -115,6 +120,23 @@ def _CleanDirectory(path, exclude=None):
utils.RemoveFile(full_name)
def _BuildUploadFileList():
"""Build the list of allowed upload files.
This is abstracted so that it's built only once at module import time.
"""
return frozenset([
constants.CLUSTER_CONF_FILE,
constants.ETC_HOSTS,
constants.SSH_KNOWN_HOSTS_FILE,
constants.VNC_PASSWORD_FILE,
])
_ALLOWED_UPLOAD_FILES = _BuildUploadFileList()
def JobQueuePurge():
"""Removes job queue files and archived jobs.
......@@ -1460,14 +1482,7 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
file_name)
return False
allowed_files = [
constants.CLUSTER_CONF_FILE,
constants.ETC_HOSTS,
constants.SSH_KNOWN_HOSTS_FILE,
constants.VNC_PASSWORD_FILE,
]
if file_name not in allowed_files:
if file_name not in _ALLOWED_UPLOAD_FILES:
logging.error("Filename passed to UploadFile not in allowed"
" upload targets: '%s'", file_name)
return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment