@ -7,14 +7,16 @@
# sets the posix attributes of a user
# sets the posix attributes of a user
#
#
# Format of csv file is three columns no header
# Format of csv file is three columns no header
# Column 1 userid
# Column 1 Principal Type (User or Group)
# Column 2 numeric override uid
# Column 2 userid or group
# Column 3 numeric override primary gid
# Column 3 numeric override user or group
# Column 4 numeric override primary uid or gid
#
#
# For example:
# For example:
#Santiago,9000,9001
#GROUP,HR,99999
#Hugh,8000,8001
#USER,Santiago,9000,9001
#Fay,7000,9001
#USER,Hugh,8000,8001
#USER,Fay,7000,9001
#
#
# Copyright © 2022, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# Copyright © 2022, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
#
#
@ -38,7 +40,7 @@ import os
from sharedfunctions import printresult , callrestapi , file_accessible
from sharedfunctions import printresult , callrestapi , file_accessible
# setup command-line arguements
# setup command-line arguements
parser = argparse . ArgumentParser ( description = " Set POSIX attributes for User (uid and gid) file format: user,uid,gid " )
parser = argparse . ArgumentParser ( description = " Set POSIX attributes for User and Group (uid and gid) file format: principal type,principal,id of user or group, primary gid for users " )
parser . add_argument ( " -f " , " --file " , help = " Full path to csv containing posix attributes. " , required = ' True ' )
parser . add_argument ( " -f " , " --file " , help = " Full path to csv containing posix attributes. " , required = ' True ' )
parser . add_argument ( " -d " , " --debug " , action = ' store_true ' , help = " Debug " )
parser . add_argument ( " -d " , " --debug " , action = ' store_true ' , help = " Debug " )
@ -62,28 +64,33 @@ if check:
filecontents = csv . reader ( f )
filecontents = csv . reader ( f )
for row in filecontents :
for row in filecontents :
# column1 is user, column2 is uid column3 is gid
# column1 is principal type, column 2 is principal, column3 is id column3 is gid for user
user = row [ 0 ]
uid = row [ 1 ]
gid = row [ 2 ]
#request
principal_type = row [ 0 ]
reqval = ' /identities/users/ ' + user + " /identifier "
principal = row [ 1 ]
id = row [ 2 ]
# build the json
if principal_type . upper ( ) == " USER " :
data = { }
data [ ' username ' ] = user
data [ ' gid ' ] = gid
data [ ' uid ' ] = uid
# print debug info
gid = row [ 3 ]
if debug :
print ( reqval )
#request
print ( row )
reqval = ' /identities/users/ ' + principal + " /identifier "
print ( data )
# build the json
data = { }
data [ ' gid ' ] = gid
data [ ' uid ' ] = id
print ( " NOTE: Upating Posix Attributes for " + principal_type + " " + principal + " : uid= " + id + " , gid= " + gid )
print ( " NOTE: Upating Posix Attributes for " + user + " : uid= " + uid + " , gid= " + gid )
elif principal_type . upper ( ) == " GROUP " :
#request
reqval = ' /identities/groups/ ' + principal + " /identifier "
data = { }
data [ ' gid ' ] = id
print ( " NOTE: Upating Posix Attributes for " + principal_type + " " + principal + " : gid= " + id )
else :
print ( " ERROR: principal type is " + principal_type + " for principal " + principal + " . P rincipal type (column1 in csv) must be USER or GROUP. " )
reqaccept = ' application/vnd.sas.identity.identifier+json '
reqaccept = ' application/vnd.sas.identity.identifier+json '