Skip to content

Commit

Permalink
modifiedthe code based on run book
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaykannan21 committed May 2, 2024
1 parent 6a4d640 commit d095b8e
Showing 1 changed file with 65 additions and 15 deletions.
80 changes: 65 additions & 15 deletions test/test_bin/test_autoleaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,72 @@
class LeaverProcess:
def __init__(self,name):
self.name =name
self.headers = {'Authorization': 'token'}
self.headers = {'Authorization': 'github_token'}

def revoke_operations_engineering_access(self, github_username, one_password_email):
# Use GitHub API to remove user from organisations
github_api_url = "https://api.github.com/orgs/MOJ/memberships/" + github_username
headers = {"Authorization": "Bearer YOUR_GITHUB_TOKEN"}
response = requests.delete(github_api_url, headers=headers)
if response.status_code !=204:
raise Exception("Failed to remove user from organisation")
# Need to use 1Password API to remove user
#
#
def process_leaver(self, github_username, one_password_email):
self.revoke_operations_engineering_access(github_username, one_password_email)


def revoke_github_access(self):
response = requests.delete(f"https://api.github.com/org/org/members/{self.name}", headers=self.headers)
return response.status_code

def revoke_gandi_access(self):
api_key ='need to input api key'
user_email= self.name

url = f"https://api.gandi.net/v5/organisation/{organisation_id}/members/{user_email}"
headers = {
'Authorization': f'Apikey {api_key}',
'content-Type': 'application/json'
}
try:
response = requests.delete(url, headers=headers)
return response.status_code
except Exception as e:
print(f"Revoking access from Gandi.net: {e}")
return None
def revoke_osdatahub_access(self):
api_key = 'need to input api key'
user_email= self.name

url =f"https://api.osdatahub.os.uk/v0/users/{user-email}/revoke-access"
headers = {
'Authorization': f'Apikey {api_key}',
'content-Type': 'application/json'
}
try:
response = requests.delete(url, headers=headers)
return response.status_code
except Exception as e:
print(f"Revoking access from OS DataHub: {e}")
return None
def revoke_1password_access(self):
api_key = 'need to input api key'
user_email = self.name

url=f"https://api.1.password.com/v1/users/{user_email}/revoke-access"
headers = {
'Authorization': f'ApiKey {api_key}',
'content-Type': 'application/json'
}
try:
response = requests.post(url, headers=headers)
return response.status_code
except Exception as e:
print(f"Revoking access from 1 Password: {e}")
return None
def revoke_pagerduty_access(self):
api_key = 'need to input api key'
user_email = self.name

url = f"https://api.1.pagerduty.com/users{user_email}/revoke-access"
headers ={
'Authorization': f'ApiKey {api_key}',
'content-Type': 'application/json'
}
try:
response =requests.post(url,headers=headers)
return response.statusd_code
except Exception as e:
print(f"Revoking access from PagerDuty: {e}")
return None
class TestLeaverprocess(unittest.TestCase):
def setup(self):
self.leaver_process = LeaverProcess()
Expand Down

0 comments on commit d095b8e

Please sign in to comment.