Skip to content

Commit

Permalink
Windows compat
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Nov 30, 2019
1 parent 552749a commit 07e2ac7
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions salt/grains/minion_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,57 @@
Set grains describing the minion process.
'''

# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals

import os

# Import salt libs
import salt.utils.user
import salt.utils.platform

try:
import pwd
except ImportError:
import getpass
pwd = None

try:
import grp
except ImportError:
grp = None


def _uid():
'''
Grain for the minion User ID
'''
if salt.utils.platform.is_windows():
return None
return os.getuid()
return salt.utils.user.get_uid()


def _username():
'''
Grain for the minion username
'''
if pwd:
username = pwd.getpwuid(os.getuid()).pw_name
else:
username = getpass.getuser()

return username
return salt.utils.user.get_user()


def _gid():
'''
Grain for the minion Group ID
'''
if salt.utils.platform.is_windows():
return None
return os.getgid()
return salt.utils.user.get_gid()


def _groupname():
'''
Grain for the minion groupname
'''
if grp:
try:
groupname = grp.getgrgid(os.getgid()).gr_name
except KeyError:
groupname = ''
else:
groupname = ''

return groupname
try:
return salt.utils.user.get_default_group(_username()) or ''
except KeyError:
return ''


def _pid():
'''
Return the current process pid
'''
return os.getpid()


def grains():
'''
Return the grains dictionary
'''
ret = {
'username': _username(),
'groupname': _groupname(),
Expand Down

0 comments on commit 07e2ac7

Please sign in to comment.