2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-26 03:19:48 +00:00

Update auth.py

This commit is contained in:
erderial 2023-03-07 21:08:01 +02:00 committed by GitHub
parent cf2f5aac7b
commit 56dea2422a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,24 +117,37 @@ class PromptsNeeded(Exception):
self.prompts = prompts
#add function to change _allowedbyrole and _deniedbyrole vars.
def add_roles(dictionary):
def add_roles(_allowed,_denied):
#function to parse the roles and the files. If there are modifications to be done to the roles, items will be added to dictionaries.
#If there are no moodifications done to one of the roles, it continues to the next
#Opening YAML file and reading the custom roles
with open("/etc/confluent/authorization.yaml","r") as stream:
loaded_file = yaml.safe_load(stream)
try:
dictionary.update(loaded_file)
except FileNotFoundError:
return "File does not exist"
allowed_loaded = loaded_file["_allowedbyrole"]
except:
pass
try:
denied_loaded = loaded_file["_deniedbyrole"]
except:
pass
try:
_allowed.update(allowed_loaded)
except NameError:
pass
try:
_denied.update(denied_loaded)
except NameError:
pass
return
def check_for_yaml():
#checking if the file exists
if exists("/etc/confluent/authorization.yaml"):
add_roles(_allowedbyrole)
add_roles(_deniedbyrole)
add_roles(_allowedbyrole,_deniedbyrole)
return "Custom auth. file detected in /etc/confluent, updated roles accordingly"
else:
return "No custom auth. file. Continuing as normal"