Пример #1
0
def GetTableCopyResourceArgs():
    """Get Table resource args (source, destination) for copy command."""
    table_spec_data = yaml_data.ResourceYAMLData.FromPath('bq.table')
    arg_specs = [
        resource_args.GetResourcePresentationSpec(
            verb='to copy from',
            name='source',
            required=True,
            prefixes=True,
            attribute_overrides={'table': 'source'},
            positional=False,
            resource_data=table_spec_data.GetData()),
        resource_args.GetResourcePresentationSpec(
            verb='to copy to',
            name='destination',
            required=True,
            prefixes=True,
            attribute_overrides={'table': 'destination'},
            positional=False,
            resource_data=table_spec_data.GetData())
    ]
    fallthroughs = {
        '--source.dataset': ['--destination.dataset'],
        '--destination.dataset': ['--source.dataset']
    }
    return [concept_parsers.ConceptParser(arg_specs, fallthroughs)]
Пример #2
0
def AddTableRestoreResourceArg(parser):
    """Add Table resource args (source, destination) for restore command."""
    table_spec_data = yaml_data.ResourceYAMLData.FromPath('bigtable.table')
    backup_spec_data = yaml_data.ResourceYAMLData.FromPath('bigtable.backup')

    arg_specs = [
        resource_args.GetResourcePresentationSpec(
            verb='to copy from',
            name='source',
            required=True,
            prefixes=True,
            attribute_overrides={'table': 'source'},
            positional=False,
            resource_data=backup_spec_data.GetData()),
        resource_args.GetResourcePresentationSpec(
            verb='to copy to',
            name='destination',
            required=True,
            prefixes=True,
            attribute_overrides={'table': 'destination'},
            positional=False,
            resource_data=table_spec_data.GetData())
    ]
    fallthroughs = {
        '--source.instance': ['--destination.instance'],
        '--destination.instance': ['--source.instance']
    }
    concept_parsers.ConceptParser(arg_specs, fallthroughs).AddToParser(parser)
Пример #3
0
def AddOutputPathBigQueryArgs(parser):
    """Add BigQuery destination args to argument list."""
    bigquery_group = parser.add_group(
        mutex=False,
        required=False,
        help='The BigQuery destination for exporting assets.')
    resource = yaml_data.ResourceYAMLData.FromPath('bq.table')
    table_dic = resource.GetData()
    # Update the name 'dataset' in table_ref to 'bigquery-dataset'
    attributes = table_dic['attributes']
    for attr in attributes:
        if attr['attribute_name'] == 'dataset':
            attr['attribute_name'] = 'bigquery-dataset'
    arg_specs = [
        resource_args.GetResourcePresentationSpec(verb='export to',
                                                  name='bigquery-table',
                                                  required=True,
                                                  prefixes=False,
                                                  positional=False,
                                                  resource_data=table_dic)
    ]
    concept_parsers.ConceptParser(arg_specs).AddToParser(bigquery_group)
    base.Argument(
        '--output-bigquery-force',
        action='store_true',
        dest='force_',
        default=False,
        required=False,
        help=
        ('If the destination table already exists and this flag is specified, '
         'the table will be overwritten by the contents of assets snapshot. '
         'If the flag is not specified and the destination table already exists, '
         'the export call returns an error.')).AddToParser(bigquery_group)
Пример #4
0
 def testGetResourcePresentationSpecAllArgs(self):
   self.table_attribute.attribute_name = 'source'
   expected = presentation_specs.ResourcePresentationSpec(
       'table',
       concepts.ResourceSpec(
           'bigquery.tables',
           resource_name='table',
           datasetId=self.dataset_attribute,
           tableId=self.table_attribute,
           projectId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
           disable_auto_completers=False),
       'A New help text for table to create.',
       required=True,
       prefixes=False)
   result = resource_args.GetResourcePresentationSpec(
       'table',
       'to create',
       self.spec_data,
       required=True,
       prefixes=False,
       help_text='A New help text for {name} {verb}.',
       attribute_overrides={'table': 'source'},
       positional=True)
   self.assertEqual(expected.attribute_to_args_map,
                    result.attribute_to_args_map)
   self.assertEqual(expected.group_help,
                    result.group_help)
