Skip to content

.Net Core Configuration Provider that allows developers to use Google Cloud Firestore as a Configuration Source in their applications including support for secrets stored in Google Cloud SecretManager.

License

Notifications You must be signed in to change notification settings

hectorescalante/googlecloud-extensions-configuration-firestore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoogleCloud.Extensions.Configuration.Firestore

.Net Core Configuration Provider that allows developers to use Google Cloud Firestore as a Configuration Source in their applications including support for secrets stored in Google Cloud SecretManager.

Build status

FirestoreOptions

Setting Default Value Description
FIRESTORECONFIG_ENABLED true Enable or disable configuration load
FIRESTORECONFIG_PROJECTID "" The google cloud project identifier where the firestore service exists
FIRESTORECONFIG_APPLICATION AppDomain.CurrentDomain.FriendlyName Name of the application
FIRESTORECONFIG_STAGE ASPNETCORE_ENVIRONMENT Name of the current environment
FIRESTORECONFIG_TAG "Default" Useful for application versioning, blue-green deployment or any other stage subclassification

Add Firestore Configuration in Program class

  public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostContext, config) =>
            {
              config.AddFirestoreConfiguration();
            })            
            .ConfigureWebHostDefaults(webBuilder =>
            {
              webBuilder.UseStartup<Startup>();
            });
  }

Automatic Settings Upload

For the first time, this package automatically load the appsettings.json file into a Firestore Document named as the application.

Also a Stages collection will be created with an empty Document named as the current environment.

Change Detection

The provider will be listening for changes in these documents:

  1. ApplicationSettings/{applicationName}
  2. ApplicationSettings/{applicationName}/Stages/{stageName}
  3. ApplicationSettings/{applicationName}/Stages/{stageName}/Tags/{tag}

When a change is made in any document, the provider reload the configuration from general to particular (Application -> Stage -> Tag).

Usage

Since the settings are loaded from Firestore into the Application Configuration they will be available through the IConfiguration interface at Startup, just like the settings declared in environment variables or appsettings.json file.

Secrets

If any setting has a value begining with 'secret:' then this package will try to resolve the secret value from Google Cloud Secret Manager.

The value should have this structure: secret:projectId:secretName:secretVersion

Alternatively support this structure: secret::secretName where the projectId is the same as the Firestore service and the secretVersion is "latest".

Google Application Credential

Permission Roles

  • Firestore: Cloud Datastore User
  • SecretManager: Secret Manager Secret Accessor

Wait for complete load

In some scenarios you need to access a configuration value inmediately but the remote nature of this provider takes a bit more time than the local settings providers.

You could use the IConfiguration extension method WaitForFirestoreLoad to wait for complete configuration loading:

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        Configuration.WaitForFirestoreLoad();
        ...
    }

About

.Net Core Configuration Provider that allows developers to use Google Cloud Firestore as a Configuration Source in their applications including support for secrets stored in Google Cloud SecretManager.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages