Пример #1
0
def GetAdminClient():
  """Shortcut to get the latest Bigtable Admin client."""
  return apis.GetClientInstance('bigtableadmin', 'v2')
Пример #2
0
def _GetClient(version):
    return apis.GetClientInstance('oslogin', version)
Пример #3
0
def OrgPoliciesClient():
  return apis.GetClientInstance('cloudresourcemanager',
                                ORG_POLICIES_API_VERSION)
Пример #4
0
def Client(api_version):
  return apis.GetClientInstance('redis', api_version)
Пример #5
0
def CreateMultiClusterIngressFeatureSpec(config_membership):
    client = core_apis.GetClientInstance('gkehub', 'v1alpha1')
    messages = client.MESSAGES_MODULE
    return messages.MultiClusterIngressFeatureSpec(
        configMembership=config_membership)
Пример #6
0
 def FromApiVersion(cls, version):
     return cls(apis.GetClientInstance('iamassist', version))
Пример #7
0
 def __init__(self, client=None, messages=None, version=None):
     self.client = client or apis.GetClientInstance(
         constants.AI_PLATFORM_API_NAME,
         constants.AI_PLATFORM_API_VERSION[version])
     self.messages = messages or self.client.MESSAGES_MODULE
Пример #8
0
def GetGenomicsClient(version='v1'):
    return core_apis.GetClientInstance('genomics', version)
Пример #9
0
def GetClientInstance(release_track=base.ReleaseTrack.GA):
    api_version = VERSION_MAP.get(release_track)
    return apis.GetClientInstance('edgecontainer', api_version)
Пример #10
0
def Client(api_version):
    """Creates a managedidentities client."""
    return apis.GetClientInstance('managedidentities', api_version)
Пример #11
0
def GetClientV1():
    """Returns the client for the v1 logging API."""
    return core_apis.GetClientInstance('logging', 'v1beta3')
Пример #12
0
def GetClientInstance():
    return apis.GetClientInstance(DATAFLOW_API_NAME, DATAFLOW_API_VERSION)
Пример #13
0
def GetServerlessClientInstance():
    return apis.GetClientInstance(SERVERLESS_API_NAME, SERVERLESS_API_VERSION)
def FoldersClient():
    return apis.GetClientInstance('cloudresourcemanager', FOLDERS_API_VERSION)
Пример #15
0
 def FromApiVersion(cls, version):
     return cls(version, apis.GetClientInstance('dns', version))
Пример #16
0
    def Run(self, args):
        # We explicitly want to allow --networks='' as a valid option and we need
        # to differentiate between that option and not passing --networks at all.
        if args.visibility == 'public' and args.IsSpecified('networks'):
            raise exceptions.InvalidArgumentException(
                '--networks',
                'If --visibility is set to public (default), setting networks is '
                'not allowed.')
        if args.visibility == 'private' and args.networks is None:
            raise exceptions.RequiredArgumentException('--networks', ("""\
           If --visibility is set to private, a list of networks must be
           provided.'
         NOTE: You can provide an empty value ("") for private zones that
          have NO network binding.
          """))

        dns = apis.GetClientInstance('dns', 'v1beta2')
        messages = apis.GetMessagesModule('dns', 'v1beta2')
        registry = util.GetRegistry('v1beta2')

        zone_ref = registry.Parse(
            args.dns_zone,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='dns.managedZones')

        visibility = messages.ManagedZone.VisibilityValueValuesEnum(
            args.visibility)
        visibility_config = None
        if visibility == messages.ManagedZone.VisibilityValueValuesEnum.private:
            # Handle explicitly empty networks case (--networks='')
            networks = args.networks if args.networks != [''] else []
            network_urls = [
                registry.Parse(n,
                               collection='compute.networks',
                               params={
                                   'project': zone_ref.project
                               }).SelfLink() for n in networks
            ]
            network_configs = [
                messages.ManagedZonePrivateVisibilityConfigNetwork(
                    networkUrl=nurl) for nurl in network_urls
            ]
            visibility_config = messages.ManagedZonePrivateVisibilityConfig(
                networks=network_configs)

        dnssec_config = _MakeDnssecConfig(args, messages)
        labels = labels_util.ParseCreateArgs(args,
                                             messages.ManagedZone.LabelsValue)
        zone = messages.ManagedZone(name=zone_ref.managedZone,
                                    dnsName=util.AppendTrailingDot(
                                        args.dns_name),
                                    description=args.description,
                                    dnssecConfig=dnssec_config,
                                    labels=labels,
                                    visibility=visibility,
                                    privateVisibilityConfig=visibility_config)

        result = dns.managedZones.Create(
            messages.DnsManagedZonesCreateRequest(managedZone=zone,
                                                  project=zone_ref.project))
        log.CreatedResource(zone_ref)
        return [result]
