使用 Autoclass

概览

本页面介绍了如何启用、停用和查看在 Cloud Storage 存储桶上设置的 Autoclass 功能的状态。

所需的角色

如需获得在存储桶上设置和管理 Autoclass 所需的权限,请让您的管理员为您授予存储桶的 Storage Admin (roles/storage.admin) IAM 角色。此预定义角色可提供在存储桶上设置和管理 Autoclass 所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

  • storage.buckets.get
  • storage.buckets.list
    • 只有在使用 Google Cloud 控制台执行本页面上的任务时,才需要此权限。
  • storage.buckets.update

您还可以通过自定义角色获得这些权限。

如需了解如何授予存储桶的角色,请参阅将 IAM 与存储桶搭配使用

为存储桶设置 Autoclass

如需为存储桶设置 Autoclass,请按照以下说明操作:

控制台

  1. 在 Google Cloud 控制台中,进入 Cloud Storage 存储桶页面。

    进入“存储桶”

  2. 在存储桶列表中,点击所需存储桶的名称。

  3. 存储桶详情页面中,点击配置标签页。

  4. 点击默认存储类别修改图标 ()。

  5. 在重叠式窗口中,选择 Autoclass 以启用 Autoclass。如需停用 Autoclass,请选择设置默认类别,然后为存储桶选择默认存储类别。

  6. 点击确认

  7. 如需切换启用了 Autoclass 的存储桶的终端存储类别,请点击包含的类对应的修改图标 (),然后点击在出现的叠加窗口中,确认

命令行

使用带有相应标志的 gcloud storage buckets update 命令:

gcloud storage buckets update gs://BUCKET_NAME FLAG

其中:

  • BUCKET_NAME 是相关存储桶的名称,例如 my-bucket

  • FLAG 是以下值之一:

    • --enable-autoclass 用于启用 Autoclass。
    • --no-enable-autoclass 用于停用 Autoclass。
    • --autoclass-terminal-storage-class=CLASS 用于为 Autoclass 设置终端存储类别。CLASS 可以是 NEARLINEARCHIVE

如果成功,响应类似于以下示例:

Updating gs://my-bucket/...
  Completed 1  

客户端库

C++

如需了解详情,请参阅 Cloud Storage C++ API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

namespace gcs = ::google::cloud::storage;
[](gcs::Client client, std::string const& bucket_name, bool enabled) {
  auto metadata = client.PatchBucket(
      bucket_name, gcs::BucketMetadataPatchBuilder().SetAutoclass(
                       gcs::BucketAutoclass{enabled}));
  if (!metadata) throw google::cloud::Status(std::move(metadata).status());

  std::cout << "The autoclass configuration for bucket " << bucket_name
            << " was successfully updated.";
  if (!metadata->has_autoclass()) {
    std::cout << " The bucket no longer has an autoclass configuration.\n";
    return;
  }
  std::cout << " The new configuration is " << metadata->autoclass() << "\n";
}

C#

如需了解详情,请参阅 Cloud Storage C# API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


using Google.Cloud.Storage.V1;
using Google.Apis.Storage.v1.Data;
using static Google.Apis.Storage.v1.Data.Bucket;
using System;

public class SetAutoclassSample
{
    public Bucket SetAutoclass(string bucketName)
    {
        var storage = StorageClient.Create();
        var bucket = storage.GetBucket(bucketName);
        bucket.Autoclass = new AutoclassData { Enabled = true, TerminalStorageClass = "ARCHIVE" };
        storage.PatchBucket(bucket);
        Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");
        Console.WriteLine($"Autoclass terminal storage class is {bucket.Autoclass.TerminalStorageClass}.");
        return bucket;
    }
}

Go

如需了解详情,请参阅 Cloud Storage Go API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

import (
	"context"
	"fmt"
	"io"
	"time"

	"cloud.google.com/go/storage"
)

