Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion parametermanager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.60.0</version>
<version>26.90.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -56,6 +56,11 @@
<artifactId>google-cloud-parametermanager</artifactId>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-resourcemanager</artifactId>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package parametermanager;

// [START parametermanager_bind_tags_to_param]

import com.google.cloud.parametermanager.v1.LocationName;
import com.google.cloud.parametermanager.v1.Parameter;
import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.resourcemanager.v3.TagBinding;
import com.google.cloud.resourcemanager.v3.TagBindingsClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**
* This class demonstrates how to create a parameter and bind a tag to it using the Parameter
* Manager SDK for GCP.
*/
public class BindTagsToParam {

public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String parameterId = "your-parameter-id";
String tagValue = "tagValues/1234567890";

// Call the method to create a parameter and bind a tag to it.
bindTagsToParam(projectId, parameterId, tagValue);
}

// This is an example snippet for creating a parameter and binding a tag to it.
public static TagBinding bindTagsToParam(String projectId, String parameterId, String tagValue)
throws IOException, ExecutionException, InterruptedException {

// 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();
TagBindingsClient tagBindingsClient = TagBindingsClient.create()) {
String locationId = "global";

// Build the parent name from the project.
LocationName location = LocationName.of(projectId, locationId);

// Create the parameter.
Parameter parameter =
client.createParameter(location.toString(), Parameter.newBuilder().build(), parameterId);
System.out.printf("Created parameter: %s\n", parameter.getName());

// Build the tag binding for the new parameter.
TagBinding tagBinding =
TagBinding.newBuilder()
.setParent("//parametermanager.googleapis.com/" + parameter.getName())
.setTagValue(tagValue)
.build();

// Create the tag binding and wait for the operation to complete.
TagBinding createdTagBinding = tagBindingsClient.createTagBindingAsync(tagBinding).get();
System.out.printf("Created tag binding: %s\n", createdTagBinding.getName());

return createdTagBinding;
}
}
}
// [END parametermanager_bind_tags_to_param]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package parametermanager;

// [START parametermanager_create_param_template]

import com.google.cloud.parametermanager.v1.LocationName;
import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.parametermanager.v1.Template;
import com.google.cloud.parametermanager.v1.TemplateFormat;
import java.io.IOException;

/** This class demonstrates how to create a template using the Parameter Manager SDK for GCP. */
public class CreateParamTemplate {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String templateId = "your-template-id";
TemplateFormat format = TemplateFormat.TEMPLATE_FORMAT_JSON;

// Call the method to create a template.
createParamTemplate(projectId, templateId, format);
}

// This is an example snippet for creating a template.
public static Template createParamTemplate(
String projectId, String templateId, TemplateFormat format) 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);

// Build the template to create.
Template template = Template.newBuilder().setFormat(format).build();

// Create the template.
Template createdTemplate = client.createTemplate(location.toString(), template, templateId);
System.out.printf(
"Created template %s with format %s\n",
createdTemplate.getName(), createdTemplate.getFormat());

return createdTemplate;
}
}
}
// [END parametermanager_create_param_template]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package parametermanager;

// [START parametermanager_create_param_template_version]

import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.parametermanager.v1.TemplateName;
import com.google.cloud.parametermanager.v1.TemplateVersion;
import com.google.cloud.parametermanager.v1.TemplateVersionPayload;
import com.google.protobuf.ByteString;
import java.io.IOException;

/**
* This class demonstrates how to create a template version using the Parameter Manager SDK for GCP.
*/
public class CreateParamTemplateVersion {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String templateId = "your-template-id";
String versionId = "your-version-id";

// Call the method to create a template version.
createParamTemplateVersion(projectId, templateId, versionId);
}

// This is an example snippet for creating a template version with placeholders in its payload.
public static TemplateVersion createParamTemplateVersion(
String projectId, String templateId, String versionId) 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 template name.
TemplateName templateName = TemplateName.of(projectId, locationId, templateId);

// Build the template version payload with placeholders.
String payload = "{\"username\": \"{{.username}}\", \"host\": \"{{.host}}\"}";
TemplateVersionPayload templateVersionPayload =
TemplateVersionPayload.newBuilder().setData(ByteString.copyFromUtf8(payload)).build();

// Build the template version to create.
TemplateVersion templateVersion =
TemplateVersion.newBuilder().setPayload(templateVersionPayload).build();

// Create the template version.
TemplateVersion createdTemplateVersion =
client.createTemplateVersion(templateName.toString(), templateVersion, versionId);
System.out.printf("Created template version: %s\n", createdTemplateVersion.getName());

return createdTemplateVersion;
}
}
}
// [END parametermanager_create_param_template_version]
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package parametermanager;

// [START parametermanager_create_param_version_with_checksum]

import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.parametermanager.v1.ParameterName;
import com.google.cloud.parametermanager.v1.ParameterVersion;
import com.google.cloud.parametermanager.v1.ParameterVersionPayload;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32C;

/**
* This class demonstrates how to create a parameter version with a checksum using the Parameter
* Manager SDK for GCP.
*/
public class CreateParamVersionWithChecksum {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String parameterId = "your-parameter-id";
String versionId = "your-version-id";

// Call the method to create a parameter version with a checksum.
createParamVersionWithChecksum(projectId, parameterId, versionId);
}

// This is an example snippet for creating a parameter version with a CRC32C checksum of the
// payload.
public static ParameterVersion createParamVersionWithChecksum(
String projectId, String parameterId, String versionId) 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 parameter name.
ParameterName parameterName = ParameterName.of(projectId, locationId, parameterId);

// Define the payload and compute its CRC32C checksum.
byte[] data = "hello world!".getBytes(StandardCharsets.UTF_8);
CRC32C crc32c = new CRC32C();
crc32c.update(data);

// Build the parameter version with the payload and checksum.
ParameterVersionPayload payload =
ParameterVersionPayload.newBuilder()
.setData(ByteString.copyFrom(data))
.setDataCrc32C(crc32c.getValue())
.build();
ParameterVersion parameterVersion = ParameterVersion.newBuilder().setPayload(payload).build();

// Create the parameter version.
ParameterVersion createdParameterVersion =
client.createParameterVersion(parameterName.toString(), parameterVersion, versionId);
System.out.printf("Created parameter version: %s\n", createdParameterVersion.getName());
System.out.printf("Checksum source: %s\n", createdParameterVersion.getChecksumSource());

return createdParameterVersion;
}
}
}
// [END parametermanager_create_param_version_with_checksum]
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package parametermanager;

// [START parametermanager_create_param_with_tags]

import com.google.cloud.parametermanager.v1.LocationName;
import com.google.cloud.parametermanager.v1.Parameter;
import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import java.io.IOException;

/**
* This class demonstrates how to create a parameter with a tag using the Parameter Manager SDK for
* GCP.
*/
public class CreateParamWithTags {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String parameterId = "your-parameter-id";
String tagKey = "tagKeys/1234567890";
String tagValue = "tagValues/1234567890";

// Call the method to create a parameter with a tag.
createParamWithTags(projectId, parameterId, tagKey, tagValue);
}

// This is an example snippet for creating a parameter with a tag.
public static Parameter createParamWithTags(
String projectId, String parameterId, String tagKey, String tagValue) 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);

// Build the parameter to create with the tag.
Parameter parameter = Parameter.newBuilder().putTags(tagKey, tagValue).build();

// Create the parameter.
Parameter createdParameter =
client.createParameter(location.toString(), parameter, parameterId);
System.out.printf(
"Created parameter %s with tag %s: %s\n", createdParameter.getName(), tagKey, tagValue);

return createdParameter;
}
}
}
// [END parametermanager_create_param_with_tags]
Loading
Loading