Skip to content

Commit 1fccc01

Browse files
authored
Fix issues with GoogleSecret syntax and version parsing (#13)
This pull request fixes two issues with the `GoogleSecret:SecretName:SecretVersion` syntax and version parsing in the `GoogleSecretsProvider.cs` file. The code now uses a regular expression to match the secret name and version, and removes the `}` character from the version before calling the Google API.
1 parent 72e2821 commit 1fccc01

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and adheres to a project-specific [Versioning](/README.md).
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed an issue where the `GoogleSecret:SecretName:SecretVersion` syntax was not working as expected. Instead of using a starts with comparison, the code now uses a regular expression to match the secret name and version.
13+
- Fixed an issue where the `GoogleSecret:SecretName:SecretVersion` syntax was not working as expected. The version was parsed including the `}` character. The code now removes the `}` character from the version before calling the google api.
14+
1015
## [1.3.0] - 2024-03-12
1116

1217
### Added

GoogleSecrets/GoogleSecretsProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Net.WebSockets;
7+
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
89
using Google.Api.Gax;
910
using Google.Api.Gax.ResourceNames;
@@ -108,15 +109,16 @@ void ScanExistingConfiguration(SecretManagerServiceClient secretManagerServiceCl
108109
{
109110
var existingKeyValues = this.existingConfiguration.AsEnumerable();
110111
// value will be in the format of {GoogleSecret:SecretName} or {GoogleSecret:SecretName:Version}
111-
var keyValuesToReplace = existingKeyValues.Where(x => x.Value?.StartsWith($"{{GoogleSecret:{secret.SecretName.SecretId}") == true);
112+
var regex = new Regex($@"\{{GoogleSecret:{secret.SecretName.SecretId}(?::(\w+))?}}");
113+
var keyValuesToReplace = existingKeyValues.Where(x => !string.IsNullOrWhiteSpace(x.Value) && regex.IsMatch(x.Value));
112114

113115
foreach (var keyValue in keyValuesToReplace)
114116
{
115117
var replaceParams = keyValue.Value.Split(':');
116118
string version = "latest";
117119
if (replaceParams.Length >= 3)
118120
{
119-
version = replaceParams[2];
121+
version = replaceParams[2].Substring(0, replaceParams[2].Length - 1);
120122
}
121123

122124
SetSecretValue(secretManagerServiceClient, secret, keyValue.Key, version);

0 commit comments

Comments
 (0)