env_reader는 .env 파일에서 환경 변수를 읽거나 암호화하거나 생성함으로써 환경 변수를 안전하게 처리할 수 있도록 해주는 Dart 패키지입니다. 이러한 변수들을 오브스큐레이트된 Dart 모델로 변환하여 민감한 데이터 노출을 방지하고 보안을 강화합니다. Android, iOS, Web, macOS, Windows, Linux 등 다양한 플랫폼에서 사용 가능하며, 간단한 pub add 명령어를 통해 Flutter 프로젝트에 쉽게 통합할 수 있습니다. 생산 및 개발 환경에서 구성 보안을 우선시하는 개발자에게 이상적입니다.
사용 사례
API 키를 안전하게 관리하기
데이터베이스 자격 증명 보호
CI/CD 파이프라인에서 앱 시크릿 처리
암호화된 구성 파일 사용
환경 설정을 안전하게 공유하기
환경 변수 생성 자동화
주요 기능
.env 파일을 안전하게 읽습니다
환경 변수 암호화
오브스큐레이트된 Dart 모델을 생성합니다
다중 플랫폼 배포를 지원합니다
pub를 통한 간편한 통합 제공
암호화 및 복호화 유틸리티 제공
적합한 대상
앱 보안에 집중하는 개발자
환경 기반 구성 사용 팀
비밀 관리가 필요한 프로젝트
민감한 데이터를 포함한 Flutter 앱
보안 환경 처리가 필요한 CI/CD 워크플로
다중 플랫폼에 배포되는 앱
고려 사항
적절한 암호화 키 관리가 필요합니다
초기 설정은 구성 단계를 포함합니다
난독화는 완전한 암호화를 대체하지 않습니다
매우 동적인 런타임 비밀에 적합하지 않음
외부 .env 파일의 존재에 의존합니다
추가 빌드 프로세스 단계가 필요할 수 있습니다
원본 README
연결된 소스 저장소의 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:
dart pub add env_reader
✨ Unlock the magic by activating the env_reader CLI:
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.
[!NOTE]
output: .env successfully generated into lib/src/env_model.dart 🎉
3. Loading your .env
Load the env_reader instance:
import'package:env_reader/env_reader.dart';
import'package:flutter/services.dart';
awaitEnv.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:
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<bool>("DEBUG") ?? false;
// If you make your own instance, call it like thisString api = production.read("API_KEY") ?? "Got'cha 😎";
bool debug = production.read<bool>("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 earlierText(
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