def GetTensorboardTimeSeriesResourceSpec(
    resource_name='tensorboard_time_series'):
  return concepts.ResourceSpec(
      constants.TENSORBOARD_TIME_SERIES_COLLECTION,
      resource_name=resource_name,
      tensorboardsId=TensorboardAttributeConfig(),
      experimentsId=TensorboardExperimentAttributeConfig(),
      runsId=TensorboardRunAttributeConfig(),
      projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
      locationsId=RegionAttributeConfig(),
      disable_auto_completers=False)
Esempio n. 2
0
def AddTriggerResourceArg(parser, group_help_text, required=False):
    """Adds a resource argument for an Eventarc trigger."""
    resource_spec = concepts.ResourceSpec(
        'eventarc.projects.locations.triggers',
        resource_name='trigger',
        triggersId=TriggerAttributeConfig(),
        locationsId=LocationAttributeConfig(),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
    concept_parser = concept_parsers.ConceptParser.ForResource(
        'trigger', resource_spec, group_help_text, required=required)
    concept_parser.AddToParser(parser)
def GetRolloutResourceSpec():
    """Constructs and returns the resource specification for Rollout."""
    return concepts.ResourceSpec(
        'clouddeploy.projects.locations.deliveryPipelines.releases.rollouts',
        resource_name='rollout',
        deliveryPipelinesId=DeliveryPipelineAttributeConfig(),
        releasesId=ReleaseAttributeConfig(),
        rolloutsId=RolloutAttributeConfig(),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        locationsId=LocationAttributeConfig(),
        disable_auto_completers=False)
Esempio n. 4
0
 def _GenerateResourceSpec(self, full_collection_name, api_version,
                           detailed_params):
     attributes = _GenerateAttributes(detailed_params, self._attribute_data)
     return concepts.ResourceSpec(
         full_collection_name,
         resource_name=self.name,
         api_version=api_version,
         disable_auto_completers=self._disable_auto_completers,
         plural_name=self._plural_name,
         **{param: attribute
            for param, attribute in attributes})
Esempio n. 5
0
def CreateCertificateTemplateResourceSpec(display_name):
    # TODO(b/186143764): GA Autocompleters
    return concepts.ResourceSpec(
        'privateca.projects.locations.certificateTemplates',
        api_version='v1',
        # This will be formatted and used as {resource} in the help text.
        resource_name=display_name,
        certificateTemplatesId=CertificateTemplateAttributeConfig(),
        locationsId=LocationAttributeConfig(),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        disable_auto_completers=True)
Esempio n. 6
0
def CreateCertResourceSpec(display_name, id_fallthroughs=None):
    return concepts.ResourceSpec(
        'privateca.projects.locations.caPools.certificates',
        # This will be formatted and used as {resource} in the help text.
        api_version='v1',
        resource_name=display_name,
        certificatesId=CertAttributeConfig(fallthroughs=id_fallthroughs or []),
        caPoolsId=CaPoolAttributeConfig('issuer-pool'),
        locationsId=LocationAttributeConfig('issuer-location'),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        disable_auto_completers=False)
Esempio n. 7
0
def AddProjectResourceArg(parser):
    """Adds a resource argument for a project."""
    resource_spec = concepts.ResourceSpec(
        'eventarc.projects',
        resource_name='project',
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
    concept_parser = concept_parsers.ConceptParser.ForResource(
        '--project',
        resource_spec,
        'Project ID of the Google Cloud project for the {resource}.',
        required=True)
    concept_parser.AddToParser(parser)
Esempio n. 8
0
def _GetPlatformPolicyResourceSpec():
    return concepts.ResourceSpec(
        'binaryauthorization.projects.platforms.policies',
        resource_name='policy',
        api_version='v1',
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        platformsId=concepts.ResourceParameterAttributeConfig(
            name='platform',
            help_text='The platform that the {resource} belongs to. '
            'PLATFORM must be one of the following: cloudRun.'),
        policyId=concepts.ResourceParameterAttributeConfig(
            name='policy', help_text='The ID of the {resource}.'))
Esempio n. 9
0
def _GetNoteResourceSpec():
    return concepts.ResourceSpec(
        'containeranalysis.projects.notes',
        resource_name='note',
        projectsId=concepts.ResourceParameterAttributeConfig(
            name='project',
            help_text=('The Container Analysis project for the {resource}.'),
        ),
        notesId=concepts.ResourceParameterAttributeConfig(
            name='note',
            help_text='The Container Analysis Note ID for the {resource}.',
        ))
Esempio n. 10
0
def CreateCertificateAuthorityResourceSpec(
        display_name,
        certificate_authority_attribute='certificate_authority',
        location_attribute='location'):
    return concepts.ResourceSpec(
        'privateca.projects.locations.certificateAuthorities',
        # This will be formatted and used as {resource} in the help text.
        resource_name=display_name,
        certificateAuthoritiesId=CertificateAuthorityAttributeConfig(
            certificate_authority_attribute),
        locationsId=LocationAttributeConfig(location_attribute),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
Esempio n. 11
0
 def testResourceSpecParamName(self):
     """Tests using ResourceParameterAttributeConfig to configure resources.
 """
     resource_spec = concepts.ResourceSpec(
         'example.projects.shelves.books',
         resource_name='book',
         **self._MakeAttributeConfigs(with_completers=True))
     self.assertEqual('projectsId', resource_spec.ParamName('project'))
     self.assertEqual('shelvesId', resource_spec.ParamName('shelf'))
     self.assertEqual('booksId', resource_spec.ParamName('book'))
     with self.assertRaisesRegex(ValueError,
                                 re.escape('[book, project, shelf]')):
         resource_spec.ParamName('junk')
Esempio n. 12
0
def GetOrderAllocationResourceSpec():
    return concepts.ResourceSpec(
        'cloudcommerceconsumerprocurement.billingAccounts.orders.orderAllocations',
        resource_name='order-allocation',
        billingAccountsId=BillingAccountAttributeConfig(
            raw_help_text=
            'Cloud Billing Account for the Procurement Order Allocation. Billing account id is required if order allocation is not specified as full resource name.'
        ),
        ordersId=OrderAttributeConfig(
            raw_help_text=
            'Procurement Order for the Order Allocation. Order id is required if order allocation is not specified as full resource name.'
        ),
        orderAllocationsId=OrderAllocationAttributeConfig())
    def GetPipelineResourceSpec():
        """Constructs and returns the Resource specification for Pipeline."""
        def PipelineAttributeConfig():
            return concepts.ResourceParameterAttributeConfig(
                name=arg_name, help_text=help_text)

        return concepts.ResourceSpec(
            'datapipelines.projects.locations.pipelines',
            resource_name='pipeline',
            pipelinesId=PipelineAttributeConfig(),
            locationsId=RegionAttributeConfig(),
            projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
            disable_auto_completers=False)
Esempio n. 14
0
 def testNoParamsCollectionRaises(self):
     """Tests creating resource from the collection with no config overrides."""
     empty_collection = resource_util.CollectionInfo(
         'example', 'v1', '', '', 'books', '', {'': ''}, [])
     self.StartObjectPatch(resources.Registry,
                           'GetCollectionInfo',
                           return_value=empty_collection)
     with self.AssertRaisesExceptionMatches(
             concepts.ResourceConfigurationError,
             'Resource [book] has no parameters'):
         concepts.ResourceSpec('books',
                               resource_name='book',
                               api_version='v1')
def GetVpcResourceSpec():
    """Constructs and returns the Resource specification for VPC."""
    def VpcAttributeConfig():
        return concepts.ResourceParameterAttributeConfig(
            name='vpc',
            help_text=
            """fully qualified name of the VPC Datastream will peer to.""")

    return concepts.ResourceSpec(
        'compute.networks',
        resource_name='vpc',
        network=VpcAttributeConfig(),
        project=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
Esempio n. 16
0
def _AutoscalingPolicyResourceSpec(api_version):
  return concepts.ResourceSpec(
      'dataproc.projects.regions.autoscalingPolicies',
      api_version=api_version,
      resource_name='autoscaling policy',
      disable_auto_completers=True,
      projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
      regionsId=_RegionAttributeConfig(),
      autoscalingPoliciesId=concepts.ResourceParameterAttributeConfig(
          name='autoscaling_policy',
          help_text='The autoscaling policy id.',
      ),
  )
Esempio n. 17
0
def _GetFakeResource(collection_name,
                     name,
                     attribute_names=None,
                     with_completers=False,
                     auto_completers=False,
                     api_version='v1'):
    return concepts.ResourceSpec(collection_name,
                                 name,
                                 api_version=api_version,
                                 disable_auto_completers=not auto_completers,
                                 **MakeAttributeConfigs(
                                     attribute_names=attribute_names,
                                     with_completers=with_completers))
def AddsRegionResourceArg(parser):
  """Add region resource argument to parser."""
  region_resource_spec = concepts.ResourceSpec(
      'cloudbuild.projects.locations',
      resource_name='region',
      locationsId=resource_args.RegionAttributeConfig(),
      projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)

  concept_parsers.ConceptParser.ForResource(
      '--region',
      region_resource_spec,
      'Region for Cloud Build.',
      required=True).AddToParser(parser)
def GetBackupResourceSpec(resource_name='backup'):
    return concepts.ResourceSpec(
        'gkebackup.projects.locations.backupPlans.backups',
        resource_name=resource_name,
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        locationsId=LOCATION_RESOURCE_PARAMETER_ATTRIBUTE,
        backupPlansId=concepts.ResourceParameterAttributeConfig(
            name='backup-plan',
            fallthroughs=[
                deps.PropertyFallthrough(
                    properties.VALUES.gkebackup.Property('backup_plan')),
            ],
            help_text='Backup Plan name.'))
Esempio n. 20
0
    def GetNetworkResourceSpec():
        """Constructs and returns the Resource specification for Subnet."""
        def NetworkAttributeConfig():
            return concepts.ResourceParameterAttributeConfig(
                name='network',
                help_text=help_text,
                completer=compute_network_flags.NetworksCompleter)

        return concepts.ResourceSpec(
            'compute.networks',
            resource_name='network',
            network=NetworkAttributeConfig(),
            project=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
            disable_auto_completers=False)
def GetRestoreResourceSpec(resource_name='restore'):
    return concepts.ResourceSpec(
        'gkebackup.projects.locations.restorePlans.restores',
        api_version='v1',
        resource_name=resource_name,
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        locationsId=LOCATION_RESOURCE_PARAMETER_ATTRIBUTE,
        restorePlansId=concepts.ResourceParameterAttributeConfig(
            name='restore-plan',
            fallthroughs=[
                deps.PropertyFallthrough(
                    properties.VALUES.gkebackup.Property('restore_plan')),
            ],
            help_text='Restore Plan name.'))
Esempio n. 22
0
 def testCreateMultiTypeResourceFailsWithMismatchedAttribute(self):
     book_resource = util.GetBookResource()
     # Create a second resource with an attribute named "project" that doesn't
     # match the book resource's project attribute.
     project_resource = concepts.ResourceSpec(
         'example.projects',
         'project',
         projectsId=concepts.ResourceParameterAttributeConfig(
             name='project',
             help_text='The Cloud project of the {resource}.'))
     with self.assertRaisesRegexp(multitype.ConfigurationError,
                                  re.escape('[project]')):
         multitype.MultitypeResourceSpec('book', book_resource,
                                         project_resource)
Esempio n. 23
0
def GetApiConfigResourceSpec(resource_name='api-config',
                             include_project=False):
    if include_project:
        projects_id = ApiConfigProjectAttributeConfig()
    else:
        projects_id = concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG

    return concepts.ResourceSpec(
        'apigateway.projects.locations.apis.configs',
        resource_name=resource_name,
        configsId=ApiConfigAttributeConfig(),
        apisId=ApiAttributeConfig(),
        locationsId=LocationAttributeConfig(default='global'),
        projectsId=projects_id)
Esempio n. 24
0
def CreateCertificateAuthorityResourceSpec(
        display_name,
        certificate_authority_attribute='certificate_authority',
        location_attribute='location',
        ca_id_fallthroughs=None):
    return concepts.ResourceSpec(
        'privateca.projects.locations.certificateAuthorities',
        # This will be formatted and used as {resource} in the help text.
        resource_name=display_name,
        certificateAuthoritiesId=CertificateAuthorityAttributeConfig(
            certificate_authority_attribute, fallthroughs=ca_id_fallthroughs),
        locationsId=LocationAttributeConfig(location_attribute),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        disable_auto_completers=False)
Esempio n. 25
0
def CreateCaPoolResourceSpec(display_name,
                             location_attribute='location',
                             pool_id_fallthroughs=None,
                             location_fallthroughs=None):
    # TODO(b/186143764): GA Autocompleters
    return concepts.ResourceSpec(
        'privateca.projects.locations.caPools',
        api_version='v1',
        # This will be formatted and used as {resource} in the help text.
        resource_name=display_name,
        caPoolsId=CaPoolAttributeConfig(fallthroughs=pool_id_fallthroughs),
        locationsId=LocationAttributeConfig(
            location_attribute, fallthroughs=location_fallthroughs),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        disable_auto_completers=True)
Esempio n. 26
0
def _GetAuthorityResourceSpec():
    return concepts.ResourceSpec(
        'binaryauthorization.projects.attestationAuthorities',
        resource_name='authority',
        projectsId=concepts.ResourceParameterAttributeConfig(
            name='project',
            help_text='The project of the {resource}.',
            fallthroughs=[
                deps.PropertyFallthrough(properties.VALUES.core.project)
            ],
        ),
        attestationAuthoritiesId=concepts.ResourceParameterAttributeConfig(
            name='name',
            help_text='The ID of the {resource}.',
        ))
def AddEndpointResource(parser):
  name = "endpoint"
  resource_spec = concepts.ResourceSpec(
      "ids.projects.locations.endpoints",
      "endpoint",
      endpointId=concepts.ResourceParameterAttributeConfig(
          "endpoint", "The name of the {resource}"),
      locationId=concepts.ResourceParameterAttributeConfig(
          "zone", "The zone of the {resource}.", parameter_name="locationId"),
      projectId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
  presentation_spec = presentation_specs.ResourcePresentationSpec(
      name=name,
      concept_spec=resource_spec,
      required=True,
      group_help="endpoint.")
  return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
Esempio n. 28
0
def AddProjectsLocationsResourceArg(parser, api_version):
    """Add resrouce arg for projects/{}/locations/{}."""

    spec = concepts.ResourceSpec(
        'dataproc.projects.locations',
        api_version=api_version,
        resource_name='region',
        disable_auto_completers=True,
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
        locationsId=_RegionAttributeConfig())

    concept_parsers.ConceptParser.ForResource(
        '--region',
        spec,
        properties.VALUES.dataproc.region.help_text,
        required=True).AddToParser(parser)
Esempio n. 29
0
def AddServiceAccountResourceArg(parser, required=False):
    """Adds a resource argument for an IAM service account."""
    resource_spec = concepts.ResourceSpec(
        'iam.projects.serviceAccounts',
        resource_name='service account',
        api_version=_IAM_API_VERSION,
        serviceAccountsId=ServiceAccountAttributeConfig(),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
    concept_parser = concept_parsers.ConceptParser.ForResource(
        '--service-account',
        resource_spec,
        'The IAM service account associated with the trigger, specified with an '
        'email address or a uniqueId. Unless a full resource name is provided, '
        'the service account is assumed to be in the same project as the '
        'trigger.',
        required=required)
    concept_parser.AddToParser(parser)
Esempio n. 30
0
def AddTransportTopicResourceArg(parser, required=False):
    """Adds a resource argument for a customer-provided transport topic."""
    resource_spec = concepts.ResourceSpec(
        'pubsub.projects.topics',
        resource_name='Pub/Sub topic',
        topicsId=TransportTopicAttributeConfig(),
        projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
    concept_parser = concept_parsers.ConceptParser.ForResource(
        '--transport-topic',
        resource_spec,
        "The Cloud Pub/Sub topic to use for the trigger's transport "
        'intermediary. This feature is currently only available for triggers '
        "of event type ``google.cloud.pubsub.topic.v1.messagePublished''. "
        'The topic must be in the same project as the trigger. '
        'If not specified, a transport topic will be created.',
        required=required)
    concept_parser.AddToParser(parser)