Skip to content

Commit fa7c2db

Browse files
Bhavana BellamgariBhavana Bellamgari
authored andcommitted
Updated template grant schema
1 parent 6b75af5 commit fa7c2db

File tree

3 files changed

+275
-168
lines changed

3 files changed

+275
-168
lines changed

examples/test_iam_policy_management_v1_examples.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,21 +1480,27 @@ def test_create_role_policy_template_example(self):
14801480
# begin-create_role_policy_template
14811481

14821482
policy_resource_model = {
1483-
'attributes': [{
1484-
'key': 'serviceName',
1485-
'operator': 'stringEquals',
1486-
'value': 'am-test-service',
1487-
}],
1483+
'attributes': [
1484+
{
1485+
'key': 'serviceName',
1486+
'operator': 'stringEquals',
1487+
'value': 'am-test-service',
1488+
}
1489+
],
14881490
}
14891491

1490-
control_model = TemplateControl(grant=TemplateGrant(
1491-
roles=[{
1492-
'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer',
1493-
}],
1494-
role_template_references=[{
1495-
'id': example_role_template_id, 'version': example_role_template_version
1496-
}]
1497-
))
1492+
control_model = TemplateControl(
1493+
grant=TemplateGrant(
1494+
roles=[
1495+
{
1496+
'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer',
1497+
}
1498+
],
1499+
role_template_references=[
1500+
{'id': example_role_template_id, 'version': example_role_template_version}
1501+
],
1502+
)
1503+
)
14981504

