openshift/openshift-restclient-python

Add user to a project?

mylespollie opened this issue · 5 comments

I'm working on a project that provisions some OpenShift resources after a form is populated by a user. First I create the project by doing the following:

project_to_create ='''
kind: Project
apiVersion: project.openshift.io/v1
metadata:
  	name: example-project
'''

project_data = yaml.load(project_to_create)
response = v1_projects.create(body=project_data)

Now I'm trying to add a user to that created project. This would be analogous to doing
oadm policy add-role-to-user admin <user_name> -n <project_name>

I'm struggling to find how to do this. Any ideas? Thanks.

yeah, you'll need to create a rolebinding resource, which is all oadm policy add-role-to-user does under the hood. Here's an example of a rolebinding: https://github.com/fabianvf/game-server-operator/blob/master/deploy/role_binding.yaml

Also just to note, you don't need to yaml.load a string if you don't want to, the yaml.load just turns the string into a python dictionary so you could do something like

project = {'kind': 'Project', 'apiVersion': project.openshift.io/v1', 'metadata': {'name': 'example'} ...}

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.