def Run(self, args):
    secret_ref = args.CONCEPTS.secret.Parse()
    server_filter = None
    if args.filter:
      rewriter = resource_expr_rewrite.Backend()
      display_info = args.GetDisplayInfo()
      defaults = resource_projection_spec.ProjectionSpec(
          symbols=display_info.transforms, aliases=display_info.aliases)
      _, server_filter = rewriter.Rewrite(args.filter, defaults=defaults)

    return secrets_api.Versions().ListWithPager(
        secret_ref=secret_ref, limit=args.limit, request_filter=server_filter)
Ejemplo n.º 2
0
  def Run(self, args):
    project_ref = args.CONCEPTS.project.Parse()
    if not project_ref:
      raise exceptions.RequiredArgumentException(
          'project',
          'Please set a project with "--project" flag or "gcloud config set project <project_id>".'
      )
    server_filter = None
    if args.filter:
      rewriter = resource_expr_rewrite.Backend()
      display_info = args.GetDisplayInfo()
      defaults = resource_projection_spec.ProjectionSpec(
          symbols=display_info.transforms, aliases=display_info.aliases)
      _, server_filter = rewriter.Rewrite(args.filter, defaults=defaults)

    return secrets_api.Secrets().ListWithPager(
        project_ref=project_ref, limit=args.limit, request_filter=server_filter)
    def testResourceFilterRewriteBackend(self):
        """Rewrite backend tests -- RE  & transform terms should rewrite to None."""
        def T(expected, expression, exception=None):
            self.Run(expected, expression, exception=exception, depth=2)

        self.SetBackend(resource_expr_rewrite.Backend())

        T((None, None), '')
        T((None, None), ' ')
        T((None, 'a:3'), 'a:3')
        T((None, 'compound.string:xyz'), 's:xyz')
        T((None, 'NOT a:3'), '-a:3')
        T((None, 'NOT a:3'), 'NOT a:3')
        T((None, 'x<3'), 'x<3')
        T((None, 'x<=3'), 'x<=3')
        T((None, 'x>=3'), 'x>=3')
        T((None, 'x>3'), 'x>3')
        T((None, 'x!=3'), 'x!=3')
        T((None, 'NOT x!=3'), '-x!=3')
        T((None, 'NOT x!=3'), 'NOT x!=3')
        T((None, 'compound.string=ing'), 's=ing')
        T((None, 'compound.string:S*ing'), 's:S*ing')
        T((None, 'compound.string:str*'), 's:str*')
        T(('s~[a-z]', None), 's~[a-z]')
        T(('s!~^s.*g$', None), 's!~^s.*g$')
        T((None, 'compound.string:STRING'), 's:"STRING"')

        T((None, 'a.b.c:c*g'), 'a.b.c:"c*g"')
        T((None, 'x:1 AND (a.b.c:2 OR floating:3)'), 'x:1 AND (y:2 OR z:3)')
        T((None, 'NOT x:1 AND (a.b.c:2 OR floating:3)'),
          'NOT x:1 AND ( y:2 OR z:3 )')
        T((None, '(x>0 OR a.b.c>0) AND floating>0'), '(x>0 OR y>0) AND z>0')
        T((None, '(x:1 OR a.b.c:2) AND (w:3 OR floating:4)'),
          '( x:1 OR y:2 ) AND ( w:3 OR z:4 )')
        T((None, '(x:1 OR a.b.c:2) AND (x:3 OR floating:4)'),
          '( x:1 OR y:2 ) AND ( x:3 OR z:4 )')

        T((None, 'x:("a b",q,"y z")'), 'x:("a b", q, "y z")')
        T((None, 'x:(a,b,q,y,z)'), 'x:(a, b, q, y, z)')

        T(('a.b.c.test_transform():1', None), 'a.b.c.test_transform():1')
        T(('a.b.c.test_transform():1 AND z:3', 'floating:3'),
          'a.b.c.test_transform():1 AND z:3')
        T(('a.b.c.unknown():1', None), 'a.b.c.unknown():1')
        T(('a.b.c.unknown():1 AND z:3', 'floating:3'),
          'a.b.c.unknown():1 AND z:3')