Skip to content

Commit

Permalink
Merge pull request #1 from AktechLabs/add-user-role-json
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech authored Nov 26, 2023
2 parents c260b6c + 203b2ab commit fecda26
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
45 changes: 31 additions & 14 deletions cirun/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def _create_access_control_repo_resource_data(
resources,
action="add",
teams=None,
roles=None,
users=None,
users_from_json=None,
policy_args=None,
):
repository_resource_access = {
Expand All @@ -160,14 +163,16 @@ def _create_access_control_repo_resource_data(
"action": action,
"policy_args": policy_args
}
if teams:
repository_resource_access = {
**repository_resource_access,
"teams": teams
}
repository_resource_access = {
**repository_resource_access,
"teams": teams,
"users": users,
"roles": roles,
"users_from_json": users_from_json,
}
return repository_resource_access

def remove_repo_from_resources(self, org, repo, resources, teams=None, policy_args=None):
def remove_repo_from_resources(self, org, repo, resources):
"""
Removes the access to the resource for the repository.
Expand All @@ -179,22 +184,27 @@ def remove_repo_from_resources(self, org, repo, resources, teams=None, policy_ar
GitHub Repository
resources: List[str]
List of resources
teams: List[str]
List of teams
policy_args: Optional[Dict[str, Any]]
Policy arguments, this is a dictionary of key values, currently the only
supported argument is ``{"pull_request": True}`` or ``{"pull_request": False}``
Returns
-------
requests.Response
"""
repository_resource_access = self._create_access_control_repo_resource_data(
repo, resources, action="remove", teams=teams, policy_args=policy_args
repo, resources, action="remove",
)
return self.update_access_control(org, [repository_resource_access])

def add_repo_to_resources(self, org, repo, resources, teams=None, policy_args=None):
def add_repo_to_resources(
self,
org,
repo,
resources,
teams=None,
roles=None,
users=None,
users_from_json=None,
policy_args=None,
):
"""
Grants access to the resource for the repository
Expand All @@ -208,6 +218,12 @@ def add_repo_to_resources(self, org, repo, resources, teams=None, policy_args=No
List of resources
teams: List[str]
List of teams
roles: List[str]
List of roles
users: List[str]
List of users
users_from_json: List[str]
List of users from a json url
policy_args: Optional[Dict[str, Any]]
Policy arguments, this is a dictionary of key values, currently the only
supported argument is ``{"pull_request": True}`` or ``{"pull_request": False}``
Expand All @@ -217,7 +233,8 @@ def add_repo_to_resources(self, org, repo, resources, teams=None, policy_args=No
requests.Response
"""
repository_resource_access = self._create_access_control_repo_resource_data(
repo, resources, action="add", teams=teams, policy_args=policy_args
repo, resources, action="add", teams=teams, roles=roles,
users=users, users_from_json=users_from_json, policy_args=policy_args
)
return self.update_access_control(org, [repository_resource_access])

Expand Down
10 changes: 9 additions & 1 deletion cirun/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ def set_api_key():
def test_access_control_add_repo_to_resource_401(set_api_key):
cirun = Cirun()
with pytest.raises(requests.exceptions.HTTPError) as exc:
cirun.add_repo_to_resources("cirun", "cirun-py", resources=["cirun-runner-1"])
cirun.add_repo_to_resources(
"cirun", "cirun-py",
teams=["team1", "team2", "team3"],
roles=["role1", "role2", "role3"],
users=["user1", "user2", "user3"],
users_from_json="https://cirun.io/users.json",
resources=["cirun-runner-1"]

)
assert exc.value.response.status_code == 401
assert exc.value.response.json() == {'message': MSG_401}

Expand Down

0 comments on commit fecda26

Please sign in to comment.