// setAutoclass sets the Autoclass configuration for a bucket.
func setAutoclass(w io.Writer, bucketName string) error {
	// bucketName := "bucket-name"

	// To update the configuration for Autoclass.TerminalStorageClass,
	// Autoclass.Enabled must also be set to true.
	// To disable autoclass on the bucket, set to an empty &Autoclass{}.
	enabled := true
	terminalStorageClass := "ARCHIVE"
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
	defer cancel()

	bucket := client.Bucket(bucketName)
	bucketAttrsToUpdate := storage.BucketAttrsToUpdate{
		Autoclass: &storage.Autoclass{
			Enabled:              enabled,
			TerminalStorageClass: terminalStorageClass,
		},
	}
	if _, err := bucket.Update(ctx, bucketAttrsToUpdate); err != nil {
		return fmt.Errorf("Bucket(%q).Update: %w", bucketName, err)
	}
	fmt.Fprintf(w, "Autoclass enabled was set to %v on bucket %q \n", bucketAttrsToUpdate.Autoclass.Enabled, bucketName)
	fmt.Fprintf(w, "Autoclass terminal storage class was last updated to %v at %v", bucketAttrsToUpdate.Autoclass.TerminalStorageClass, bucketAttrsToUpdate.Autoclass.TerminalStorageClassUpdateTime)
	return nil
}

Java

如需了解详情,请参阅 Cloud Storage Java API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo.Autoclass;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BucketTargetOption;
import com.google.cloud.storage.StorageClass;
import com.google.cloud.storage.StorageOptions;

public class SetBucketAutoclass {
  public static void setBucketAutoclass(
      String projectId, String bucketName, StorageClass storageClass) throws Exception {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // The storage class that objects in an Autoclass bucket eventually transition to if not read
    // for a certain length of time
    // StorageClass storageClass = StorageClass.ARCHIVE;

    // Configure the Autoclass setting for a bucket.

    // Note:  terminal_storage_class field is optional and defaults to NEARLINE if not otherwise
    // specified. Valid terminal_storage_class values are NEARLINE and ARCHIVE.
    boolean enabled = true;

    try (Storage storage =
        StorageOptions.newBuilder().setProjectId(projectId).build().getService()) {
      Bucket bucket = storage.get(bucketName);

      Bucket toUpdate =
          bucket
              .toBuilder()
              .setAutoclass(
                  Autoclass.newBuilder()
                      .setEnabled(enabled)
                      .setTerminalStorageClass(storageClass)
                      .build())
              .build();

      Bucket updated = storage.update(toUpdate, BucketTargetOption.metagenerationMatch());

      System.out.println(
          "Autoclass for bucket "
              + bucketName
              + " was "
              + (updated.getAutoclass().getEnabled() ? "enabled." : "disabled."));
      System.out.println(
          "Autoclass terminal storage class is "
              + updated.getAutoclass().getTerminalStorageClass().toString());
    }
  }
}

Node.js

如需了解详情,请参阅 Cloud Storage Node.js API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The terminal storage class to be set on your GCS bucket. Valid values are NEARLINE and ARCHIVE.
// const terminalStorageClass = 'NEARLINE';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function setAutoclass() {
  // Configure the Autoclass setting for a bucket.
  // terminalStorageClass field is optional and defaults to NEARLINE if not otherwise specified.
  // Valid terminalStorageClass values are NEARLINE and ARCHIVE.
  const [metadata] = await storage.bucket(bucketName).setMetadata({
    autoclass: {
      enabled: toggle,
      terminalStorageClass,
    },
  });

  console.log(
    `Autoclass terminal storage class is ${metadata.autoclass.terminalStorageClass}.`
  );
}

setAutoclass().catch(console.error);

PHP

如需了解详情,请参阅 Cloud Storage PHP API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

use Google\Cloud\Storage\StorageClient;

/**
 * Updates an existing bucket with provided autoclass config.
 *
 * @param string $bucketName The name of your Cloud Storage bucket (e.g. 'my-bucket').
 * @param bool $autoclassStatus If true, enables Autoclass. Disables otherwise.
 * @param string $terminalStorageClass This field is optional and defaults to `NEARLINE`.
 *        Valid values are `NEARLINE` and `ARCHIVE`.
 */
function set_bucket_autoclass(
    string $bucketName,
    bool $autoclassStatus,
    string $terminalStorageClass
): void {
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);

    $bucket->update([
        'autoclass' => [
            'enabled' => $autoclassStatus,
            'terminalStorageClass' => $terminalStorageClass
        ],
    ]);

    $info = $bucket->info();
    printf(
        'Updated bucket %s with autoclass set to %s.' . PHP_EOL,
        $info['name'],
        $autoclassStatus ? 'true' : 'false'
    );
    printf(
        'Autoclass terminal storage class is %s.' . PHP_EOL,
        $info['autoclass']['terminalStorageClass']
    );
}

