Exemplo n.º 1
0
    def RunWithArgs(self, name):
        """Creates a ServiceAccountKey and returns it.

    Args:
      name: The resource name of the service account in the following format:
        `projects/{project}/serviceAccounts/{account}`. Using `-` as a
        wildcard for the project will infer the project from the account. The
        `account` value can be the `email` address or the `unique_id` of the
        service account.

    Flags:
      createServiceAccountKeyRequest: A CreateServiceAccountKeyRequest
        resource to be passed as the request body.
    """
        client = GetClientFromFlags()
        global_params = GetGlobalParamsFromFlags()
        request = messages.IamProjectsServiceAccountsKeysCreateRequest(
            name=name.decode('utf8'), )
        if FLAGS['createServiceAccountKeyRequest'].present:
            request.createServiceAccountKeyRequest = apitools_base.JsonToMessage(
                messages.CreateServiceAccountKeyRequest,
                FLAGS.createServiceAccountKeyRequest)
        result = client.projects_serviceAccounts_keys.Create(
            request, global_params=global_params)
        print apitools_base_cli.FormatOutput(result)
Exemplo n.º 2
0
  def RunWithArgs(self, projectId, datasetId, tableId):
    """Updates information in an existing table. The update method replaces
    the entire table resource, whereas the patch method only replaces fields
    that are provided in the submitted table resource. This method supports
    patch semantics.

    Args:
      projectId: Project ID of the table to update
      datasetId: Dataset ID of the table to update
      tableId: Table ID of the table to update

    Flags:
      table: A Table resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryTablesPatchRequest(
        projectId=projectId.decode('utf8'),
        datasetId=datasetId.decode('utf8'),
        tableId=tableId.decode('utf8'),
        )
    if FLAGS['table'].present:
      request.table = apitools_base.JsonToMessage(messages.Table, FLAGS.table)
    result = client.tables.Patch(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 3
0
  def RunWithArgs(self, projectId, datasetId, tableId):
    """Streams data into BigQuery one record at a time without needing to run
    a load job. Requires the WRITER dataset role.

    Args:
      projectId: Project ID of the destination table.
      datasetId: Dataset ID of the destination table.
      tableId: Table ID of the destination table.

    Flags:
      tableDataInsertAllRequest: A TableDataInsertAllRequest resource to be
        passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryTabledataInsertAllRequest(
        projectId=projectId.decode('utf8'),
        datasetId=datasetId.decode('utf8'),
        tableId=tableId.decode('utf8'),
        )
    if FLAGS['tableDataInsertAllRequest'].present:
      request.tableDataInsertAllRequest = apitools_base.JsonToMessage(messages.TableDataInsertAllRequest, FLAGS.tableDataInsertAllRequest)
    result = client.tabledata.InsertAll(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 4
0
  def RunWithArgs(self, projectId):
    """Starts a new asynchronous job. Requires the Can View project role.

    Args:
      projectId: Project ID of the project that will be billed for the job

    Flags:
      job: A Job resource to be passed as the request body.
      upload_filename: Filename to use for upload.
      upload_mime_type: MIME type to use for the upload. Only needed if the
        extension on --upload_filename does not determine the correct (or any)
        MIME type.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryJobsInsertRequest(
        projectId=projectId.decode('utf8'),
        )
    if FLAGS['job'].present:
      request.job = apitools_base.JsonToMessage(messages.Job, FLAGS.job)
    upload = None
    if FLAGS.upload_filename:
      upload = apitools_base.Upload.FromFile(
          FLAGS.upload_filename, FLAGS.upload_mime_type,
          progress_callback=apitools_base.UploadProgressPrinter,
          finish_callback=apitools_base.UploadCompletePrinter)
    result = client.jobs.Insert(
        request, global_params=global_params, upload=upload)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 5
0
    def RunWithArgs(self, resource):
        """Tests the specified permissions against the IAM access control policy
    for the specified IAM resource.

    Args:
      resource: REQUIRED: The resource for which the policy detail is being
        requested. `resource` is usually specified as a path, such as
        `projects/*project*/zones/*zone*/disks/*disk*`.  The format for the
        path specified in this value is resource specific and is specified in
        the `testIamPermissions` documentation.

    Flags:
      testIamPermissionsRequest: A TestIamPermissionsRequest resource to be
        passed as the request body.
    """
        client = GetClientFromFlags()
        global_params = GetGlobalParamsFromFlags()
        request = messages.IamProjectsServiceAccountsTestIamPermissionsRequest(
            resource=resource.decode('utf8'), )
        if FLAGS['testIamPermissionsRequest'].present:
            request.testIamPermissionsRequest = apitools_base.JsonToMessage(
                messages.TestIamPermissionsRequest,
                FLAGS.testIamPermissionsRequest)
        result = client.projects_serviceAccounts.TestIamPermissions(
            request, global_params=global_params)
        print apitools_base_cli.FormatOutput(result)
Exemplo n.º 6
0
    def RunWithArgs(self, name):
        """Signs a JWT using a service account's system-managed private key.  If
    no `exp` (expiry) time is contained in the claims, we will provide an
    expiry of one hour in the future. If an expiry of more than one hour in
    the future is requested, the request will fail.

    Args:
      name: The resource name of the service account in the following format:
        `projects/{project}/serviceAccounts/{account}`. Using `-` as a
        wildcard for the project will infer the project from the account. The
        `account` value can be the `email` address or the `unique_id` of the
        service account.

    Flags:
      signJwtRequest: A SignJwtRequest resource to be passed as the request
        body.
    """
        client = GetClientFromFlags()
        global_params = GetGlobalParamsFromFlags()
        request = messages.IamProjectsServiceAccountsSignJwtRequest(
            name=name.decode('utf8'), )
        if FLAGS['signJwtRequest'].present:
            request.signJwtRequest = apitools_base.JsonToMessage(
                messages.SignJwtRequest, FLAGS.signJwtRequest)
        result = client.projects_serviceAccounts.SignJwt(
            request, global_params=global_params)
        print apitools_base_cli.FormatOutput(result)
Exemplo n.º 7
0
  def RunWithArgs(self, project):
    """Create a new ManagedZone.

    Args:
      project: Identifies the project addressed by this request.

    Flags:
      managedZone: A ManagedZone resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.DnsManagedZonesCreateRequest(
        project=project.decode('utf8'),
        )
    if FLAGS['managedZone'].present:
      request.managedZone = apitools_base.JsonToMessage(messages.ManagedZone, FLAGS.managedZone)
    result = client.managedZones.Create(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 8
0
  def RunWithArgs(self, projectId):
    """Creates a new empty dataset.

    Args:
      projectId: Project ID of the new dataset

    Flags:
      dataset: A Dataset resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryDatasetsInsertRequest(
        projectId=projectId.decode('utf8'),
        )
    if FLAGS['dataset'].present:
      request.dataset = apitools_base.JsonToMessage(messages.Dataset, FLAGS.dataset)
    result = client.datasets.Insert(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 9
0
  def RunWithArgs(self, projectId):
    """Runs a BigQuery SQL query synchronously and returns query results if
    the query completes within a specified timeout.

    Args:
      projectId: Project ID of the project billed for the query

    Flags:
      queryRequest: A QueryRequest resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryJobsQueryRequest(
        projectId=projectId.decode('utf8'),
        )
    if FLAGS['queryRequest'].present:
      request.queryRequest = apitools_base.JsonToMessage(messages.QueryRequest, FLAGS.queryRequest)
    result = client.jobs.Query(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 10
0
  def RunWithArgs(self, projectId, datasetId):
    """Creates a new, empty table in the dataset.

    Args:
      projectId: Project ID of the new table
      datasetId: Dataset ID of the new table

    Flags:
      table: A Table resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryTablesInsertRequest(
        projectId=projectId.decode('utf8'),
        datasetId=datasetId.decode('utf8'),
        )
    if FLAGS['table'].present:
      request.table = apitools_base.JsonToMessage(messages.Table, FLAGS.table)
    result = client.tables.Insert(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 11
0
  def RunWithArgs(self, project, managedZone):
    """Atomically update the ResourceRecordSet collection.

    Args:
      project: Identifies the project addressed by this request.
      managedZone: Identifies the managed zone addressed by this request. Can
        be the managed zone name or id.

    Flags:
      change: A Change resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.DnsChangesCreateRequest(
        project=project.decode('utf8'),
        managedZone=managedZone.decode('utf8'),
        )
    if FLAGS['change'].present:
      request.change = apitools_base.JsonToMessage(messages.Change, FLAGS.change)
    result = client.changes.Create(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 12
0
    def RunWithArgs(self, name):
        """Creates a ServiceAccount and returns it.

    Args:
      name: Required. The resource name of the project associated with the
        service accounts, such as `projects/my-project-123`.

    Flags:
      createServiceAccountRequest: A CreateServiceAccountRequest resource to
        be passed as the request body.
    """
        client = GetClientFromFlags()
        global_params = GetGlobalParamsFromFlags()
        request = messages.IamProjectsServiceAccountsCreateRequest(
            name=name.decode('utf8'), )
        if FLAGS['createServiceAccountRequest'].present:
            request.createServiceAccountRequest = apitools_base.JsonToMessage(
                messages.CreateServiceAccountRequest,
                FLAGS.createServiceAccountRequest)
        result = client.projects_serviceAccounts.Create(
            request, global_params=global_params)
        print apitools_base_cli.FormatOutput(result)
Exemplo n.º 13
0
  def RunWithArgs(self, projectId, datasetId):
    """Updates information in an existing dataset. The update method replaces
    the entire dataset resource, whereas the patch method only replaces fields
    that are provided in the submitted dataset resource.

    Args:
      projectId: Project ID of the dataset being updated
      datasetId: Dataset ID of the dataset being updated

    Flags:
      dataset: A Dataset resource to be passed as the request body.
    """
    client = GetClientFromFlags()
    global_params = GetGlobalParamsFromFlags()
    request = messages.BigqueryDatasetsUpdateRequest(
        projectId=projectId.decode('utf8'),
        datasetId=datasetId.decode('utf8'),
        )
    if FLAGS['dataset'].present:
      request.dataset = apitools_base.JsonToMessage(messages.Dataset, FLAGS.dataset)
    result = client.datasets.Update(
        request, global_params=global_params)
    print apitools_base_cli.FormatOutput(result)
Exemplo n.º 14
0
    def RunWithArgs(self, name):
        """Signs a blob using a service account's system-managed private key.

    Args:
      name: The resource name of the service account in the following format:
        `projects/{project}/serviceAccounts/{account}`. Using `-` as a
        wildcard for the project will infer the project from the account. The
        `account` value can be the `email` address or the `unique_id` of the
        service account.

    Flags:
      signBlobRequest: A SignBlobRequest resource to be passed as the request
        body.
    """
        client = GetClientFromFlags()
        global_params = GetGlobalParamsFromFlags()
        request = messages.IamProjectsServiceAccountsSignBlobRequest(
            name=name.decode('utf8'), )
        if FLAGS['signBlobRequest'].present:
            request.signBlobRequest = apitools_base.JsonToMessage(
                messages.SignBlobRequest, FLAGS.signBlobRequest)
        result = client.projects_serviceAccounts.SignBlob(
            request, global_params=global_params)
        print apitools_base_cli.FormatOutput(result)
Exemplo n.º 15
0
 def parse_map_task(self, serialized_map_task):
     return apitools_base.JsonToMessage(dataflow.MapTask,
                                        serialized_map_task)