Cloud Storage-Dienst-Agent abrufen

Mit Sammlungen den Überblick behalten Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.

Auf dieser Seite wird beschrieben, wie Sie die E-Mail-Adresse des Cloud Storage-Dienst-Agents eines Projekts finden. Ein Dienst-Agent ist ein spezialisiertes Dienstkonto, das von Cloud Storage erstellt und verwaltet wird. Einen Überblick über Cloud Storage-Dienst-Agents, einschließlich ihrer Erstellung und Verwendung, finden Sie unter Dienstkonten für Cloud Storage. Eine allgemeine Übersicht über Dienstkonten in Google Cloud finden Sie unter Dienstkonten.

E-Mail-Adresse des Cloud Storage-Dienst-Agents eines Projekts abrufen:

Console

  1. Wechseln Sie in der Cloud Console zur Seite Cloud Storage-Buckets.

    Buckets aufrufen

  2. Klicken Sie auf Settings (Einstellungen).

  3. Auf dem Tab Projektzugriff wird die E-Mail-Adresse im Abschnitt Cloud Storage-Dienstkonto angezeigt.

Befehlszeile

gcloud

Führen Sie den Befehl gcloud storage service-agent aus:

gcloud storage service-agent --project=PROJECT_IDENTIFIER

Dabei ist PROJECT_IDENTIFIER die ID oder Nummer des entsprechenden Projekts. Beispiel: my-project.

gsutil

Führen Sie den Befehl kms serviceaccount aus:

gsutil kms serviceaccount -p PROJECT_IDENTIFIER

Dabei ist PROJECT_IDENTIFIER die ID oder Nummer des entsprechenden Projekts. Beispiel: my-project.

Clientbibliotheken

C++

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage C++ API.

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client) {
  StatusOr<gcs::ServiceAccount> account = client.GetServiceAccount();
  if (!account) throw std::move(account).status();

  std::cout << "The service account details are " << *account << "\n";
}

C#

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage C# API.


using Google.Cloud.Storage.V1;
using System;

public class GetStorageServiceAccountSample
{
	public string GetStorageServiceAccount(string projectId = "your-project-id")
	{
		var storage = StorageClient.Create();

		var serviceAccountEmail = storage.GetStorageServiceAccountEmail(projectId);

		Console.WriteLine($"The GCS service account for project {projectId} is: {serviceAccountEmail}.");
		return serviceAccountEmail;
	}
}

Go

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage Go API.

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

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

// getServiceAccount gets the default Cloud Storage service account email address.
func getServiceAccount(w io.Writer, projectID string) error {
	// projectID := "my-project-id"

	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %v", err)
	}
	defer client.Close()

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

	serviceAccount, err := client.ServiceAccount(ctx, projectID)
	if err != nil {
		return fmt.Errorf("ServiceAccount: %v", err)
	}

	fmt.Fprintf(w, "The GCS service account for project %v is: %v\n", projectID, serviceAccount)
	return nil
}

Java

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage Java API.

import com.google.cloud.storage.ServiceAccount;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class GetServiceAccount {
  public static void getServiceAccount(String projectId) {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
    ServiceAccount serviceAccount = storage.getServiceAccount(projectId);
    System.out.println(
        "The GCS service account for project " + projectId + " is: " + serviceAccount.getEmail());
  }
}

Node.js

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage Node.js API.

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCP project
// const projectId = 'your-project-id';

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

// Creates a client
const storage = new Storage({
  projectId,
});

async function getServiceAccount() {
  const [serviceAccount] = await storage.getServiceAccount();
  console.log(
    `The GCS service account for project ${projectId} is: ${serviceAccount.emailAddress}`
  );
}

getServiceAccount().catch(console.error);

PHP

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage PHP API.

use Google\Cloud\Storage\StorageClient;

/**
 * Get the current service account email.
 *
 * @param string $projectId The ID of your Google Cloud Platform project.
 *        (e.g. 'my-project-id')
 */
function get_service_account(string $projectId): void
{
    $storage = new StorageClient([
        'projectId' => $projectId,
    ]);

    $serviceAccountEmail = $storage->getServiceAccount();

    printf('The GCS service account email for project %s is %s', $projectId, $serviceAccountEmail);
}

Python

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage Python API.

from google.cloud import storage

def get_service_account():
    """Get the service account email"""
    storage_client = storage.Client()

    email = storage_client.get_service_account_email()
    print(
        f"The GCS service account for project {storage_client.project} is: {email} "
    )

Ruby

Weitere Informationen finden Sie in der Referenzdokumentation zur Cloud Storage Ruby API.

def get_service_account
  require "google/cloud/storage"

  storage = Google::Cloud::Storage.new
  email = storage.service_account_email

  puts "The GCS service account for project #{storage.project_id} is: #{email}"
end

JSON API

  1. Rufen Sie ein Zugriffstoken für die Autorisierung aus dem OAuth 2.0 Playground ab. Konfigurieren Sie den Playground so, dass Ihre eigenen OAuth-Anmeldedaten verwendet werden. Eine Anleitung finden Sie unter API-Authentifizierung.
  2. Verwenden Sie cURL, um die JSON API mit einer GET serviceAccount-Objektanfrage aufzurufen:

    curl -X GET -H "Authorization: Bearer OAUTH2_TOKEN" \
    "https://storage.googleapis.com/storage/v1/projects/PROJECT_ID/serviceAccount"

    Dabei gilt:

    • OAUTH2_TOKEN ist der Name des Zugriffstokens, das Sie in Schritt 1 generiert haben.
    • PROJECT_ID ist die ID oder Nummer des entsprechenden Projekts. Beispiel: my-project.

Nächste Schritte