Пример #17
0
def _MembershipClient():
    return core_apis.GetClientInstance('gkehub', 'v1beta1')
Пример #18
0
def GetClientInstance(version='v1beta1', no_http=False):
    return apis.GetClientInstance('ml', version, no_http=no_http)
Пример #19
0
def PrepareEnvironment(args):
  """Ensures that the user's environment is ready to accept SSH connections."""

  # Load Cloud Shell API
  client = apis.GetClientInstance('cloudshell', 'v1alpha1')
  messages = apis.GetMessagesModule('cloudshell', 'v1alpha1')
  operations_client = apis.GetClientInstance('cloudshell', 'v1')

  # Ensure we have a key pair on the local machine
  ssh_env = ssh.Environment.Current()
  ssh_env.RequireSSH()
  keys = ssh.Keys.FromFilename(filename=args.ssh_key_file)
  keys.EnsureKeysExist(overwrite=args.force_key_file_overwrite)

  # Look up the Cloud Shell environment
  environment = client.users_environments.Get(
      messages.CloudshellUsersEnvironmentsGetRequest(
          name=DEFAULT_ENVIRONMENT_NAME))

  # If the environment doesn't have the public key, push it
  key_parts = keys.GetPublicKey().ToEntry().split(' ')
  key = messages.PublicKey(
      format=messages.PublicKey.FormatValueValuesEnum(key_parts[0].replace(
          '-', '_').upper()),
      key=base64.b64decode(key_parts[1]),
  )
  has_key = False
  for candidate in environment.publicKeys:
    if key.format == candidate.format and key.key == candidate.key:
      has_key = True
      break
  if not has_key:
    log.Print('Pushing your public key to Cloud Shell...')
    client.users_environments_publicKeys.Create(
        messages.CloudshellUsersEnvironmentsPublicKeysCreateRequest(
            parent=DEFAULT_ENVIRONMENT_NAME,
            createPublicKeyRequest=messages.CreatePublicKeyRequest(key=key),
        ))

  # If the environment isn't running, start it
  if environment.state != messages.Environment.StateValueValuesEnum.RUNNING:
    log.Print('Starting your Cloud Shell machine...')
    start_operation = client.users_environments.Start(
        messages.CloudshellUsersEnvironmentsStartRequest(
            name=DEFAULT_ENVIRONMENT_NAME))

    environment = waiter.WaitFor(
        StartEnvironmentPoller(client.users_environments,
                               operations_client.operations),
        start_operation,
        'Waiting for your Cloud Shell machine to start',
        sleep_ms=500,
        max_wait_ms=None)

  return ConnectionInfo(
      ssh_env=ssh_env,
      user=environment.sshUsername,
      host=environment.sshHost,
      port=environment.sshPort,
      key=keys.key_file,
  )
Пример #20
0
def Client(api_version):
    return apis.GetClientInstance('artifactregistry', api_version)
Пример #21
0
def GetClientInstance():
    return apis.GetClientInstance(API_NAME, API_VERSION)
Пример #22
0
 def OrganizationsClient(cls):
     client = apis.GetClientInstance(cls.ORGS_API, cls.ORGS_API_VERSION)
     return client.organizations
Пример #23
0
def GetClientInstance():
  return apis.GetClientInstance(_DATAPOL_API_NAME, _DATAPOL_API_VERSION)
Пример #24
0
    def _ConfigureCleanPreviewSchedulerJob(self, repo_owner, repo_name,
                                           pull_request_pattern,
                                           clean_preview_trigger_id):

        # Generate deterministic scheduler job name (id)
        job_id = self._FixSchedulerName(
            self._GenerateResourceName(
                function_code='cp',  # Clean Preview
                repo_type='github',  # Only supports github for now.
                full_repo_name=repo_owner + '-' + repo_name,
                branch_pattern=pull_request_pattern))

        project = properties.VALUES.core.project.Get(required=True)
        name = 'projects/{}/locations/{}/jobs/{}'.format(
            project, _CLEAN_PREVIEW_SCHEDULER_LOCATION, job_id)

        # AppEngine service account has Editor permission by default.
        messages = apis.GetMessagesModule('cloudscheduler', 'v1')
        service_account_email = project + '@appspot.gserviceaccount.com'
        job = messages.Job(
            name=name,
            description='Every day, run trigger to clean expired preview '
            'deployments for PRs against "{}" in {}/{}'.format(
                pull_request_pattern, repo_owner, repo_name),
            schedule=_CLEAN_PREVIEW_SCHEDULE,
            timeZone='UTC',
            httpTarget=messages.HttpTarget(
                uri=
                'https://cloudbuild.googleapis.com/v1/projects/{}/triggers/{}:run'
                .format(project, clean_preview_trigger_id),
                httpMethod=messages.HttpTarget.HttpMethodValueValuesEnum.POST,
                body=bytes(
                    # We don't actually use the branchName value but it has to be
                    # set to an existing branch, so set it to main.
                    '{{"projectId":"{}","repoName":"{}","branchName":"main"}}'.
                    format(project, repo_name).encode('utf-8')),
                oauthToken=messages.OAuthToken(
                    serviceAccountEmail=service_account_email)))

        client = apis.GetClientInstance('cloudscheduler', 'v1')

        log.status.Print(
            'Upserting Cloud Scheduler to run Cloud Build trigger to '
            'clean expired preview deployments of your application.')

        existing = None
        try:
            existing = client.projects_locations_jobs.Get(
                messages.CloudschedulerProjectsLocationsJobsGetRequest(
                    name=name))

            upserted_job = client.projects_locations_jobs.Patch(
                messages.CloudschedulerProjectsLocationsJobsPatchRequest(
                    name=name, job=job))
            log.debug('updated existing CloudScheduler job: ' +
                      six.text_type(upserted_job))

        except HttpNotFoundError:
            upserted_job = client.projects_locations_jobs.Create(
                messages.CloudschedulerProjectsLocationsJobsCreateRequest(
                    parent='projects/{}/locations/{}'.format(
                        project, _CLEAN_PREVIEW_SCHEDULER_LOCATION),
                    job=job))
            log.debug('created CloudScheduler job: ' +
                      six.text_type(upserted_job))

        job_id = upserted_job.name.split('/')[-1]
        job_ref = resources.REGISTRY.Parse(
            None,
            collection='cloudscheduler.projects.locations.jobs',
            api_version='v1',
            params={
                'projectsId': project,
                'locationsId': _CLEAN_PREVIEW_SCHEDULER_LOCATION,
                'jobsId': job_id,
            })

        if existing:
            log.UpdatedResource(job_ref)
        else:
            log.CreatedResource(job_ref)

        return upserted_job
Пример #25
0
def GetClientInstance(no_http=False):
    return apis.GetClientInstance('pubsub', 'v1', no_http=no_http)
Пример #26
0
 def __init__(self):
   client = apis.GetClientInstance(_API_NAME, _API_VERSION)
   self.messages = client.MESSAGES_MODULE
   self._service = client.projects_locations
Пример #27
0
def OperationsClient():
    return apis.GetClientInstance('cloudresourcemanager',
                                  OPERATIONS_API_VERSION)
Пример #28
0
def GetClient():
    """Returns the Cloud Datastore client for the appropriate release track."""
    return apis.GetClientInstance('datastore', _DATASTORE_API_VERSION)
def GetClient():
  """Returns the client for the logging API."""
  return core_apis.GetClientInstance('logging', 'v2')
def GetClient(version=None):
    """Get the default client."""
    return apis.GetClientInstance(
        'secretmanager', version or apis.ResolveVersion('secretmanager'))