Created
March 8, 2016 17:17
-
-
Save badvision/24c99a523002e16d1f5a to your computer and use it in GitHub Desktop.
Part 2 of building user information (See getGroupInfo.groovy for instructions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.* | |
def slurper = new JsonSlurper() | |
slurper.setType(JsonParserType.INDEX_OVERLAY); | |
def groupDir = '.' as File | |
def output = 'matrix.txt' as File | |
def users = new TreeMap(); | |
def userGroups = new HashMap(); | |
def allGroups = new TreeSet(); | |
groupDir.list({d, f-> f ==~ /.*.json/ } as FilenameFilter).each{jsonFile -> | |
def data = slurper.parse(new File(groupDir, jsonFile)) | |
def groupName = data.authorizableId; | |
if (data.members && data.members.size() > 0) { | |
allGroups += groupName; | |
} | |
data.members.each{user -> | |
def userName = user.authorizableId; | |
if (!users.containsKey(userName)) { | |
userGroups[userName] = new HashSet(); | |
users[userName] = user; | |
} | |
userGroups[userName] += groupName; | |
} | |
} | |
FileWriter fileWriter = new FileWriter(output, false) | |
BufferedWriter buffWriter = new BufferedWriter(fileWriter) | |
buffWriter.write("User\tHome\tCount") | |
allGroups.each{buffWriter.write("\t${it}")} | |
users.each{userName,userObject -> | |
def groups = userGroups[userName] | |
buffWriter.write("\n${userName}\t${userObject.home}\t${groups.size()}") | |
allGroups.each{ | |
buffWriter.write("\t${groups.contains(it)?'X':''}") | |
} | |
} | |
buffWriter.flush() | |
buffWriter.close() | |
"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment