125 lines
3.8 KiB
Python
125 lines
3.8 KiB
Python
import os
|
|
import requests
|
|
import yaml
|
|
|
|
|
|
def get_user_teams_map(all_teams_details):
|
|
body = {}
|
|
for team in all_teams_details:
|
|
for member in team["members"]:
|
|
user = member["user"]
|
|
if user["email"] not in body:
|
|
body[user["email"]] = []
|
|
return body
|
|
|
|
|
|
def user_roles(user_teams):
|
|
user_roles_map = {}
|
|
env = ["cmd", "prod", "dev", "qa", "perf", "uat", "data-platform-prod", "data-platform-nonprod"]
|
|
# list from okta
|
|
managers = {
|
|
"harinder.singh@navi.com",
|
|
"aviral.harsh@navi.com",
|
|
"ankit.jain@navi.com",
|
|
"abhishek.k@navi.com",
|
|
"yagyansh.k@navi.com",
|
|
"deepak.jain@navi.com",
|
|
"ashvin.s@navi.com",
|
|
"bhanu.teja@navi.com",
|
|
"sagar.popat@navi.com",
|
|
"chandrapal.bn@navi.com",
|
|
"sanjog.panda@navi.com",
|
|
"akash.nagar@navi.com",
|
|
"koshtubh.m@navi.com",
|
|
"chetan.k@navi.com",
|
|
"setu.poddar@navi.com",
|
|
"mayur.patki@navi.com",
|
|
"abhishek.kumar@navi.com",
|
|
"saurabh.araiyer@navi.com",
|
|
"ravi.raipuria@navi.com",
|
|
"md.anees@navi.com",
|
|
"sarthak.b@navi.com",
|
|
"purushotham.p@navi.com",
|
|
"abhrajit.chattopadhyay@navi.com",
|
|
"rohit.mishra@navi.com",
|
|
"praveen.jha@navi.com",
|
|
"surajit.chongder@navi.com",
|
|
"satish.prasad@navi.com",
|
|
"raaj.gopal@navi.com",
|
|
"daivat.vaishnani@navi.com",
|
|
"shardul.singh@navi.com",
|
|
"anshul.shukla@navi.com",
|
|
"tatinati.sivanagaraja@navi.com",
|
|
"gujju.chanakya@navi.com",
|
|
"apoorva.gupta@navi.com",
|
|
"mudit.raj@navi.com",
|
|
"sajal.gupta@navi.com",
|
|
"praveen.p@navi.com",
|
|
"sneha.goel@navi.com",
|
|
"ankit.sorathiya@navi.com",
|
|
"chandresh.pancholi@navi.com",
|
|
"jai.gangwani@navi.com",
|
|
"ashish.tadose@navi.com",
|
|
"rahul.bhat@navi.com",
|
|
"mohd.danish@navi.com",
|
|
"raju.raghuwanshi@navi.com",
|
|
"amit.jambotkar@navi.com",
|
|
}
|
|
for user, teams in user_teams.items():
|
|
roles = []
|
|
for team in teams:
|
|
for e in env:
|
|
roles.append(f"{team}_{e}_MAINTAINER")
|
|
if user in managers:
|
|
roles.append(f"{team}_{e}_MANAGER")
|
|
user_roles_map[user] = {}
|
|
user_roles_map[user]["roles"] = roles
|
|
return user_roles_map
|
|
|
|
|
|
def get_all_teams(z_request, blacklist_team, team_name_map):
|
|
list_team_api = "https://www.zenduty.com/api/account/teams"
|
|
response = z_request.get(list_team_api)
|
|
if response.status_code != 200:
|
|
raise Exception("Error while fetching teams")
|
|
teams = response.json()
|
|
|
|
teams = [team for team in teams if team["name"] not in blacklist_team]
|
|
|
|
for team in teams:
|
|
if team["name"] in team_name_map:
|
|
team["name"] = team_name_map[team["name"]]
|
|
|
|
return teams
|
|
|
|
|
|
def cleanup_user_teams(user_teams):
|
|
return user_teams
|
|
|
|
|
|
def main():
|
|
ZENDUTY_API_KEY = os.getenv("ZENDUTY_TOKEN", "")
|
|
if ZENDUTY_API_KEY == "":
|
|
raise Exception("Zenduty API key not found")
|
|
|
|
zendutyrequest = requests.Session()
|
|
zendutyrequest.headers.update({"Authorization": f"Token {ZENDUTY_API_KEY}"})
|
|
|
|
blacklist_team = ["Global Team", "Android", "Date Change", "Infra Team(Sample)", "iOS",
|
|
"IT-Network", "Kubernetes Platform"]
|
|
team_name_map: dict = {
|
|
"HL": "HL-Conversions"
|
|
}
|
|
|
|
all_teams_details = get_all_teams(zendutyrequest, blacklist_team, team_name_map)
|
|
user_teams = get_user_teams_map(all_teams_details)
|
|
cleaned_user_teams = cleanup_user_teams(user_teams)
|
|
content = user_roles(cleaned_user_teams)
|
|
|
|
with open("user_roles.yaml", "w") as file:
|
|
yaml.dump(content, file, default_flow_style=None, width=10000)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|