List parameters

This page describes how to retrieve a list of all the parameters within a project.

Listing parameters is useful when you want to get a complete view of all the parameters that you have stored in Parameter Manager, including their names, types, and descriptions. You can also generate reports or gather information about your parameter configurations for auditing purposes.

Required roles

To get the permissions that you need to list parameters, ask your administrator to grant you the Parameter Manager Parameter Viewer ( roles/parametermanager.parameterViewer ) IAM role on the project, folder, or organization. For more information about granting roles, see Manage access to projects, folders, and organizations .

You might also be able to get the required permissions through custom roles or other predefined roles .

List all parameters

To list all parameters in a project, folder, or organization, use one of the following methods:

Global parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see a list of all the parameters in that project.

gcloud

Before using any of the command data below, make the following replacements:

  • PROJECT_ID : the Google Cloud project ID

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud  
parametermanager  
parameters  
list  
--location = 
global  
--project = 
 PROJECT_ID 

Windows (PowerShell)

gcloud  
parametermanager  
parameters  
list  
--location = 
global  
--project = 
 PROJECT_ID 

Windows (cmd.exe)

gcloud  
parametermanager  
parameters  
list  
--location = 
global  
--project = 
 PROJECT_ID 

You should receive a response similar to the following:

projects/production-1/locations/global/parameters/allowed_ip_ranges                         UNFORMATTED  {'iamPolicyUidPrincipal': 'principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/d81462f3-f333-49d6-8a37-18ba24ad21b3'}  2024-10-23T09:58:00.195567192Z  2024-10-23T09:58:00.521576004Z
projects/production-1/locations/global/parameters/app_config                                FORMATTED  {'iamPolicyUidPrincipal': 'principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/4d3737fa-ab28-47f3-8ca7-4ea4d3de6305'}  2024-10-25T13:54:53.162338414Z  2024-10-25T13:54:53.444576707Z

REST

Before using any of the request data, make the following replacements:

  • PROJECT_ID : the Google Cloud project ID

HTTP method and URL:

GET https://parametermanager.googleapis.com/v1/projects/ PROJECT_ID 
/locations/global/parameters

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json , and execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.googleapis.com/v1/projects/ PROJECT_ID /locations/global/parameters"

PowerShell

Save the request body in a file named request.json , and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.googleapis.com/v1/projects/ PROJECT_ID /locations/global/parameters" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "parameters": [
    {
      "name": "projects/production-1/locations/global/parameters/app_config",
      "createTime": "2024-10-15T08:39:05.191747694Z",
      "updateTime": "2024-10-15T08:39:05.530311092Z",
      "format": "YAML",
      "policyMember": {
        "iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/c86ca5bc-f4c2-439d-b62c-d578b4b78b12"
      }
    },
    {
      "name": "projects/production-1/locations/global/parameters/allowed_ip_ranges",
      "createTime": "2024-10-15T08:31:53.250487112Z",
      "updateTime": "2024-10-15T08:31:53.576010644Z",
      "format": "UNFORMATTED",
      "policyMember": {
        "iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/c0100d79-7c8d-4da3-8eb6-fe2a35843d9b"
      }
    }
  ]
}

C#

