Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and adheres to a project-specific [Versioning](/README.md).

## [Unreleased]

### Added

- Added new overload for `AddGoogleSecrets` to allow passing `GoogleSecretsOptions`.

## [1.4.0] - 2025-03-18

### Added
Expand Down
15 changes: 0 additions & 15 deletions GoogleSecrets/ConfigurationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ public static class ConfigurationBuilderExtensions
/// <exception cref="System.ArgumentNullException">options</exception>
public static IConfigurationBuilder AddGoogleSecrets(this IConfigurationBuilder configuration)
{
// Configure app configuration to add Google Secrets if environment variable is set
var googleSecretProject = Environment.GetEnvironmentVariable(EnvironmentVariableNames.GoogleSecretsProject);
if (!string.IsNullOrWhiteSpace(googleSecretProject))
{
return AddGoogleSecrets(configuration, options =>
{
options.ProjectName = googleSecretProject;
});
}

return AddGoogleSecrets(configuration, _ => { });
}

Expand All @@ -45,11 +35,6 @@ public static IConfigurationBuilder AddGoogleSecrets(this IConfigurationBuilder
var googleSecretsOptions = new GoogleSecretsOptions();
options(googleSecretsOptions);

if (string.IsNullOrWhiteSpace(googleSecretsOptions.ProjectName))
{
throw new ArgumentNullException(nameof(googleSecretsOptions.ProjectName));
}

configuration.Add(new GoogleSecretsSource(googleSecretsOptions, configuration.Build()));

return configuration;
Expand Down
2 changes: 1 addition & 1 deletion GoogleSecrets/GoogleSecretsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class GoogleSecretsOptions
/// <value>
/// The name of the project or the numeric project id
/// </value>
public string ProjectName { get; set; }
public string ProjectName { get; set; } = Environment.GetEnvironmentVariable(EnvironmentVariableNames.GoogleSecretsProject) ?? string.Empty;

/// <summary>
/// Gets or sets the filter.
Expand Down
6 changes: 6 additions & 0 deletions GoogleSecrets/GoogleSecretsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public override void Load()
{
try
{
if (string.IsNullOrWhiteSpace(this.Source.ProjectName))
{
this.logger.LogWarning("ProjectName is not set. Skipping Google Secrets Provider.");
return;
}

// Create client
SecretManagerServiceClient secretManagerServiceClient = SecretManagerServiceClient.Create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ public static void AddGoogleSecrets(this WebApplicationBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);

// Configure app configuration to add Google Secrets if environment variable is set
var googleSecretProject = Environment.GetEnvironmentVariable(EnvironmentVariableNames.GoogleSecretsProject);
if (!string.IsNullOrWhiteSpace(googleSecretProject))
{
builder.Configuration.AddGoogleSecrets(options =>
{
options.ProjectName = googleSecretProject;
});
}
builder.Configuration.AddGoogleSecrets(_ => { });
}

/// <summary>
/// Adds the Google secrets to the <see cref="WebApplicationBuilder"/>.
/// </summary>
/// <param name="builder"></param>
/// <param name="googleSecretsOptions"></param>
public static void AddGoogleSecrets(this WebApplicationBuilder builder, Action<GoogleSecretsOptions> googleSecretsOptions)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(googleSecretsOptions);

builder.Configuration.AddGoogleSecrets(googleSecretsOptions);
}
}
}