Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(project,usergroup): adds support for specifying roles #212

Merged
merged 2 commits into from
Sep 26, 2023
Merged
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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ graphlib-backport = ">=1.0.3"
jinja2 = ">=3.0.1"
munch = ">=2.4.0"
pyyaml = ">=5.4.1"
rapyuta-io = ">=1.11.1"
rapyuta-io = ">=1.12.0"
tabulate = ">=0.8.0"
pyrfc3339 = ">=1.1"
directory-tree = ">=0.0.3.1"
Expand Down
338 changes: 184 additions & 154 deletions Pipfile.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions riocli/apply/manifests/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ metadata:
organizationGUID: org-guid
spec:
users:
- emailID: "[email protected]"
- emailID: "[email protected]"
pallabpain marked this conversation as resolved.
Show resolved Hide resolved
role: "admin"
- emailID: "[email protected]"
role: "viewer"
userGroups:
- name: dev-group
- name: "dev-group"
role: "admin"
- name: "qa-group"
role: "viewer"
features:
vpn: true
tracing: false
2 changes: 2 additions & 0 deletions riocli/apply/manifests/usergroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ spec:
- emailID: [email protected]
projects:
- name: project01
role: viewer
- name: project02
role: admin
11 changes: 11 additions & 0 deletions riocli/jsonschema/schemas/project-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ definitions:
type: string
userGroupGUID:
type: string
role:
"$ref": "#/definitions/roleSpec"
required:
- name
- role
user:
type: object
properties:
Expand All @@ -92,8 +95,11 @@ definitions:
type: string
userGUID:
"$ref": "#/definitions/uuid"
role:
"$ref": "#/definitions/roleSpec"
required:
- emailID
- role
projectStatus:
type: object
properties:
Expand All @@ -103,3 +109,8 @@ definitions:
type: string
tracing:
type: string
roleSpec:
type: string
enum:
- admin
- viewer
5 changes: 5 additions & 0 deletions riocli/jsonschema/schemas/usergroup-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ definitions:
pattern: "^project-([a-z0-9]{20}|[a-z]{24})$"
name:
type: string
role:
type: string
enum:
- viewer
- admin
oneOf:
- required:
- guid
Expand Down
5 changes: 3 additions & 2 deletions riocli/usergroup/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def to_manifest(usergroup: UserGroup, org_guid: str) -> typing.Dict:
"""
Transform a usergroup resource to a rio apply manifest construct
"""
role_map = {i['projectGUID']: i['groupRole'] for i in (usergroup.role_in_projects or [])}
members = {m.email_id for m in usergroup.members}
admins = {a.email_id for a in usergroup.admins}
projects = [p.name for p in usergroup.projects]
projects = [{'name': p.name, 'role': role_map[p.guid]} for p in (usergroup.projects or [])]

return {
'apiVersion': 'api.rapyuta.io/v2',
Expand All @@ -68,6 +69,6 @@ def to_manifest(usergroup: UserGroup, org_guid: str) -> typing.Dict:
'description': usergroup.description,
'members': [{'emailID': m} for m in list(members - admins)],
'admins': [{'emailID': a} for a in list(admins)],
'projects': [{'name': p} for p in projects],
'projects': projects,
},
}
18 changes: 13 additions & 5 deletions riocli/usergroup/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def delete_object(self, client: Client, obj: typing.Any) -> typing.Any:
return client.delete_usergroup(self.metadata.organization, obj.guid)

def _modify_payload(self, group: typing.Dict) -> typing.Dict:
group['spec']['userGroupRoleInProjects'] = []
for entity in ('members', 'admins'):
for u in group['spec'].get(entity, []):
if USER_GUID in u:
Expand All @@ -80,10 +81,16 @@ def _modify_payload(self, group: typing.Dict) -> typing.Dict:
u.pop(USER_EMAIL)

for p in group['spec'].get('projects', []):
if 'guid' in p:
continue
p['guid'] = self.project_name_to_guid_map.get(p['name'])
p.pop('name')
if 'guid' not in p:
p['guid'] = self.project_name_to_guid_map.get(p['name'])
p.pop('name')

if 'role' in p:
group['spec']['userGroupRoleInProjects'].append({
'projectGUID': p['guid'],
'groupRole': p['role'],
})
p.pop('role')

return group

Expand All @@ -106,7 +113,8 @@ def _create_update_payload(old: typing.Any, new: typing.Dict) -> typing.Dict:
'members': {'add': [], 'remove': []},
'projects': {'add': [], 'remove': []},
'admins': {'add': [], 'remove': []}
}
},
'userGroupRoleInProjects': new['spec'].get('userGroupRoleInProjects', []),
}

entity_sets = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"python-dateutil>=2.8.2",
"pytz",
"pyyaml>=5.4.1",
"rapyuta-io>=1.11.1",
"rapyuta-io>=1.12.0",
"requests>=2.20.0",
"setuptools",
"six>=1.13.0",
Expand Down