Skip to content

Commit

Permalink
add check for sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
laszewsk committed Dec 19, 2023
1 parent 31e9aab commit 29cbf37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ source: welcome ## Install the package in source mode
pip: welcome ## Install the package in pip mode
pip install -e . -U --config-settings editable_mode=strict


##############################################################################
# CHECK
##############################################################################
Expand Down
14 changes: 14 additions & 0 deletions src/cloudmesh/common/security.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import random
import string
import os
import subprocess

def can_use_sudo():
"""Checks if the current user has sudo privileges.
Returns:
bool: True if the user has sudo privileges, False otherwise.
"""
try:
# The 'id -u' command returns the user ID. When run with sudo, it should return 0 (the ID of the root user).
output = subprocess.check_output('sudo id -u', shell=True).decode().strip()
return output == '0'
except subprocess.CalledProcessError:
return False

def generate_strong_pass():
"""Generates a password from letters, digits and punctuation
Expand Down

0 comments on commit 29cbf37

Please sign in to comment.