To run this code, first set up a C# development environment and install the Parameter Manager C# SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  using 
  
  Google.Api.Gax 
 
 ; 
 using 
  
  Google.Api.Gax.ResourceNames 
 
 ; 
 using 
  
  Google.Cloud.ParameterManager.V1 
 
 ; 
 public 
  
 class 
  
 ListParametersSample 
 { 
  
 /// <summary> 
  
 /// This function lists parameter using the Parameter Manager SDK for GCP. 
  
 /// </summary> 
  
 /// <param name="projectId">The ID of the project where the parameter is located.</param> 
  
 /// <returns>A list of Parameter objects.</returns> 
  
 public 
  
 IEnumerable<Parameter> 
  
 ListParameters 
 ( 
 string 
  
 projectId 
 ) 
  
 { 
  
 // Create the client. 
  
  ParameterManagerClient 
 
  
 client 
  
 = 
  
  ParameterManagerClient 
 
 . 
  Create 
 
 (); 
  
 // Build the parent resource name. 
  
  LocationName 
 
  
 parent 
  
 = 
  
 new 
  
  LocationName 
 
 ( 
 projectId 
 , 
  
 "global" 
 ); 
  
 // Call the API to list the parameters. 
  
 PagedEnumerable<ListParametersResponse 
 , 
  
 Parameter 
>  
 response 
  
 = 
  
 client 
 . 
  ListParameters 
 
 ( 
 parent 
 ); 
  
 // Print each parameter name. 
  
 foreach 
  
 ( 
 Parameter 
  
 parameter 
  
 in 
  
 response 
 ) 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Found parameter {parameter.Name} with format {parameter.Format}" 
 ); 
  
 } 
  
 // Return the list of parameters. 
  
 return 
  
 response 
 ; 
  
 } 
 } 
 

Go

To run this code, first set up a Go development environment and install the Parameter Manager Go SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 parametermanager 
  
 "cloud.google.com/go/parametermanager/apiv1" 
  
 parametermanagerpb 
  
 "cloud.google.com/go/parametermanager/apiv1/parametermanagerpb" 
  
 "google.golang.org/api/iterator" 
 ) 
 // listParam lists parameters using the Parameter Manager SDK for GCP. 
 // 
 // w: The io.Writer object used to write the output. 
 // projectID: The ID of the project where the parameters are located. 
 // 
 // The function returns an error if the parameter listing fails. 
 func 
  
 listParams 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
  
 string 
 ) 
  
 error 
  
 { 
  
 // Create a context and a Parameter Manager client. 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 parametermanager 
 . 
  NewClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "failed to create Parameter Manager client: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
  Close 
 
 () 
  
 // Construct the name of the list parameter. 
  
 parent 
  
 := 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/locations/global" 
 , 
  
 projectID 
 ) 
  
 // Build the request to list parameters. 
  
 req 
  
 := 
  
& parametermanagerpb 
 . 
 ListParametersRequest 
 { 
  
 Parent 
 : 
  
 parent 
 , 
  
 } 
  
 // Call the API to list parameters. 
  
 parameters 
  
 := 
  
 client 
 . 
 ListParameters 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 parameter 
 , 
  
 err 
  
 := 
  
 parameters 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "failed to list parameters: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Found parameter %s with format %s \n" 
 , 
  
 parameter 
 . 
 Name 
 , 
  
 parameter 
 . 
 Format 
 . 
 String 
 ()) 
  
 } 
  
 return 
  
 nil 
 } 
 

Java

To run this code, first set up a Java development environment and install the Parameter Manager Java SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  import 
  
 com.google.cloud.parametermanager.v1. LocationName 
 
 ; 
 import 
  
 com.google.cloud.parametermanager.v1. ParameterManagerClient 
 
 ; 
 import 
  
 com.google.cloud.parametermanager.v1. ParameterManagerClient 
