パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.0

env_reader

.env ファイルから環境変数を読み取り、暗号化するか生成し、オブフスケートされた Dart モデルに格納します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
82
いいね数
23
Pub ポイント
140

パッケージをインストール

flutter pub add env_reader

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

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.

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:

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:

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:

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:

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 this

String 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 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:

env_reader -i ".env" -o "assets/env/" -s "MyOptionalSecretKey" --model="lib/src/env_model.dart" --null-safety

Example 🚀

カテゴリー

依存関係

依存関係一覧 3 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。