Example #1
0
    def testOrganization_invalid(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--organization', 'abc'])
        with self.assertRaises(exceptions.InvalidArgumentException):
            parent.GetParent(args)
Example #2
0
    def testFolder_invalid(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--folder', 'folder123'])
        with self.assertRaises(exceptions.InvalidArgumentException):
            parent.GetParent(args)
Example #3
0
    def testProject_invalid(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--project', '123AAABBCC'])
        with self.assertRaises(exceptions.InvalidArgumentException):
            parent.GetParent(args)
Example #4
0
    def testDefaultToCoreProject(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        properties.VALUES.core.project.Set('my-project-123')

        args = parser.parse_args([])
        self.assertEqual(parent.GetParent(args), 'projects/my-project-123')
Example #5
0
    def testNoCoreProjectSet(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        properties.PersistProperty(properties.VALUES.core.project, None)

        args = parser.parse_args([])
        with self.assertRaises(properties.RequiredPropertyError):
            parent.GetParent(args)
Example #6
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)
        return settings.Get(name=('%s/accessApprovalSettings' % p))
Example #7
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)
    return requests.List(parent=p, filter=(
        args.state.upper() if args.state else None))
Example #8
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))
Example #9
0
    def testOrganization(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--organization', '123'])
        self.assertEqual(parent.GetParent(args), 'organizations/123')
Example #10
0
    def testFolder(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--folder', '123'])
        self.assertEqual(parent.GetParent(args), 'folders/123')
Example #11
0
    def testProjectId(self):
        parser = argparse.ArgumentParser()
        parent.Args(parser)

        args = parser.parse_args(['--project', 'my-project-abc123'])
        self.assertEqual(parent.GetParent(args), 'projects/my-project-abc123')