This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ✨ add ConfigurationManager
#309
Open
erectfully
wants to merge
1
commit into
main
Choose a base branch
from
305-add-configuraton-management-abstraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Configuration | ||
|
|
||
| `Configurator` will look for application configuration files, then will | ||
| search environment variables and at the end if environment variables | ||
| provided external secret providers will hit them up for secrets. | ||
| If the configuration wasn't satisfied, error will be thrown. | ||
|
|
||
| - Environment Variables | ||
| - Configuration Files | ||
| - Command Line Arguments | ||
| - Externalized configuration providers | ||
|
|
||
| ## RC-like Configuration | ||
|
|
||
| Application always will take command-line parameters as the highest priority, | ||
| then environment variables, then configuration files. | ||
| However, if the external configuration provider is available by configuration | ||
| software such as Consul, Vault, or any other, it'll be used as the highest | ||
| priority once the application will connect to it. | ||
|
|
||
| ## Configuration File Resolution | ||
|
|
||
| // TODO: ... | ||
|
|
||
| ## Configuration File Format | ||
|
|
||
| - json | ||
| - yaml | ||
| - toml | ||
| - xml | ||
| - ini | ||
| - hcl | ||
| - properties | ||
| - dotenv | ||
| - env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
apps/server/src/core/configuration/configuration-manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // | ||
| //One secure mechanism for handling secrets in Node.js is using a library or implementing a Secret Manager approach as previously discussed, along with some additional best practices. | ||
| // | ||
| //1. Leverage a library: Utilize a secure library such as `dotenv` or `env-var` for handling environment variables, or `node-secret-loader` for loading secrets from environment variables or files. These libraries provide better safety and abstraction in handling secrets. | ||
| // | ||
| //2. Encryption: Use encryption to protect secrets, especially when they're stored in configuration files or in a secure environment variable storage service like HashiCorp Vault. This prevents the secrets from being visible to anyone who gains access to the server's file system. | ||
| // | ||
| //3. Secure the environment variables storage: Store your secrets in environment variables rather than in your code, but be careful about where these environment variables are stored. Do not hard-code them directly in the source code. Instead, consider using tools like `dotenv`, which let you store environment variables in a `.env` file and load them only in development and testing environments. | ||
| // | ||
| //4. Use a configuration management tool: Employ a configuration management tool like `Fig` or `Kelsey Hightower's envconfig` that can help you manage and securely store secrets and configuration data. These tools can also ensure that secrets are only available to the specific services that need them. | ||
| // | ||
| //5. Limit access: Restrict access to secrets by using process isolation (like containers) or user permissions. This way, even if an attacker gains access to one process, they won't necessarily have access to secrets stored in other processes. | ||
| // | ||
| //6. Audit and monitor: Log any access to secrets, and monitor for unusual or unauthorized activity. This helps you detect if there have been breaches, and enables you to respond quickly. | ||
| // | ||
| //7. Regularly rotate secrets: Periodically rotate sensitive secrets, especially those used for authentication and cryptographic purposes, to limit the potential damage caused by a possible compromise. | ||
| // | ||
| // By following these best practices, you can significantly improve the security of handling secrets in Node.js applications. | ||
|
|
||
|
|
||
|
|
||
| export interface HttpServerConfiguration { | ||
| port: number | ||
| host: string | ||
| protocol: "http" | "https" | ||
| } | ||
|
|
||
| export interface Configuration { | ||
| environment: "production" | "staging" | "testing" | "development" | "local" | ||
| http: HttpServerConfiguration | ||
| cacheMechanism: "redis" | "memcached" | "memory" | ||
| } | ||
|
|
||
|
|
||
| type ConfigType<K extends keyof Configuration> = K extends "http" ? HttpConfig : never; | ||
|
|
||
| type HttpConfig = { | ||
| port: number; host: string; protocol: "http" | "https"; | ||
| }; | ||
|
|
||
|
|
||
| export interface ConfigurationLoader { | ||
| load(): Promise<Partial<Configuration>> | ||
| } | ||
|
|
||
|
|
||
| export class DotEnvConfigurationLoader implements ConfigurationLoader { | ||
| async load(): Promise<Partial<Configuration>> { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
|
|
||
| export class RcLoader implements ConfigurationLoader { | ||
| async load(): Promise<Partial<Configuration>> { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
| export class ConfigCatLoader implements ConfigurationLoader { | ||
| async load(): Promise<Partial<Configuration>> { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** Configuration Manager is a core service that's responsible for managing the configuration of the application. | ||
| * It's important to notice this class isn't intended to handle secrets themselves as they shouldn't be persisted | ||
| * or available in selected methods. | ||
| * For the secure operations, there's a secret manager that handles these values in a safe way. */ | ||
| export class ConfigurationManager { | ||
| private readonly loaders: ConfigurationLoader[] = [] | ||
|
|
||
|
|
||
| /// Loads configuration from specified sources | ||
| async load(): Promise<void> { | ||
| return Promise.resolve() | ||
| } | ||
|
|
||
|
|
||
| async get<K extends keyof Configuration>(key: K): Promise<Configuration[K]> { | ||
| return Promise.resolve({} as any) | ||
| } | ||
|
|
||
| async set<K extends keyof Configuration>(key: K, value: Configuration[K]): Promise<void> { | ||
| return Promise.resolve() | ||
| } | ||
|
|
||
| async reset(): Promise<void> { | ||
| return Promise.resolve() | ||
| } | ||
| } | ||
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| # Autopilot | ||
|
|
||
| ## Introduction | ||
|
|
||
| This is a simplified implementation for server autopilot - | ||
| an server that's able to manage itself and automate maintained tasks such as running migrations, backups, and more. | ||
|
|
||
| ## Features | ||
|
|
||
| - `Automatic Migration`, once non-destructive migrations are added into stack server is able to manage them itself, and prepare a database once it'll connect to one. | ||
| - `Automatic Backup`, once backup is configured, server will be able to manage backups itself. | ||
| - `Automatic Restore`, once backup is configured, server will be able to manage restores itself. |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.