. ListParametersPagedResponse 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 /** Class to demonstrate listing parameter using the parameter manager SDK for GCP. */ 
 public 
  
 class 
 ListParams 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 projectId 
  
 = 
  
 "your-project-id" 
 ; 
  
 // Call the method to list parameters. 
  
 listParams 
 ( 
 projectId 
 ); 
  
 } 
  
 // This is an example snippet for listing all parameters in given project. 
  
 public 
  
 static 
  
  ListParametersPagedResponse 
 
  
 listParams 
 ( 
 String 
  
 projectId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // Initialize the client that will be used to send requests. This client only 
  
 // needs to be created once, and can be reused for multiple requests. 
  
 try 
  
 ( 
  ParameterManagerClient 
 
  
 client 
  
 = 
  
  ParameterManagerClient 
 
 . 
 create 
 ()) 
  
 { 
  
 String 
  
 locationId 
  
 = 
  
 "global" 
 ; 
  
 // Build the parent name from the project. 
  
  LocationName 
 
  
 location 
  
 = 
  
  LocationName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 locationId 
 ); 
  
 // Get all parameters. 
  
  ListParametersPagedResponse 
 
  
 response 
  
 = 
  
 client 
 . 
 listParameters 
 ( 
 location 
 . 
  toString 
 
 ()); 
  
 // List all parameters. 
  
 response 
  
 . 
 iterateAll 
 () 
  
 . 
 forEach 
 ( 
 parameter 
  
 - 
>  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Found parameter %s with format %s\n" 
 , 
  
 parameter 
 . 
 getName 
 (), 
  
 parameter 
 . 
 getFormat 
 ())); 
  
 return 
  
 response 
 ; 
  
 } 
  
 } 
 } 
 

Node.js

To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  /** 
 * TODO(developer): Uncomment these variables before running the sample. 
 */ 
 // const projectId = 'my-project'; 
 // Imports the Parameter Manager library 
 const 
  
 { 
 ParameterManagerClient 
 } 
  
 = 
  
 require 
 ( 
 ' @google-cloud/parametermanager 
' 
 ); 
 // Instantiates a client 
 const 
  
 client 
  
 = 
  
 new 
  
  ParameterManagerClient 
 
 (); 
 async 
  
 function 
  
 listParams 
 () 
  
 { 
  
 // Construct the parent string for listing parameters globally 
  
 const 
  
 parent 
  
 = 
  
 client 
 . 
  locationPath 
 
 ( 
 projectId 
 , 
  
 'global' 
 ); 
  
 const 
  
 request 
  
 = 
  
 { 
  
 parent 
 : 
  
 parent 
 , 
  
 }; 
  
 // Use listParametersAsync to handle pagination automatically 
  
 const 
  
 parameters 
  
 = 
  
 await 
  
 client 
 . 
  listParametersAsync 
 
 ( 
 request 
 ); 
  
 for 
  
 await 
  
 ( 
 const 
  
 parameter 
  
 of 
  
 parameters 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
  
 `Found parameter 
 ${ 
 parameter 
 . 
 name 
 } 
 with format 
 ${ 
 parameter 
 . 
 format 
 } 
 ` 
  
 ); 
  
 } 
  
 return 
  
 parameters 
 ; 
 } 
 return 
  
 await 
  
 listParams 
 (); 
 

PHP

To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  // Import necessary classes for list a parameters. 
 use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient; 
 use Google\Cloud\ParameterManager\V1\ListParametersRequest; 
 use Google\Cloud\ParameterManager\V1\ParameterFormat; 
 /** 
 * Lists a parameters using the Parameter Manager SDK for GCP. 
 * 
 * @param string $projectId The Google Cloud Project ID (e.g. 'my-project') 
 */ 
 function list_params(string $projectId): void 
 { 
 // Create a client for the Parameter Manager service. 
 $client = new ParameterManagerClient(); 
 // Build the resource name of the parameter. 
 $parent = $client->locationName($projectId, 'global'); 
 // Prepare the request to list the parameters. 
 $request = (new ListParametersRequest()) 
 ->setParent($parent); 
 // Retrieve the parameter using the client. 
 foreach ($client->listParameters($request) as $parameter) { 
 printf('Found parameter %s with format %s' . PHP_EOL, $parameter->getName(), ParameterFormat::name($parameter->getFormat())); 
 } 
 } 
 

Python

To run this code, first set up a Python development environment and install the Parameter Manager Python SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  def 
  
 list_params 
 ( 
 project_id 
 : 
 str 
 ) 
 - 
