Skip to content

Instantly share code, notes, and snippets.

@jbaker10
Created October 10, 2019 18:24
Show Gist options
  • Save jbaker10/e2c053c1a56ffd59974133d998cccb59 to your computer and use it in GitHub Desktop.
Save jbaker10/e2c053c1a56ffd59974133d998cccb59 to your computer and use it in GitHub Desktop.
import yaml
from itertools import islice
user = {
"email": "[email protected]",
"department": "Sales",
"title": "Senior Account Executive",
"location": "New York",
"salesRegion": "Americas",
"costCenter": "Enterprise Sales",
"referenceId": "Test"
}
with open("/Users/jeremy.baker/Desktop/groups.yaml", "r") as f:
conditions = yaml.safe_load(f)
for condition in conditions.get("conditions", {}):
print("Working on condition {}".format(condition.get("name", "")))
if condition.get("type", "") == "and":
match = True
for attr in condition.get("attributes", []):
key = next(iter(attr))
val = attr[key]
if "*" in val and val in user[key]:
print("Attribute {} with defined value {} matched for user {}, continuing".format(key, val, user.get("email", "")))
elif user[key] == val:
print("Attribute {} with defined value {} matched for user {}, continuing".format(key, val, user.get("email", "")))
else:
print("Attribute {} with defined value {} did not match for user {}".format(key, val, user.get("email", "")))
match = False
break
if match:
print("We have finished condition {} and need to make a Google groups change now".format(condition.get("name", "")))
for group in condition.get("groups", []):
google_group_address = ""
group_enumerator = iter(enumerate(group))
for i, char in group_enumerator:
if char == "{":
close_bracket_i = group.find("}", i)
var = group[i+1:close_bracket_i]
google_group_address += user.get(var, "")
next(islice(group_enumerator, close_bracket_i-i, 0), "")
else:
google_group_address += char
print("Adding user to {}".format(google_group_address))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment