def testAddIamPolicyBindingNewRole(self):
        original_policy = self.msgs.GoogleIamV1Policy(bindings=[],
                                                      etag=b'abcd')
        new_policy = self.msgs.GoogleIamV1Policy(bindings=[
            self.msgs.GoogleIamV1Binding(members=['user:[email protected]'],
                                         role='roles/owner')
        ],
                                                 etag=b'abcd')
        get_iam_policy = self.StartObjectPatch(self.models_client,
                                               'GetIamPolicy',
                                               return_value=original_policy,
                                               autospec=True)
        set_iam_policy = self.StartObjectPatch(self.models_client,
                                               'SetIamPolicy',
                                               return_value=new_policy,
                                               autospec=True)

        response = models_util.AddIamPolicyBinding(self.models_client,
                                                   'myModel',
                                                   'user:[email protected]',
                                                   'roles/owner')

        self.assertEqual(response, new_policy)
        get_iam_policy.assert_called_once_with(self.model_ref)
        set_iam_policy.assert_called_once_with(self.model_ref, new_policy,
                                               'bindings,etag')
 def Run(self, args):
     return models_util.AddIamPolicyBinding(models.ModelsClient(),
                                            args.model, args.member,
                                            args.role)
Example #3
0
def _Run(args):
    with endpoint_util.MlEndpointOverrides(region=args.region):
        return models_util.AddIamPolicyBinding(models.ModelsClient(),
                                               args.model, args.member,
                                               args.role)