> None 
 : 
  
 """ 
 Lists all parameters in the global location for the specified 
 project using the Google Cloud Parameter Manager SDK. 
 Args: 
 project_id (str): The ID of the project 
 where the parameters are located. 
 Returns: 
 None 
 Example: 
 list_params( 
 "my-project" 
 ) 
 """ 
 # Import the necessary library for Google Cloud Parameter Manager. 
 from 
  
 google.cloud 
  
 import 
  parametermanager_v1 
 
 # Create the Parameter Manager client. 
 client 
 = 
  parametermanager_v1 
 
 . 
  ParameterManagerClient 
 
 () 
 # Build the resource name of the parent project in the global location. 
 parent 
 = 
 client 
 . 
  common_location_path 
 
 ( 
 project_id 
 , 
 "global" 
 ) 
 # List all parameters in the specified parent project. 
 for 
 parameter 
 in 
 client 
 . 
  list_parameters 
 
 ( 
 parent 
 = 
 parent 
 ): 
 print 
 ( 
 f 
 "Found parameter 
 { 
 parameter 
 . 
 name 
 } 
 with format 
 { 
 parameter 
 . 
 format_ 
 . 
 name 
 } 
 " 
 ) 
 

Ruby

To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  require 
  
 "google/cloud/parameter_manager" 
 ## 
 # List a parameters 
 # 
 # @param project_id [String] The Google Cloud project (e.g. "my-project") 
 # 
 def 
  
 list_params 
  
 project_id 
 : 
  
 # Create a Parameter Manager client. 
  
 client 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  ParameterManager 
 
 . 
  parameter_manager 
 
  
 # Build the resource name of the parent project. 
  
 parent 
  
 = 
  
 client 
 . 
  location_path 
 
  
 project 
 : 
  
 project_id 
 , 
  
 location 
 : 
  
 "global" 
  
 # List the parameters. 
  
 param_list 
  
 = 
  
 client 
 . 
 list_parameters 
  
 parent 
 : 
  
 parent 
  
 # Print out all parameters. 
  
 param_list 
 . 
 each 
  
 do 
  
 | 
 param 
 | 
  
 puts 
  
 "Found parameter 
 #{ 
 param 
 . 
 name 
 } 
 with format 
 #{ 
 param 
 . 
  format 
 
 } 
 " 
  
 end 
 end 
 

Regional parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see a list of all the parameters in that project.

gcloud

Before using any of the command data below, make the following replacements:

  • LOCATION : the Google Cloud location of the parameter
  • PROJECT_ID : the Google Cloud project ID

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud  
parametermanager  
parameters  
list  
--location = 
 LOCATION 
  
--project = 
 PROJECT_ID 

Windows (PowerShell)

gcloud  
parametermanager  
parameters  
list  
--location = 
 LOCATION 
  
--project = 
 PROJECT_ID 

Windows (cmd.exe)

gcloud  
parametermanager  
parameters  
list  
--location = 
 LOCATION 
  
--project = 
 PROJECT_ID 

You should receive a response similar to the following:

projects/production-1/locations/us-central1/parameters/allowed_ip_ranges                        UNFORMATTED  {'iamPolicyUidPrincipal': 'principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/us-central1/parameters/d81462f3-f333-49d6-8a37-18ba24ad21b3'}  2024-10-23T09:58:00.195567192Z  2024-10-23T09:58:00.521576004Z
projects/production-1/locations/us-central1/parameters/app_config                                FORMATTED  {'iamPolicyUidPrincipal': 'principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/us-central1/parameters/4d3737fa-ab28-47f3-8ca7-4ea4d3de6305'}  2024-10-25T13:54:53.162338414Z  2024-10-25T13:54:53.444576707Z

REST

Before using any of the request data, make the following replacements:

  • LOCATION : the Google Cloud location of the parameters
  • PROJECT_ID : the Google Cloud project ID

HTTP method and URL:

GET https://parametermanager. LOCATION 
.rep.googleapis.com/v1/projects/ PROJECT_ID 
/locations/ LOCATION 
/parameters

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json , and execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager. LOCATION .rep.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /parameters"

PowerShell

Save the request body in a file named request.json , and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager. LOCATION .rep.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /parameters" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "parameters": [
    {
      "name": "projects/production-1/locations/us-central1/parameters/app_config",
      "createTime": "2024-10-30T05:27:28.934719122Z",
      "updateTime": "2024-10-30T05:27:29.010260475Z",
      "format": "YAML",
      "policyMember": {
        "iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/463050620945/uid/locations/us-central1/parameters/6ffe4045-0778-490a-a786-d77b124e2613"
      }
    },
    {
      "name": "projects/production-1/locations/us-central1/parameters/allowed_ip_ranges",
      "createTime": "2024-10-29T06:18:23.070009070Z",
      "updateTime": "2024-10-29T06:18:23.123580038Z",
      "format": "UNFORMATTED",
      "policyMember": {
        "iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/463050620945/uid/locations/us-central1/parameters/a7d81e39-3f53-4794-b3c6-484800a18c32"
      }
    }
  ]
}

C#

To run this code, first set up a C# development environment and install the Parameter Manager C# SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  using 
  
  Google.Api.Gax 
 
 ; 
 using 
  
  Google.Api.Gax.ResourceNames 
 
 ; 
 using 
  
  Google.Cloud.ParameterManager.V1 
 
 ; 
 public 
  
 class 
  
 ListRegionalParametersSample 
 { 
  
 /// <summary> 
  
 /// This function lists all regional parameters using the Parameter Manager SDK for GCP. 
  
 /// </summary> 
  
 /// <param name="projectId">The ID of the project where the parameter is located.</param> 
  
 /// <param name="locationId">The ID of the region where the parameter is located.</param> 
  
 /// <returns>A list of Parameter objects.</returns> 
  
 public 
  
 IEnumerable<Parameter> 
  
 ListRegionalParameters 
 ( 
  
 string 
  
 projectId 
 , 
  
 string 
  
 locationId 
 ) 
  
 { 
  
 // Define the regional endpoint 
  
 string 
  
 regionalEndpoint 
  
 = 
  
 $"parametermanager.{locationId}.rep.googleapis.com" 
 ; 
  
 // Create the client with the regional endpoint 
  
  ParameterManagerClient 
 
  
 client 
  
 = 
  
 new 
  
  ParameterManagerClientBuilder 
 
  
 { 
  
 Endpoint 
  
 = 
  
 regionalEndpoint 
  
 }. 
  Build 
 
 (); 
  
 // Build the parent resource name for the regional locationId 
  
  LocationName 
 
  
 parent 
  
 = 
  
 new 
  
  LocationName 
 
 ( 
 projectId 
 , 
  
 locationId 
 ); 
  
 // Call the API to list the parameters 
  
 PagedEnumerable<ListParametersResponse 
 , 
  
 Parameter 
>  
 response 
  
 = 
  
 client 
 . 
  ListParameters 
 
 ( 
 parent 
 ); 
  
 // Print each parameter name 
  
 foreach 
  
 ( 
 Parameter 
  
 parameter 
  
 in 
  
 response 
 ) 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Found regional parameter {parameter.Name} with format {parameter.Format}" 
 ); 
  
 } 
  
 // Return the list of parameters 
  
 return 
  
 response 
 ; 
  
 } 
 } 
 

Go

To run this code, first set up a Go development environment and install the Parameter Manager Go SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 parametermanager 
  
 "cloud.google.com/go/parametermanager/apiv1" 
  
 parametermanagerpb 
  
 "cloud.google.com/go/parametermanager/apiv1/parametermanagerpb" 
  
 "google.golang.org/api/iterator" 
  
 "google.golang.org/api/option" 
 ) 
 // listRegionalParam lists all parameters regional using the Parameter Manager SDK for GCP. 
 // 
 // projectID: The ID of the project where the parameter is located. 
 // locationID: The ID of the region where the parameter is located. 
 // parameterID: The ID of the parameter to be listed. 
 // 
 // The function returns an error if the parameter listing fails 
 func 
  
 listRegionalParam 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
 , 
  
 locationID 
  
 string 
 ) 
  
 error 
  
 { 
  
 // Create a new context. 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 // Create a Parameter Manager client. 
  
 endpoint 
  
 := 
  
 fmt 
 . 
 Sprintf 
 ( 
 "parametermanager.%s.rep.googleapis.com:443" 
 , 
  
 locationID 
 ) 
  
 client 
 , 
  
 err 
  
 := 
  
 parametermanager 
 . 
  NewClient 
 
 ( 
 ctx 
 , 
  
 option 
 . 
 WithEndpoint 
 ( 
 endpoint 
 )) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "failed to create Parameter Manager client: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
  Close 
 
 () 
  
 // Construct the name of the parent resource to list parameters. 
  
 parent 
  
 := 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/locations/%s" 
 , 
  
 projectID 
 , 
  
 locationID 
 ) 
  
 // Build the request to list all parameters. 
  
 req 
  
 := 
  
& parametermanagerpb 
 . 
 ListParametersRequest 
 { 
  
 Parent 
 : 
  
 parent 
 , 
  
 } 
  
 // Call the API to list all parameters. 
  
 parameters 
  
 := 
  
 client 
 . 
 ListParameters 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 parameter 
 , 
  
 err 
  
 := 
  
 parameters 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "failed to list parameters: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Found regional parameter %s with format %s\n" 
 , 
  
 parameter 
 . 
 Name 
 , 
  
 parameter 
 . 
 Format 
 . 
 String 
 ()) 
  
 } 
  
 return 
  
 nil 
 } 
 

Java

To run this code, first set up a Java development environment and install the Parameter Manager Java SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  import 
  
 com.google.cloud.parametermanager.v1. LocationName 
 
 ; 
 import 
  
 com.google.cloud.parametermanager.v1. ParameterManagerClient 
 
 ; 
 import 
  
 com.google.cloud.parametermanager.v1. ParameterManagerClient 
. ListParametersPagedResponse 
 
 ; 
 import 
  
 com.google.cloud.parametermanager.v1. ParameterManagerSettings 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 /** 
 * Class to demonstrate listing parameters for a specified region using the Parameter Manager SDK 
 * for GCP. 
 */ 
 public 
  
 class 
 ListRegionalParams 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 projectId 
  
 = 
  
 "your-project-id" 
 ; 
  
 String 
  
 locationId 
  
 = 
  
 "your-location-id" 
 ; 
  
 // Call the method to list parameters regionally. 
  
 listRegionalParams 
 ( 
 projectId 
 , 
  
 locationId 
 ); 
  
 } 
  
 // This is an example snippet that list all parameters in a given region. 
  
 public 
  
 static 
  
  ListParametersPagedResponse 
 
  
 listRegionalParams 
 ( 
 String 
  
 projectId 
 , 
  
 String 
  
 locationId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // Endpoint to call the regional parameter manager server 
  
 String 
  
 apiEndpoint 
  
 = 
  
 String 
 . 
 format 
 ( 
 "parametermanager.%s.rep.googleapis.com:443" 
 , 
  
 locationId 
 ); 
  
  ParameterManagerSettings 
 
  
 parameterManagerSettings 
  
 = 
  
  ParameterManagerSettings 
 
 . 
 newBuilder 
 (). 
 setEndpoint 
 ( 
 apiEndpoint 
 ). 
 build 
 (); 
  
 // Initialize the client that will be used to send requests. This client only 
  
 // needs to be created once, and can be reused for multiple requests. 
  
 try 
  
 ( 
  ParameterManagerClient 
 
  
 client 
  
 = 
  
  ParameterManagerClient 
 
 . 
 create 
 ( 
 parameterManagerSettings 
 )) 
  
 { 
  
 // Build the parent name from the project. 
  
  LocationName 
 
  
 location 
  
 = 
  
  LocationName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 locationId 
 ); 
  
 // Get all parameters. 
  
  ListParametersPagedResponse 
 
  
 response 
  
 = 
  
 client 
 . 
 listParameters 
 ( 
 location 
 . 
  toString 
 
 ()); 
  
 // List all parameters. 
  
 response 
  
 . 
 iterateAll 
 () 
  
 . 
 forEach 
 ( 
 parameter 
  
 - 
>  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Found regional parameter %s with format %s\n" 
 , 
  
 parameter 
 . 
 getName 
 (), 
  
 parameter 
 . 
 getFormat 
 ())); 
  
 return 
  
 response 
 ; 
  
 } 
  
 } 
 } 
 

Node.js

To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  /** 
 * TODO(developer): Uncomment these variables before running the sample. 
 */ 
 // const projectId = 'my-project'; 
 // const locationId = 'us-central1'; 
 // Imports the Parameter Manager library 
 const 
  
 { 
 ParameterManagerClient 
 } 
  
 = 
  
 require 
 ( 
 ' @google-cloud/parametermanager 
' 
 ); 
 // Adding the endpoint to call the regional parameter manager server 
 const 
  
 options 
  
 = 
  
 { 
  
 apiEndpoint 
 : 
  
 `parametermanager. 
 ${ 
 locationId 
 } 
 .rep.googleapis.com` 
 , 
 }; 
 // Instantiates a client with regional endpoint 
 const 
  
 client 
  
 = 
  
 new 
  
  ParameterManagerClient 
 
 ( 
 options 
 ); 
 async 
  
 function 
  
 listRegionalParams 
 () 
  
 { 
  
 // Construct the parent string for listing parameters in a specific region 
  
 const 
  
 parent 
  
 = 
  
 client 
 . 
  locationPath 
 
 ( 
 projectId 
 , 
  
 locationId 
 ); 
  
 const 
  
 request 
  
 = 
  
 { 
  
 parent 
 : 
  
 parent 
 , 
  
 }; 
  
 // Use listParametersAsync to handle pagination automatically 
  
 const 
  
 parameters 
  
 = 
  
 await 
  
 client 
 . 
  listParametersAsync 
 
 ( 
 request 
 ); 
  
 for 
  
 await 
  
 ( 
 const 
  
 parameter 
  
 of 
  
 parameters 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
  
 `Found regional parameter 
 ${ 
 parameter 
 . 
 name 
 } 
 with format 
 ${ 
 parameter 
 . 
 format 
 } 
 ` 
  
 ); 
  
 } 
  
 return 
  
 parameters 
 ; 
 } 
 return 
  
 await 
  
 listRegionalParams 
 (); 
 

PHP

To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  // Import necessary classes for list a parameters. 
 use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient; 
 use Google\Cloud\ParameterManager\V1\ListParametersRequest; 
 use Google\Cloud\ParameterManager\V1\ParameterFormat; 
 /** 
 * Lists a regional parameters using the Parameter Manager SDK for GCP. 
 * 
 * @param string $projectId The Google Cloud Project ID (e.g. 'my-project') 
 * @param string $locationId The Parameter Location (e.g. 'us-central1') 
 */ 
 function list_regional_params(string $projectId, string $locationId): void 
 { 
 // Specify regional endpoint. 
 $options = ['apiEndpoint' => "parametermanager.$locationId.rep.googleapis.com"]; 
 // Create a client for the Parameter Manager service. 
 $client = new ParameterManagerClient($options); 
 // Build the resource name of the parameter. 
 $parent = $client->locationName($projectId, $locationId); 
 // Prepare the request to list the parameters. 
 $request = (new ListParametersRequest()) 
 ->setParent($parent); 
 // Retrieve the parameter using the client. 
 foreach ($client->listParameters($request) as $parameter) { 
 printf('Found regional parameter %s with format %s' . PHP_EOL, $parameter->getName(), ParameterFormat::name($parameter->getFormat())); 
 } 
 } 
 

Python

To run this code, first set up a Python development environment and install the Parameter Manager Python SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  def 
  
 list_regional_params 
 ( 
 project_id 
 : 
 str 
 , 
 location_id 
 : 
 str 
 ) 
 - 
> None 
 : 
  
 """ 
 Lists all parameters in the specified region for the specified 
 project using the Google Cloud Parameter Manager SDK. 
 Args: 
 project_id (str): The ID of the project where 
 the parameters are located. 
 location_id (str): The ID of the region where 
 the parameters are located. 
 Returns: 
 None 
 Example: 
 list_regional_params( 
 "my-project", 
 "us-central1" 
 ) 
 """ 
 # Import the necessary library for Google Cloud Parameter Manager. 
 from 
  
 google.cloud 
  
 import 
  parametermanager_v1 
 
 # Create the Parameter Manager client with the regional endpoint. 
 api_endpoint 
 = 
 f 
 "parametermanager. 
 { 
 location_id 
 } 
 .rep.googleapis.com" 
 client 
 = 
  parametermanager_v1 
 
 . 
  ParameterManagerClient 
 
 ( 
 client_options 
 = 
 { 
 "api_endpoint" 
 : 
 api_endpoint 
 } 
 ) 
 # Build the resource name of the parent project in the specified region. 
 parent 
 = 
 client 
 . 
  common_location_path 
 
 ( 
 project_id 
 , 
 location_id 
 ) 
 # List all parameters in the specified parent project and region. 
 for 
 parameter 
 in 
 client 
 . 
  list_parameters 
 
 ( 
 parent 
 = 
 parent 
 ): 
 print 
 ( 
 f 
 "Found regional parameter 
 { 
 parameter 
 . 
 name 
 } 
 with format 
 { 
 parameter 
 . 
 format_ 
 . 
 name 
 } 
 " 
 ) 
 

Ruby

To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK . On Compute Engine or GKE, you must authenticate with the cloud-platform scope .

  require 
  
 "google/cloud/parameter_manager" 
 ## 
 # List a regional parameters 
 # 
 # @param project_id [String] The Google Cloud project (e.g. "my-project") 
 # @param location_id [String] The location name (e.g. "us-central1") 
 # 
 def 
  
 list_regional_params 
  
 project_id 
 :, 
  
 location_id 
 : 
  
 # Endpoint for the regional parameter manager service. 
  
 api_endpoint 
  
 = 
  
 "parametermanager. 
 #{ 
 location_id 
 } 
 .rep.googleapis.com" 
  
 # Create the Parameter Manager client. 
  
 client 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
  ParameterManager 
 
 . 
  parameter_manager 
 
  
 do 
  
 | 
 config 
 | 
  
 config 
 . 
 endpoint 
  
 = 
  
 api_endpoint 
  
 end 
  
 # Build the resource name of the parent project. 
  
 parent 
  
 = 
  
 client 
 . 
  location_path 
 
  
 project 
 : 
  
 project_id 
 , 
  
 location 
 : 
  
 location_id 
  
 # List the parameters. 
  
 param_list 
  
 = 
  
 client 
 . 
 list_parameters 
  
 parent 
 : 
  
 parent 
  
 # Print out all parameters. 
  
 param_list 
 . 
 each 
  
 do 
  
 | 
 param 
 | 
  
 puts 
  
 "Found regional parameter 
 #{ 
 param 
 . 
 name 
 } 
 with format 
 #{ 
 param 
 . 
  format 
 
 } 
 " 
  
 end 
 end 
 

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: