def testUpdate_project_bothFields(self):
     name = 'projects/123/accessApprovalSettings'
     emails_list = ['*****@*****.**', '*****@*****.**']
     services = ['all']
     services_protos = [self.msgs.EnrolledService(cloudProduct='all')]
     req = self.msgs.AccessapprovalProjectsUpdateAccessApprovalSettingsRequest(
         name=name,
         accessApprovalSettings=self.msgs.AccessApprovalSettings(
             name=name,
             notificationEmails=emails_list,
             enrolledServices=services_protos),
         updateMask='enrolled_services,notification_emails')
     # this doesn't reflect a realistic response but we don't
     # really care what it looks like because the library just passes the
     # response unmodified and doesn't look at it at all.
     mocked_response = self.msgs.AccessApprovalSettings(name=name)
     self.client.projects.UpdateAccessApprovalSettings.Expect(
         request=req, response=mocked_response)
     self.assertEqual(
         mocked_response,
         settings.Update(
             name=name,
             enrolled_services=services,
             notification_emails=emails_list,
             update_mask='enrolled_services,notification_emails'))
Exemple #2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """
        p = parent.GetParent(args)

        if (args.notification_emails is None and args.enrolled_services is None
                and args.active_key_version is None):
            raise exceptions.MinimumArgumentException([
                '--notification_emails', '--enrolled_services',
                '--active_key_version'
            ], 'must specify at least one of these flags')

        update_mask = []
        emails_list = []
        if args.notification_emails is not None:
            update_mask.append('notification_emails')
            if args.notification_emails:
                emails_list = args.notification_emails.split(',')
                emails_list = [i.strip() for i in emails_list]

        services_list = []
        if args.enrolled_services is not None:
            update_mask.append('enrolled_services')
            if args.enrolled_services:
                services_list = args.enrolled_services.split(',')
                services_list = [i.strip() for i in services_list]

        if args.active_key_version is not None:
            update_mask.append('active_key_version')

        return settings.Update(name=('%s/accessApprovalSettings' % p),
                               notification_emails=emails_list,
                               enrolled_services=services_list,
                               active_key_version=args.active_key_version,
                               update_mask=','.join(update_mask))
 def testUpdate_org_emailsOnly(self):
     name = 'organizations/123/accessApprovalSettings'
     emails_list = ['*****@*****.**', '*****@*****.**']
     req = self.msgs.AccessapprovalOrganizationsUpdateAccessApprovalSettingsRequest(
         name=name,
         accessApprovalSettings=self.msgs.AccessApprovalSettings(
             name=name, notificationEmails=emails_list,
             enrolledServices=[]),
         updateMask='notification_emails')
     # this doesn't reflect a realistic response but we don't
     # really care what it looks like because the library just passes the
     # response unmodified and doesn't look at it at all.
     mocked_response = self.msgs.AccessApprovalSettings(name=name)
     self.client.organizations.UpdateAccessApprovalSettings.Expect(
         request=req, response=mocked_response)
     self.assertEqual(
         mocked_response,
         settings.Update(name=name,
                         enrolled_services=[],
                         notification_emails=emails_list,
                         update_mask='notification_emails'))