Python

如需了解详情,请参阅 Cloud Storage Python API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from google.cloud import storage


def set_autoclass(bucket_name):
    """Configure the Autoclass setting for a bucket.

    terminal_storage_class field is optional and defaults to NEARLINE if not otherwise specified.
    Valid terminal_storage_class values are NEARLINE and ARCHIVE.
    """
    # The ID of your GCS bucket
    # bucket_name = "my-bucket"
    # Enable Autoclass for a bucket. Set enabled to false to disable Autoclass.
    # Set Autoclass.TerminalStorageClass, valid values are NEARLINE and ARCHIVE.
    enabled = True
    terminal_storage_class = "ARCHIVE"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

    bucket.autoclass_enabled = enabled
    bucket.autoclass_terminal_storage_class = terminal_storage_class
    bucket.patch()
    print(f"Autoclass enabled is set to {bucket.autoclass_enabled} for {bucket.name} at {bucket.autoclass_toggle_time}.")
    print(f"Autoclass terminal storage class is {bucket.autoclass_terminal_storage_class}.")

    return bucket

Ruby

如需了解详情,请参阅 Cloud Storage Ruby API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

require "google/cloud/storage"

##
# This is a snippet for showcasing how to set the autoclass
# configuration of a bucket.
#
# @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")
# @param toggle [Boolean] if true, enables Autoclass; if false, disables Autoclass
#
def set_autoclass bucket_name:, toggle:, terminal_storage_class: nil
  # Initialize client
  storage = Google::Cloud::Storage.new

  # Fetch the GCS bucket
  bucket = storage.bucket bucket_name

  # Update the autoclass configuration
  bucket.update_autoclass({ enabled: toggle, terminal_storage_class: terminal_storage_class })
  terminal_class_update_time = bucket.autoclass_terminal_storage_class_update_time

  # Get autoclass config of the bucket
  puts "Bucket #{bucket.name} has autoclass config set to #{bucket.autoclass_enabled}."
  puts "Bucket #{bucket.name} has autoclass toggle time set to #{bucket.autoclass_toggle_time}."
  puts "Bucket #{bucket.name} has autoclass terminal storage class set to #{bucket.autoclass_terminal_storage_class}."
  puts "Bucket #{bucket.name} has autoclass terminal storage class update time set to #{terminal_class_update_time}."
end

REST API

JSON API

  1. 安装并初始化 gcloud CLI,以便为 Authorization 标头生成访问令牌。

    或者,您可以创建访问令牌(使用 OAuth 2.0 Playground),并将其包含在 Authorization 标头中。

  2. 创建一个包含以下信息的 JSON 文件:

    {
      "storageClass": "DEFAULT_CLASS",
      "autoclass": {
        "enabled": BOOLEAN,
        "terminalStorageClass":TERMINAL_CLASS
      }
    }

    其中:

    • DEFAULT_CLASS 设置存储桶的存储类别元数据。启用 Autoclass 时,STANDARD 是唯一的有效值,如果存储桶目前使用其他存储类别,则必须提供此值。

    • BOOLEANtrue(用于启用 Autoclass)或 false(用于停用 Autoclass)。

    • TERMINAL_CLASS 是启用 Autoclass 时使用的终端存储类别

  3. 使用 cURL,通过 PATCH Bucket 请求调用 JSON API:

    curl -X PATCH --data-binary @JSON_FILE_NAME \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=autoclass"

    其中:

    • JSON_FILE_NAME 是您在第 2 步中创建的 JSON 文件的路径。
    • BUCKET_NAME 是相关存储桶的名称,例如 my-bucket

XML API

此功能无法通过 XML API 进行管理。请改用 Google Cloud 控制台或其他工具。

查看存储桶的 Autoclass 状态

如需查看单个存储桶的 Autoclass 状态,请执行以下操作:

控制台

  1. 在 Google Cloud 控制台中,进入 Cloud Storage 存储桶页面。

    进入“存储桶”

  2. 点击您要查看其状态的存储桶的名称。

  3. 点击配置标签页。

  4. Autoclass 的状态显示在默认存储类别字段中。

    如果启用了 Autoclass,则该字段显示为使用 Autoclass 管理,而包含的类字段显示为对象可以在其之间转换的存储类别。

