Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nialixus/env_reader
Read, encrypt, or generate environment variables from a .env file into an obfuscated Dart model.
https://github.com/nialixus/env_reader
dart dotenv env environment flutter
Last synced: 18 days ago
JSON representation
Read, encrypt, or generate environment variables from a .env file into an obfuscated Dart model.
- Host: GitHub
- URL: https://github.com/nialixus/env_reader
- Owner: Nialixus
- License: mit
- Created: 2023-08-25T10:39:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-09T11:27:42.000Z (about 1 year ago)
- Last Synced: 2024-12-02T15:12:16.809Z (20 days ago)
- Topics: dart, dotenv, env, environment, flutter
- Language: Dart
- Homepage:
- Size: 356 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Env Reader
Read, encrypt, or generate environment variables from .env file into an obfuscated Dart model.## Features ð
- **Automated Generation:** Transform your .env files into dynamic Dart models directly. No need to add annotation. âĻ
- **Seamless Integration:** Directly update your pubspec.yaml and .gitignore on command. No need manual labor. ð ïļ
- **Fortified Encryption:** Shield your precious .env configurations with an encryption. Say no to prying eyes.ð
- **Data Diversity Unleashed:** Whether they're integers, decimals, booleans, or strings. Automatic interpretation is at your service. ðŪ
- **Versatile Sourcing**: Load your .env from various sources: assets, files, memory, network, and strings. The choice is yours. ð## Install ð
Get started with these quick commands:ðĨ Add `env_reader` to your `pubspec.yaml` with a single line:
```bash
dart pub add env_reader
```
âĻ Unlock the magic by activating the `env_reader` CLI:
```bash
dart pub global activate env_reader
```## Usage ð
Now elevate your development experience with these straightforward steps:### 1. Set up your configuration
Start by crafting your `.env` file in the root directory of your project, right alongside your trusty `pubspec.yaml`.
```env
API_KEY=VYIUJ7tLdJFqrBesnOJEpkbceBB5GNz0t1aYgHxK3BMxbJOc/g==
DEBUG=true
PORT=8080
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
```
---### 2. Run the command (Optional)
Now, if you want to generate encrypted env file, run this command in your terminal:
```bash
env_reader --input=".env" --output="assets/env/" --key="MyOptionalSecretKey"
```
> [!NOTE]
> **`output:`** .env successfully encrypted into assets/env/.env ðalso if you want to generate dart model from this env file, use tihs:
```bash
env_reader --input-".env" --model="lib/src/env_model.dart" --null-safety
```
> [!NOTE]
> **`output:`** .env successfully generated into lib/src/env_model.dart ð
---### 3. Loading your .env
Load the env_reader instance:
```dart
import 'package:env_reader/env_reader.dart';
import 'package:flutter/services.dart';await Env.load(
EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
"MyOptionalSecretKey");// Or you can load by creating your own `EnvReader` instance.
EnvReader production = EnvReader();
await production.load(
EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
"MyOptionalSecretKey");
```
---### 4. Access your configuration
To get and read the value of your env:
```dart
import 'package:env_reader/env_reader.dart';
import 'package:my_package/src/env_model.dart';String api = Env.read("API_KEY") ?? "Got'cha ð";
bool debug = Env.read("DEBUG") ?? false;// If you make your own instance, call it like this
String api = production.read("API_KEY") ?? "Got'cha ð";
bool debug = production.read("DEBUG") ?? false;Text(
text:
debug ? "ðĪŦ pssst, this is my api key y'all \n\n $api" : "Nothing to see here ðĪŠ",
);// Or you can access the value directly from env generated model earlier
Text(
text:
EnvModel.debug ? "ðĪŦ pssst, this is my api key y'all \n\n ${EnvModel.apiKey}" : "Nothing to see here ðĪŠ",
);
```
---## Env Reader Command ð
Available commands:| Flag | Description |
|--------------------------|--------------------------------------------------------------|
| -i, --input (mandatory) | Input path of the .env file |
| -o, --output | Output path for the encrypted .env file |
| -s, --key | Secrey key for encryption & decryption |
| --model | Generate dart model file to your desired file path |
| --null-safety | Make the model null safety |
| --[no-]obfuscate | Obfuscating generated values of model |
| | (defaults to on) |
| --[no-]pubspec | Insert asset path to pubspec.yaml |
| | (defaults to on) |
| --[no-]gitignore | Insert .env input & output file into .gitignore |
| | (defaults to on) |
| -h, --help | Print usage information |Example usage:
```bash
env_reader -i ".env" -o "assets/env/" -s "MyOptionalSecretKey" --model="lib/src/env_model.dart" --null-safety
```## Example ð