Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions github_access/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get_org,
get_org_invite,
get_org_repo_list,
get_repo_blacklist,
get_repo,
get_user,
grant_access,
Expand Down Expand Up @@ -77,7 +78,14 @@ def approve(
error_message = constants.REPO_NOT_FOUND % label["repository"]
return_value = False
else:
if return_value and grant_access(
# Verify that the repository is not in the blacklist
blacklisted_repos = set(get_repo_blacklist())

if label["repository"] in blacklisted_repos:
logger.error(constants.REPO_BLACKLISTED, label["repository"])
error_message = constants.REPO_BLACKLISTED % label["repository"]
return_value = False
elif return_value and grant_access(
label["repository"], label["access_level"], user_name
):
logger.debug(
Expand Down Expand Up @@ -199,10 +207,20 @@ def fetch_access_request_form_path(self):
return "github_access/access_request_form.html"

def access_request_data(self, request, is_group=False):
repo_data = [repo for repo in get_org_repo_list()]
data = {"githubRepoList": repo_data}
repo_data = get_org_repo_list()
filtered_repo_data = self.__exclude_blacklisted_repos(repo_data)
data = {"githubRepoList": filtered_repo_data}
return data

def __exclude_blacklisted_repos(self, repo_data):
blacklisted_repos = set(get_repo_blacklist())
if not blacklisted_repos:
return repo_data

filtered_repo_data = [repo for repo in repo_data if repo not in blacklisted_repos]
logger.debug(f"Filtered out {len(repo_data) - len(filtered_repo_data)} blacklisted repositories")
return filtered_repo_data

def fetch_access_approve_email(self, request, data):
context_details = {
"approvers": {
Expand Down
3 changes: 2 additions & 1 deletion github_access/config.json.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"GITHUB_TOKEN": "test-token",
"GITHUB_BASE_URL": "https://api.github.com",
"GITHUB_ORG": "browserstack"
"GITHUB_ORG": "browserstack",
"GITHUB_REPO_BLACKLIST": []
}
1 change: 1 addition & 0 deletions github_access/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
INVITE_USER_SUCCESS = "Invited user %s to join github org. Access can be granted post inivation acceptance."
INVITE_USER_FAILED = "Failed to add user %s to github org"
REPO_NOT_FOUND = "Repository %s does not exist"
REPO_BLACKLISTED = "Repository %s is blacklisted. Access cannot be granted."
GRANT_ACCESS_FAILED = "Failed to grant access to user %s for repo %s"
REVOKE_REQUEST = "Revoke Request: %s for %s"
REVOKE_SUCCESS = "Successfully revoked access for user %s to %s repository."
Expand Down
5 changes: 5 additions & 0 deletions github_access/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ def get_org_repo_list():
return []


def get_repo_blacklist():
config = _get_github_config()
return config.get("GITHUB_REPO_BLACKLIST", [])


def revoke_access(username, repo=None):
return _revoke_github_user(username, repo)

Expand Down