命令行

使用带有 --format 标志的 gcloud storage buckets describe 命令:

gcloud storage buckets describe gs://BUCKET_NAME --format="default(autoclass)"

其中,BUCKET_NAME 是您要查看其状态的存储桶的名称,例如 my-bucket

如果成功,响应类似于以下示例:

autoclass:
  enabled: true
  terminalStorageClass: ARCHIVE
  terminalStorageClassUpdateTime: '2023-02-10T16:11:02.384000+00:00'
  toggleTime: '2022-11-09T16:01:40.775000+00:00'

客户端库

C++

如需了解详情,请参阅 Cloud Storage C++ API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

namespace gcs = ::google::cloud::storage;
[](gcs::Client client, std::string const& bucket_name) {
  auto metadata = client.GetBucketMetadata(bucket_name);
  if (!metadata) throw google::cloud::Status(std::move(metadata).status());

  if (!metadata->has_autoclass()) {
    std::cout << "The bucket " << metadata->name() << " does not have an"
              << " autoclass configuration.\n";
    return;
  }

  std::cout << "Autoclass is "
            << (metadata->autoclass().enabled ? "enabled" : "disabled")
            << " for bucket " << metadata->name() << ". "
            << " The bucket's full autoclass configuration is "
            << metadata->autoclass() << "\n";
}

C#

如需了解详情,请参阅 Cloud Storage C# API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


using Google.Cloud.Storage.V1;
using System;
using static Google.Apis.Storage.v1.Data.Bucket;

public class GetAutoclassSample
{
    public AutoclassData GetAutoclass(string bucketName)
    {
        var storage = StorageClient.Create();
        var bucket = storage.GetBucket(bucketName);
        Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");
        Console.WriteLine($"Autoclass terminal storage class is set to {bucket.Autoclass.TerminalStorageClass} for {bucketName} at {bucket.Autoclass.TerminalStorageClassUpdateTimeDateTimeOffset}.");
        return bucket.Autoclass;
    }
}

Go

如需了解详情,请参阅 Cloud Storage Go API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

import (
	"context"
	"fmt"
	"io"
	"time"

	"cloud.google.com/go/storage"
)

// getAutoclass gets the Autoclass configuration for a bucket.
// See https://cloud.google.com/storage/docs/using-autoclass for more information.
func getAutoclass(w io.Writer, bucketName string) error {
	// bucketName := "bucket-name"
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	ctx, cancel := context.WithTimeout(ctx, time.Second*10)
	defer cancel()

	attrs, err := client.Bucket(bucketName).Attrs(ctx)
	if err != nil {
		return fmt.Errorf("Bucket(%q).Attrs: %w", bucketName, err)
	}
	fmt.Fprintf(w, "Autoclass enabled was set to %v on bucket %q at %v", attrs.Autoclass.Enabled, bucketName, attrs.Autoclass.ToggleTime)
	fmt.Fprintf(w, "Autoclass terminal storage class was last updated to %v at %v", attrs.Autoclass.TerminalStorageClass, attrs.Autoclass.TerminalStorageClassUpdateTime)
	return nil
}

Java

如需了解详情,请参阅 Cloud Storage Java API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.storage.BucketInfo.Autoclass;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageClass;
import com.google.cloud.storage.StorageOptions;
import java.time.OffsetDateTime;

public class GetBucketAutoclass {
  public static void getBucketAutoclass(String projectId, String bucketName) {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
    Autoclass autoclass = storage.get(bucketName).getAutoclass();
    String status = autoclass.getEnabled() ? "enabled" : "disabled";
    String toggleTime = autoclass.getToggleTime().toString();
    StorageClass terminalStorageClass = autoclass.getTerminalStorageClass();
    OffsetDateTime terminalStorageClassUpdateTime = autoclass.getTerminalStorageClassUpdateTime();

    System.out.println(
        "Autoclass is currently "
            + status
            + " for bucket "
            + bucketName
            + " and was last changed at "
            + toggleTime
            + ". The terminal storage class is set to be "
            + terminalStorageClass.name()
            + " last updated at "
            + terminalStorageClassUpdateTime.toString());
  }
}

Node.js