Пример #5
0
def AddOutputPathBigQueryArgs(parser):
    """Add BigQuery destination args to argument list."""
    bigquery_group = parser.add_group(
        mutex=False,
        required=False,
        help='The BigQuery destination for exporting assets.')
    resource = yaml_data.ResourceYAMLData.FromPath('bq.table')
    table_dic = resource.GetData()
    # Update the name 'dataset' in table_ref to 'bigquery-dataset'
    attributes = table_dic['attributes']
    for attr in attributes:
        if attr['attribute_name'] == 'dataset':
            attr['attribute_name'] = 'bigquery-dataset'
    arg_specs = [
        resource_args.GetResourcePresentationSpec(verb='export to',
                                                  name='bigquery-table',
                                                  required=True,
                                                  prefixes=False,
                                                  positional=False,
                                                  resource_data=table_dic)
    ]
    concept_parsers.ConceptParser(arg_specs).AddToParser(bigquery_group)
    base.Argument(
        '--output-bigquery-force',
        action='store_true',
        dest='force_',
        default=False,
        required=False,
        help=
        ('If the destination table already exists and this flag is specified, '
         'the table will be overwritten by the contents of assets snapshot. '
         'If the flag is not specified and the destination table already exists, '
         'the export call returns an error.')).AddToParser(bigquery_group)
    base.Argument(
        '--per-asset-type',
        action='store_true',
        dest='per_type_',
        default=False,
        required=False,
        help=(
            'If the flag is specified, the snapshot results will be written to '
            'one or more tables, each of which contains results of one '
            'asset type.')).AddToParser(bigquery_group)
    base.ChoiceArgument(
        '--partition-key',
        required=False,
        choices=['read-time', 'request-time'],
        help_str=(
            'If specified. the snapshot results will be written to partitioned '
            'table(s) with two additional timestamp columns, readTime and '
            'requestTime, one of which will be the partition key.'
        )).AddToParser(bigquery_group)
Пример #6
0
def AppendOrgArg():
  """Add Organization as positional resource."""
  org_spec_data = yaml_data.ResourceYAMLData.FromPath("scc.organization")
  arg_specs = [
      resource_args.GetResourcePresentationSpec(
          verb="to be used for the SCC command",
          name="organization",
          required=True,
          prefixes=False,
          positional=True,
          resource_data=org_spec_data.GetData()),
  ]
  return [concept_parsers.ConceptParser(arg_specs, [])]
Пример #7
0
def AppendAssetArg():
  """Add asset as positional resource."""
  asset_spec_data = yaml_data.ResourceYAMLData.FromPath("scc.asset")
  arg_specs = [
      resource_args.GetResourcePresentationSpec(
          verb="to be used for the SCC (Security Command Center) command",
          name="asset",
          required=True,
          prefixes=False,
          positional=True,
          resource_data=asset_spec_data.GetData()),
  ]
  return [concept_parsers.ConceptParser(arg_specs, [])]
Пример #8
0
  def testGetResourcePresentationSpec(self):
    expected = presentation_specs.ResourcePresentationSpec(
        '--table',
        concepts.ResourceSpec(
            'bigquery.tables',
            resource_name='table',
            datasetId=self.dataset_attribute,
            tableId=self.table_attribute,
            projectId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
            disable_auto_completers=False),
        'The table to create.',
        required=False,
        prefixes=True)

    result = resource_args.GetResourcePresentationSpec('table', 'to create',
                                                       self.spec_data)
    self.assertEqual(expected.attribute_to_args_map,
                     result.attribute_to_args_map)
    self.assertEqual(expected.group_help,
                     result.group_help)