I am working on a project to create an Org policy using python. The specific policy which I want to create is set the value of the constraint "constraints/iam.serviceAccountKeyExpiryHours" to "24h".
The documents which I am following for this specific task is:
The code I have written so far is as below:
from google.cloud import orgpolicy_v2
from google.cloud.orgpolicy_v2 import types
def build_policy():
rule = types.PolicySpec.PolicyRule.StringValues()
rule.allowed_values = ["24h"]
spec = types.PolicySpec.PolicyRule()
spec.values.append(rule)
policy = types.Policy(
name="projects/{project_id}/policies/iam.serviceAccountKeyExpiryHours",
spec = spec
)
return policy
def set_organization_policy():
# Create the orgpolicies client
client = orgpolicy_v2.OrgPolicyClient()
policy = build_policy()
request = orgpolicy_v2.UpdatePolicyRequest(
policy=policy
)
# Make the request
response = client.create_policy(request=request)
# Handle the response
print(response)
However, I am getting error: AttributeError: Unknown field for StringValues: append
Could you please help me with it ?
Thank you