如需了解详情,请参阅 Cloud Storage Node.js API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function getAutoclass() {
  const [metadata] = await storage.bucket(bucketName).getMetadata();
  console.log(
    `Autoclass is ${
      metadata.autoclass.enabled ? 'enabled' : 'disabled'
    } for ${metadata.name} at ${metadata.autoclass.toggleTime}.
 Autoclass terminal storage class is last updated to ${
   metadata.autoclass.terminalStorageClass
 } at ${metadata.autoclass.terminalStorageClassUpdateTime}.`
  );
}

getAutoclass().catch(console.error);

PHP

如需了解详情,请参阅 Cloud Storage PHP API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

use Google\Cloud\Storage\StorageClient;

/**
 * Print a bucket autoclass configuration.
 *
 * @param string $bucketName The name of your Cloud Storage bucket (e.g. 'my-bucket').
 */
function get_bucket_autoclass(string $bucketName): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);

    $info = $bucket->info();

    if (isset($info['autoclass'])) {
        printf('Bucket %s has autoclass enabled: %s' . PHP_EOL,
            $bucketName,
            $info['autoclass']['enabled']
        );
        printf('Bucket %s has autoclass toggle time: %s' . PHP_EOL,
            $bucketName,
            $info['autoclass']['toggleTime']
        );
        printf(
            'Autoclass terminal storage class is set to %s for %s at %s.' . PHP_EOL,
            $info['autoclass']['terminalStorageClass'],
            $info['name'],
            $info['autoclass']['terminalStorageClassUpdateTime'],
        );
    }
}

Python

如需了解详情,请参阅 Cloud Storage Python API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from google.cloud import storage


def get_autoclass(bucket_name):
    """Get the Autoclass setting for a bucket."""
    # The ID of your GCS bucket
    # bucket_name = "my-bucket"

    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    autoclass_enabled = bucket.autoclass_enabled
    autoclass_toggle_time = bucket.autoclass_toggle_time
    terminal_storage_class = bucket.autoclass_terminal_storage_class
    tsc_update_time = bucket.autoclass_terminal_storage_class_update_time

    print(f"Autoclass enabled is set to {autoclass_enabled} for {bucket.name} at {autoclass_toggle_time}.")
    print(f"Autoclass terminal storage class is set to {terminal_storage_class} for {bucket.name} at {tsc_update_time}.")

    return bucket

Ruby

如需了解详情,请参阅 Cloud Storage Ruby API 参考文档

如需向 Cloud Storage 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

require "google/cloud/storage"

##
# This is a snippet for showcasing how to access the autoclass
# configuration of a bucket.
#
# @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")
#
def get_autoclass bucket_name:
  # Initialize client
  storage = Google::Cloud::Storage.new

  # Fetch the GCS bucket
  bucket = storage.bucket bucket_name
  terminal_class_update_time = bucket.autoclass_terminal_storage_class_update_time

  # Get autoclass config of the bucket
  puts "Bucket #{bucket.name} has autoclass config set to #{bucket.autoclass_enabled}."
  puts "Bucket #{bucket.name} has autoclass toggle time set to #{bucket.autoclass_toggle_time}."
  puts "Bucket #{bucket.name} has autoclass terminal storage class set to #{bucket.autoclass_terminal_storage_class}."
  puts "Bucket #{bucket.name} has autoclass terminal storage class update time set to #{terminal_class_update_time}."
end

REST API

JSON API

  1. 安装并初始化 gcloud CLI,以便为 Authorization 标头生成访问令牌。

    或者,您可以创建访问令牌(使用 OAuth 2.0 Playground),并将其包含在 Authorization 标头中。

  2. 使用 cURL,通过包含 autoclass 字段的 GET Bucket 请求调用 JSON API:

    curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=autoclass"

    其中 BUCKET_NAME 是相关存储桶的名称,例如 my-bucket

    如果存储桶启用了 Autoclass,则响应类似如下示例:

    {
      "autoclass": {
          "enabled": "BOOLEAN",
          "toggleTime": "DATETIME",
          "terminalStorageClass": "STORAGE_CLASS",
          "terminalStorageClassUpdateTime": "DATETIME"
       },
    }

XML API

此功能无法通过 XML API 进行管理。请改用 Google Cloud 控制台或其他工具。

后续步骤