[go: up one dir, main page]

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

Appending a role binding does not work as per the docs #12681

Open
aaron-tillekeratne opened this issue May 9, 2024 · 3 comments
Open

Appending a role binding does not work as per the docs #12681

aaron-tillekeratne opened this issue May 9, 2024 · 3 comments
Labels
type: docs Improvement to the documentation for an API. type: question Request for information or clarification. Not an issue.

Comments

@aaron-tillekeratne
Copy link

Summary

As per documented in https://cloud.google.com/iam/docs/write-policy-client-libraries, adding a new role binding is shown to be accomplished by the following

binding = {"role": "foo", "members": ["bar"]}
policy["bindings"].append(binding)

Expected behaviour

Successfully adding the binding

Observed behaviour


TypeError: Expected a message object, but got {'role': 'foo', 'members': ['bar']}.

Background info

python-version: 3.11.9

Pip freeze:

Arpeggio==2.0.2
asttokens==2.4.1
attrs==23.2.0
black==24.4.2
cachetools==5.3.3
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
cryptography==42.0.7
decorator==5.1.1
Deprecated==1.2.14
dill==0.3.8
executing==2.0.1
gitdb==4.0.11
GitPython==3.1.41
google-api-core==2.19.0
google-auth==2.29.0
google-cloud-core==2.4.1
google-cloud-firestore==2.15.0
google-cloud-resource-manager==1.12.3
googleapis-common-protos==1.63.0
grpc-google-iam-v1==0.13.0
grpcio==1.60.1
grpcio-status==1.60.1
idna==3.7
iniconfig==2.0.0
ipython==8.24.0
isort==5.13.2
jedi==0.19.1
Jinja2==3.1.3
MarkupSafe==2.1.5
matplotlib-inline==0.1.7
mypy-extensions==1.0.0
packaging==24.0
parso==0.8.4
parver==0.5
pathspec==0.12.1
pexpect==4.9.0
platformdirs==4.2.1
pluggy==1.5.0
prompt-toolkit==3.0.43
proto-plus==1.23.0
protobuf==4.25.3
ptyprocess==0.7.0
pulumi==3.114.0
pulumi_gcp==7.20.0
pure-eval==0.2.2
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
PyGithub==2.2.0
Pygments==2.18.0
PyJWT==2.8.0
PyNaCl==1.5.0
pytest==8.2.0
pytest-order==1.2.1
PyYAML==6.0.1
requests==2.31.0
rsa==4.9
semver==2.13.0
six==1.16.0
smmap==5.0.1
stack-data==0.6.3
toml==0.10.2
traitlets==5.14.3
typing_extensions==4.11.0
urllib3==2.2.1
wcwidth==0.2.13
wrapt==1.16.0

@ohmayr ohmayr added type: docs Improvement to the documentation for an API. type: question Request for information or clarification. Not an issue. labels May 10, 2024
@ohmayr
Copy link
Contributor
ohmayr commented May 10, 2024

@aaron-tillekeratne Thanks for reporting this. It's unclear how you've defined policy.

For the quickest resolution to this issue, kindly provide a complete code snippet to reproduce this issue. We can then identify if it's a problem with the sample docs or the api / client.

@aaron-tillekeratne
Copy link
Author
aaron-tillekeratne commented May 12, 2024

Reproducible code example.

from google.cloud import resourcemanager_v3 

PROJECT_ID = "YOUR_PROJECT_GOES_HERE"
ROLE = f"projects/{PROJECT_ID}/roles/YOUR_ROLE_ID_HERE"
MEMBER = "user:YOU@google.com"

client = resourcemanager_v3.ProjectsClient()

policy = client.get_iam_policy(request={"resource":f"projects/{PROJECT_ID}"})

policy.bindings.append({"role":ROLE, "members":[MEMBER]})
# TypeError: Expected a message object, but got {'role': 'projects/YOUR_PROJECT_GOES_HERE/roles/YOUR_ROLE_ID_HERE', 'members': ['user:YOU@google.com']}.

@aaron-tillekeratne
Copy link
Author

Any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs Improvement to the documentation for an API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants