Skip to content

Commit 2b72975

Browse files
feat(parametermanager): Added samples for delete, disable and enable regional parameter (#2993)
1 parent 6713846 commit 2b72975

10 files changed

+426
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.Cloud.ParameterManager.V1;
18+
19+
[Collection(nameof(ParameterManagerRegionalFixture))]
20+
public class DeleteRegionalParameterTests
21+
{
22+
private readonly ParameterManagerRegionalFixture _fixture;
23+
private readonly DeleteRegionalParameterSample _sample;
24+
25+
public DeleteRegionalParameterTests(ParameterManagerRegionalFixture fixture)
26+
{
27+
_fixture = fixture;
28+
_sample = new DeleteRegionalParameterSample();
29+
}
30+
31+
[Fact]
32+
public void DeleteRegionalParameter()
33+
{
34+
string parameterId = _fixture.RandomId();
35+
Parameter parameter = _fixture.CreateParameter(parameterId, ParameterFormat.Unformatted);
36+
37+
_sample.DeleteRegionalParameter(projectId: _fixture.ProjectId, locationId: ParameterManagerRegionalFixture.LocationId, parameterId: parameterId);
38+
39+
ParameterManagerClient client = _fixture.Client;
40+
var exception = Assert.Throws<Grpc.Core.RpcException>(() => client.GetParameter(parameter.ParameterName));
41+
Assert.Equal(Grpc.Core.StatusCode.NotFound, exception.Status.StatusCode);
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.Cloud.ParameterManager.V1;
18+
19+
[Collection(nameof(ParameterManagerRegionalFixture))]
20+
public class DeleteRegionalParameterVersionTests
21+
{
22+
private readonly ParameterManagerRegionalFixture _fixture;
23+
private readonly DeleteRegionalParameterVersionSample _sample;
24+
25+
public DeleteRegionalParameterVersionTests(ParameterManagerRegionalFixture fixture)
26+
{
27+
_fixture = fixture;
28+
_sample = new DeleteRegionalParameterVersionSample();
29+
}
30+
31+
[Fact]
32+
public void DeleteRegionalParameterVersion()
33+
{
34+
var (parameterId, versionId, parameter, payload) = _fixture.CreateParameterWithVersion();
35+
36+
ParameterVersion parameterVersion = _fixture.CreateParameterVersion(parameterId, versionId, payload);
37+
_sample.DeleteRegionalParameterVersion(projectId: _fixture.ProjectId, locationId: ParameterManagerRegionalFixture.LocationId, parameterId: parameterId, versionId: versionId);
38+
39+
ParameterManagerClient client = _fixture.Client;
40+
var exception = Assert.Throws<Grpc.Core.RpcException>(() => client.GetParameterVersion(parameterVersion.ParameterVersionName));
41+
Assert.Equal(Grpc.Core.StatusCode.NotFound, exception.Status.StatusCode);
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.Cloud.ParameterManager.V1;
18+
19+
[Collection(nameof(ParameterManagerRegionalFixture))]
20+
public class DisableRegionalParameterVersionTests
21+
{
22+
private readonly ParameterManagerRegionalFixture _fixture;
23+
private readonly DisableRegionalParameterVersionSample _sample;
24+
25+
public DisableRegionalParameterVersionTests(ParameterManagerRegionalFixture fixture)
26+
{
27+
_fixture = fixture;
28+
_sample = new DisableRegionalParameterVersionSample();
29+
}
30+
31+
[Fact]
32+
public void DisableRegionalParameterVersion()
33+
{
34+
var (parameterId, versionId, parameter, payload) = _fixture.CreateParameterWithVersion();
35+
36+
ParameterVersion parameterVersion = _fixture.CreateParameterVersion(parameterId, versionId, payload);
37+
ParameterVersion result = _sample.DisableRegionalParameterVersion(projectId: _fixture.ProjectId, locationId: ParameterManagerRegionalFixture.LocationId, parameterId: parameterId, versionId: versionId);
38+
39+
Assert.NotNull(result);
40+
Assert.True(result.Disabled);
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.Cloud.ParameterManager.V1;
18+
19+
[Collection(nameof(ParameterManagerRegionalFixture))]
20+
public class EnableRegionalParameterVersionTests
21+
{
22+
private readonly ParameterManagerRegionalFixture _fixture;
23+
private readonly EnableRegionalParameterVersionSample _sample;
24+
25+
public EnableRegionalParameterVersionTests(ParameterManagerRegionalFixture fixture)
26+
{
27+
_fixture = fixture;
28+
_sample = new EnableRegionalParameterVersionSample();
29+
}
30+
31+
[Fact]
32+
public void EnableRegionalParameterVersion()
33+
{
34+
var (parameterId, versionId, parameter, payload) = _fixture.CreateParameterWithVersion();
35+
36+
ParameterVersion parameterVersion = _fixture.CreateParameterVersion(parameterId, versionId, payload);
37+
ParameterVersion result = _sample.EnableRegionalParameterVersion(projectId: _fixture.ProjectId, locationId: ParameterManagerRegionalFixture.LocationId, parameterId: parameterId, versionId: versionId);
38+
39+
Assert.NotNull(result);
40+
Assert.False(result.Disabled);
41+
}
42+
}

parametermanager/api/ParameterManager.RegionalSamples.Tests/ParameterManagerRegionalFixture.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public string RandomId()
7676
return $"csharp-{System.Guid.NewGuid()}";
7777
}
7878

79+
public (string parameterId, string versionId, Parameter parameter, string payload) CreateParameterWithVersion()
80+
{
81+
string parameterId = RandomId();
82+
string versionId = RandomId();
83+
Parameter parameter = CreateParameter(parameterId, ParameterFormat.Unformatted);
84+
string payload = "test123";
85+
return (parameterId, versionId, parameter, payload);
86+
}
87+
7988
public Parameter CreateParameter(string parameterId, ParameterFormat format)
8089
{
8190
LocationName parent = new LocationName(ProjectId, LocationId);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START parametermanager_delete_regional_param]
18+
19+
using Google.Cloud.ParameterManager.V1;
20+
21+
public class DeleteRegionalParameterSample
22+
{
23+
/// <summary>
24+
/// This function deletes a regional parameter using the Parameter Manager SDK for GCP.
25+
/// </summary>
26+
/// <param name="projectId">The ID of the project where the parameter is located.</param>
27+
/// <param name="locationId">The ID of the region where the parameter is located.</param>
28+
/// <param name="parameterId">The ID of the parameter to be deleted.</param>
29+
public void DeleteRegionalParameter(
30+
string projectId,
31+
string locationId,
32+
string parameterId)
33+
{
34+
// Define the regional endpoint
35+
string regionalEndpoint = $"parametermanager.{locationId}.rep.googleapis.com";
36+
37+
// Create the client with the regional endpoint
38+
ParameterManagerClient client = new ParameterManagerClientBuilder
39+
{
40+
Endpoint = regionalEndpoint
41+
}.Build();
42+
43+
// Build the resource name for the parameter in the specified regional locationId
44+
ParameterName parameterName = new ParameterName(projectId, locationId, parameterId);
45+
46+
// Call the API to delete the parameter
47+
client.DeleteParameter(parameterName);
48+
49+
Console.WriteLine($"Deleted regional parameter: {parameterName}");
50+
}
51+
}
52+
// [END parametermanager_delete_regional_param]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START parametermanager_delete_regional_param_version]
18+
19+
using Google.Cloud.ParameterManager.V1;
20+
21+
public class DeleteRegionalParameterVersionSample
22+
{
23+
/// <summary>
24+
/// This function deletes a regional parameter version using the Parameter Manager SDK for GCP.
25+
/// </summary>
26+
/// <param name="projectId">The ID of the project where the parameter is located.</param>
27+
/// <param name="locationId">The ID of the region where the parameter is located.</param>
28+
/// <param name="parameterId">The ID of the parameter for which the version is to be deleted.</param>
29+
/// <param name="versionId">The ID of the version to be deleted.</param>
30+
public void DeleteRegionalParameterVersion(
31+
string projectId,
32+
string locationId,
33+
string parameterId,
34+
string versionId)
35+
{
36+
// Define the regional endpoint
37+
string regionalEndpoint = $"parametermanager.{locationId}.rep.googleapis.com";
38+
39+
// Create the client with the regional endpoint
40+
ParameterManagerClient client = new ParameterManagerClientBuilder
41+
{
42+
Endpoint = regionalEndpoint
43+
}.Build();
44+
45+
// Build the resource name for the parameter version in the specified regional locationId
46+
ParameterVersionName parameterVersionName = new ParameterVersionName(projectId, locationId, parameterId, versionId);
47+
48+
// Call the API to delete the parameter version
49+
client.DeleteParameterVersion(parameterVersionName);
50+
51+
Console.WriteLine($"Deleted regional parameter version: {parameterVersionName}");
52+
}
53+
}
54+
// [END parametermanager_delete_regional_param_version]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START parametermanager_disable_regional_param_version]
18+
19+
using Google.Cloud.ParameterManager.V1;
20+
using Google.Protobuf.WellKnownTypes;
21+
22+
public class DisableRegionalParameterVersionSample
23+
{
24+
/// <summary>
25+
/// This function disables a regional parameter version using the Parameter Manager SDK for GCP.
26+
/// </summary>
27+
/// <param name="projectId">The ID of the project where the parameter is located.</param>
28+
/// <param name="locationId">The ID of the region where the parameter is located.</param>
29+
/// <param name="parameterId">The ID of the parameter for which the version is to be disabled.</param>
30+
/// <param name="versionId">The ID of the version to be disabled.</param>
31+
public ParameterVersion DisableRegionalParameterVersion(
32+
string projectId,
33+
string locationId,
34+
string parameterId,
35+
string versionId)
36+
{
37+
// Define the regional endpoint
38+
string regionalEndpoint = $"parametermanager.{locationId}.rep.googleapis.com";
39+
40+
// Create the client with the regional endpoint
41+
ParameterManagerClient client = new ParameterManagerClientBuilder
42+
{
43+
Endpoint = regionalEndpoint
44+
}.Build();
45+
46+
// Build the resource name for the parameter version in the specified regional locationId
47+
ParameterVersionName parameterVersionName = new ParameterVersionName(projectId, locationId, parameterId, versionId);
48+
49+
UpdateParameterVersionRequest request = new UpdateParameterVersionRequest
50+
{
51+
ParameterVersion = new ParameterVersion
52+
{
53+
Name = parameterVersionName.ToString(),
54+
Disabled = true
55+
},
56+
UpdateMask = new FieldMask
57+
{
58+
Paths = { "disabled" }
59+
}
60+
};
61+
62+
// Call the API to update (disable) the parameter version.
63+
ParameterVersion updatedParameterVersion = client.UpdateParameterVersion(request);
64+
65+
Console.WriteLine($"Disabled regional parameter version {versionId} for parameter {parameterId}");
66+
67+
return updatedParameterVersion;
68+
}
69+
}
70+
// [END parametermanager_disable_regional_param_version]

0 commit comments

Comments
 (0)