Skip to content

Commit

Permalink
Merge branch 'minio' of github.com:truenas/apps into minio-enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed May 2, 2024
2 parents 5b88c2c + f8d8fc4 commit eca4e40
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions library/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,50 @@ def func_host_path_with_perms(data: dict, root: dict, perms: dict) -> str:

path = ''
if data['type'] == 'host_path':
if not data.get('host_path_config', {}):
throw_error("Host Path Configuration: [host_path_config] must be set")
if not data['host_path_config'].get('path', ''):
throw_error("Host Path Configuration: [host_path_config.path] must be set")
path = data['host_path_config']['path']
path = process_host_path(data, root, perms)
elif data['type'] == 'ix_volume':
path = process_ix_volume(data, root)
else:
throw_error(f"Type [{data['type']}] is not supported")

os.makedirs(path, exist_ok=True)

# FIXME: only do such things if user agreed or if its ixVolumes
if perms.get('user') and perms.get('group'):
# Set permissions
os.chown(path, int(perms['user']), int(perms['group']))

return path

def process_ix_volume(data: dict, root: dict) -> dict:
path = ''
if not data.get('ix_volume_config', {}):
throw_error("IX Volume Configuration: [ix_volume_config] must be set")

if not data['ix_volume_config'].get('dataset_name', ''):
throw_error("IX Volume Configuration: [ix_volume_config.dataset_name] must be set")

if not root.get('ixVolumes', []):
throw_error("IX Volume Configuration: [ixVolumes] must be set")

for item in root['ixVolumes']:
if not item.get('hostPath', ''):
throw_error("IX Volume Configuration: [ixVolumes] item must contain [hostPath]")

if item['hostPath'].split('/')[-1] == data['ix_volume_config']['dataset_name']:
path = item['hostPath']
break

if not path:
throw_error(f"IX Volume Configuration: [ixVolumes] does not contain dataset with name [{data['ix_volume_config']['dataset_name']}]")
else:
throw_error(f"Type [{data['type']}] is not supported")

return path

os.makedirs(path, exist_ok=True)
def process_host_path(data: dict, root: dict, perms: dict) -> str:
if not data.get('host_path_config', {}):
throw_error("Host Path Configuration: [host_path_config] must be set")

# FIXME: only do such things if user agreed or if its ixVolumes
if perms.get('user') and perms.get('group'):
# Set permissions
os.chown(path, int(perms['user']), int(perms['group']))
if not data['host_path_config'].get('path', ''):
throw_error("Host Path Configuration: [host_path_config.path] must be set")

return path
return data['host_path_config']['path']

0 comments on commit eca4e40

Please sign in to comment.