Eliminar espacio de nombres

Permiso para eliminar un espacio de nombres de Directorio de servicios.

Investigar más

Para obtener documentación detallada que incluya este código de muestra, consulta lo siguiente:

Código de ejemplo

C#

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.


using Google.Cloud.ServiceDirectory.V1;

public class DeleteNamespaceSample
{
    public void DeleteNamespace(
        string projectId = "projectId",
        string locationId = "us-east1",
        string namespaceId = "test-namespace")
    {
        // Create client
        RegistrationServiceClient registrationServiceClient = RegistrationServiceClient.Create();
        // Initialize request argument(s)
        var namespaceName = NamespaceName.FromProjectLocationNamespace(projectId, locationId, namespaceId);
        registrationServiceClient.DeleteNamespace(namespaceName);
    }
}

Go

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

import (
	"context"
	"fmt"

	servicedirectory "cloud.google.com/go/servicedirectory/apiv1"
	sdpb "cloud.google.com/go/servicedirectory/apiv1/servicedirectorypb"
)

func deleteNamespace(projectID string) error {
	// projectID := "my-project"
	location := "us-east4"
	namespaceID := "golang-test-namespace"

	ctx := context.Background()
	// Create a registration client.
	client, err := servicedirectory.NewRegistrationClient(ctx)
	if err != nil {
		return fmt.Errorf("ServiceDirectory.NewRegistrationClient: %w", err)
	}

	defer client.Close()
	// Delete a Namespace.
	req := &sdpb.DeleteNamespaceRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/namespaces/%s", projectID, location, namespaceID),
	}
	if err := client.DeleteNamespace(ctx, req); err != nil {
		return fmt.Errorf("DeleteNamespace: %w", err)
	}
	return nil
}

Java

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.


import com.google.cloud.servicedirectory.v1.NamespaceName;
import com.google.cloud.servicedirectory.v1.RegistrationServiceClient;
import java.io.IOException;

public class NamespacesDelete {

  public static void deleteNamespace() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // These variables should refer to an existing Service Directory namespace.
    String projectId = "your-project-id";
    String locationId = "your-region";
    String namespaceId = "your-namespace";
    deleteNamespace(projectId, locationId, namespaceId);
  }

  // Delete a namespace.
  public static void deleteNamespace(String projectId, String locationId, String namespaceId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (RegistrationServiceClient client = RegistrationServiceClient.create()) {

      // The namespace to delete.
      NamespaceName namespaceName = NamespaceName.of(projectId, locationId, namespaceId);

      // Send the request to delete the namespace.
      client.deleteNamespace(namespaceName);

      // Log the action.
      System.out.println("Deleted Namespace: " + namespaceName.toString());
    }
  }
}

Node.js

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

//
// TODO(developer): Uncomment these variables before running the sample.
//
// const projectId = 'my-project';
// const locationId = 'us-central1';
// const namespaceId = 'my-namespace';

// Imports the Google Cloud client library
const {
  RegistrationServiceClient,
} = require('@google-cloud/service-directory');

// Creates a client
const registrationServiceClient = new RegistrationServiceClient();

// Build the namespace name
const namespaceName = registrationServiceClient.namespacePath(
  projectId,
  locationId,
  namespaceId
);

async function deleteNamespace() {
  await registrationServiceClient.deleteNamespace({
    name: namespaceName,
  });

  console.log(`Deleted namespace: ${namespaceName}`);
}

deleteNamespace();

PHP

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
use Google\Cloud\ServiceDirectory\V1\DeleteNamespaceRequest;

/**
 * @param string $projectId     Your Cloud project ID
 * @param string $locationId    Your GCP region
 * @param string $namespaceId   Your namespace name
 */
function delete_namespace(
    string $projectId,
    string $locationId,
    string $namespaceId
): void {
    // Instantiate a client.
    $client = new RegistrationServiceClient();

    // Run request.
    $namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
    $deleteNamespaceRequest = (new DeleteNamespaceRequest())
        ->setName($namespaceName);
    $client->deleteNamespace($deleteNamespaceRequest);

    // Print results.
    printf('Deleted Namespace: %s' . PHP_EOL, $namespaceName);
}

Python

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

def delete_namespace(project_id: str, location: str, namespace_id: str) -> bool:
    """Deletes a namespace in the given location.

    Args:
        project_id: Your Google Cloud project id.
        location: The Google Cloud region containing the namespace to delete.
        namespace_id: The id for the namespace to delete.
    """

    client = servicedirectory_v1.RegistrationServiceClient()

    namespace_name = client.namespace_path(project_id, location, namespace_id)

    client.delete_namespace(name=namespace_name)
    print(f"Deleted namespace {namespace_name}.")
    return True

Ruby

Para obtener información sobre cómo instalar y usar la biblioteca de cliente de Service Directory, consulta Bibliotecas de cliente de Service Directory.

Para autenticarte en Service Directory, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

# project   = "Your Google Cloud project ID"
# location  = "The Google Cloud region containing the namespace"
# namespace = "The name of the namespace"

require "google/cloud/service_directory"

# Initialize the client
registration_service = Google::Cloud::ServiceDirectory.registration_service

# The path of the namespace
namespace_name = registration_service.namespace_path(
  project: project, location: location, namespace: namespace
)

# Use the Service Directory API to delete the namespace
registration_service.delete_namespace name: namespace_name
puts "Deleted namespace: #{namespace_name}"

Siguientes pasos

Para buscar y filtrar ejemplos de código de otros Google Cloud productos, consulta el Google Cloud navegador de ejemplos.