14991505
template_policy_model = {
15001506
'type': 'access',

ibm_platform_services/iam_policy_management_v1.py

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10882,11 +10882,11 @@ class RoleTemplate:
1088210882
def __init__(
1088310883
self,
1088410884
name: str,
10885-
description: str,
1088610885
account_id: str,
1088710886
version: str,
1088810887
state: str,
1088910888
*,
10889+
description: Optional[str] = None,
1089010890
committed: Optional[bool] = None,
1089110891
role: Optional['RoleTemplatePrototypeRole'] = None,
1089210892
id: Optional[str] = None,
@@ -10940,8 +10940,6 @@ def from_dict(cls, _dict: Dict) -> 'RoleTemplate':
1094010940
raise ValueError('Required property \'name\' not present in RoleTemplate JSON')
1094110941
if (description := _dict.get('description')) is not None:
1094210942
args['description'] = description
10943-
else:
10944-
raise ValueError('Required property \'description\' not present in RoleTemplate JSON')
1094510943
if (account_id := _dict.get('account_id')) is not None:
1094610944
args['account_id'] = account_id
1094710945
else:
@@ -11781,7 +11779,7 @@ def from_dict(cls, _dict: Dict) -> 'TemplateControl':
1178111779
"""Initialize a TemplateControl object from a json dictionary."""
1178211780
args = {}
1178311781
if (grant := _dict.get('grant')) is not None:
11784-
args['grant'] = TemplateGrant.from_dict(grant)
11782+
args['grant'] = grant
1178511783
else:
1178611784
raise ValueError('Required property \'grant\' not present in TemplateControl JSON')
1178711785
return cls(**args)
@@ -14075,6 +14073,146 @@ class StatusEnum(str, Enum):
1407514073
FAILED = 'failed'
1407614074

1407714075

14076+
class TemplateGrantRoleReferences(TemplateGrant):
14077+
"""
14078+
TemplateGrantRoleReferences.
14079+
14080+
:param List[RoleTemplateReferencesItem] role_template_references: A set of role
14081+
template reference IDs granted by the policy.
14082+
"""
14083+
14084+
def __init__(
14085+
self,
14086+
role_template_references: List['RoleTemplateReferencesItem'],
14087+
) -> None:
14088+
"""
14089+
Initialize a TemplateGrantRoleReferences object.
14090+
14091+
:param List[RoleTemplateReferencesItem] role_template_references: A set of
14092+
role template reference IDs granted by the policy.
14093+
"""
14094+
# pylint: disable=super-init-not-called
14095+
self.role_template_references = role_template_references
14096+
14097+
@classmethod
14098+
def from_dict(cls, _dict: Dict) -> 'TemplateGrantRoleReferences':
14099+
"""Initialize a TemplateGrantRoleReferences object from a json dictionary."""
14100+
args = {}
14101+
if (role_template_references := _dict.get('role_template_references')) is not None:
14102+
args['role_template_references'] = [
14103+
RoleTemplateReferencesItem.from_dict(v) for v in role_template_references
14104+
]
14105+
else:
14106+
raise ValueError(
14107+
'Required property \'role_template_references\' not present in TemplateGrantRoleReferences JSON'
14108+
)
14109+
return cls(**args)
14110+
14111+
@classmethod
14112+
def _from_dict(cls, _dict):
14113+
"""Initialize a TemplateGrantRoleReferences object from a json dictionary."""
14114+
return cls.from_dict(_dict)
14115+
14116+
def to_dict(self) -> Dict:
14117+
"""Return a json dictionary representing this model."""
14118+
_dict = {}
14119+
if hasattr(self, 'role_template_references') and self.role_template_references is not None:
14120+
role_template_references_list = []
14121+
for v in self.role_template_references:
14122+
if isinstance(v, dict):
14123+
role_template_references_list.append(v)
14124+
else:
14125+
role_template_references_list.append(v.to_dict())
14126+
_dict['role_template_references'] = role_template_references_list
14127+
return _dict
14128+
14129+
def _to_dict(self):
14130+
"""Return a json dictionary representing this model."""
14131+
return self.to_dict()
14132+
14133+
def __str__(self) -> str:
14134+
"""Return a `str` version of this TemplateGrantRoleReferences object."""
14135+
return json.dumps(self.to_dict(), indent=2)
14136+
14137+
def __eq__(self, other: 'TemplateGrantRoleReferences') -> bool:
14138+
"""Return `true` when self and other are equal, false otherwise."""
14139+
if not isinstance(other, self.__class__):
14140+
return False
14141+
return self.__dict__ == other.__dict__
14142+
14143+
def __ne__(self, other: 'TemplateGrantRoleReferences') -> bool:
14144+
"""Return `true` when self and other are not equal, false otherwise."""
14145+
return not self == other
14146+
14147+
14148+
class TemplateGrantRoles(TemplateGrant):
14149+
"""
14150+
TemplateGrantRoles.
14151+
14152+
:param List[Roles] roles: A set of role Cloud Resource Names (CRNs) granted by
14153+
the policy.
14154+
"""
14155+
14156+
def __init__(
14157+
self,
14158+
roles: List['Roles'],
14159+
) -> None:
14160+
"""
14161+
Initialize a TemplateGrantRoles object.
14162+
14163+
:param List[Roles] roles: A set of role Cloud Resource Names (CRNs) granted
14164+
by the policy.
14165+
"""
14166+
# pylint: disable=super-init-not-called
14167+
self.roles = roles
14168+
14169+
@classmethod
14170+
def from_dict(cls, _dict: Dict) -> 'TemplateGrantRoles':
14171+
"""Initialize a TemplateGrantRoles object from a json dictionary."""
14172+
args = {}
14173+
if (roles := _dict.get('roles')) is not None:
14174+
args['roles'] = [Roles.from_dict(v) for v in roles]
14175+
else:
14176+
raise ValueError('Required property \'roles\' not present in TemplateGrantRoles JSON')
14177+
return cls(**args)
14178+
14179+
@classmethod
14180+
def _from_dict(cls, _dict):
14181+
"""Initialize a TemplateGrantRoles object from a json dictionary."""
14182+
return cls.from_dict(_dict)
14183+
14184+
def to_dict(self) -> Dict:
14185+
"""Return a json dictionary representing this model."""
14186+
_dict = {}
14187+
if hasattr(self, 'roles') and self.roles is not None:
14188+
roles_list = []
14189+
for v in self.roles:
14190+
if isinstance(v, dict):
14191+
roles_list.append(v)
14192+
else:
14193+
roles_list.append(v.to_dict())
14194+
_dict['roles'] = roles_list
14195+
return _dict
14196+
14197+
def _to_dict(self):
14198+
"""Return a json dictionary representing this model."""
14199+
return self.to_dict()
14200+
14201+
def __str__(self) -> str:
14202+
"""Return a `str` version of this TemplateGrantRoles object."""
14203+
return json.dumps(self.to_dict(), indent=2)
14204+
14205+
def __eq__(self, other: 'TemplateGrantRoles') -> bool:
14206+
"""Return `true` when self and other are equal, false otherwise."""
14207+
if not isinstance(other, self.__class__):
14208+
return False
14209+
return self.__dict__ == other.__dict__
14210+
14211+
def __ne__(self, other: 'TemplateGrantRoles') -> bool:
14212+
"""Return `true` when self and other are not equal, false otherwise."""
14213+
return not self == other
14214+
14215+
1407814216
class V2PolicyRuleRuleAttribute(V2PolicyRule):
1407914217
"""
1408014218
Rule that specifies additional access that is granted (For example, time-based

0 commit comments

Comments
 (0)