Last updated:
0 purchases
keychain
keychain #
A simple class that can be extended to create a type safe, cached store for passwords, api keys, etc.
The first time an extended Keychain class is initiated, the keys are obtained based on how they are created and then cached for future instances of the extended Keychain class.
This package uses dart:io and is intended for command line / server applications although there is a KeychainLight class that currently only supports String keys (see below).
shell (set an environment variable)
ENV_VAR=anEnvVar
copied to clipboard
/home/path/to/project/secrets/keys.json
{
"object": {
"key": "aJsonVar"
}
}
copied to clipboard
project/lib/secrets/keys.json
{
"object": {
"anotherKey": "anotherJsonVar"
}
}
copied to clipboard
/home/path/to/project/lib/bin/main.dart
import "package:keychain/keychain.dart"
class Keys extends Keychain {
final String env = Keychain.fromEnv('ENV_VAR');
final String json = Keychain.fromJsonFile('key', 'project/secrets/keys.json');
final Future<String> resource = Keychain.fromJsonResource('anotherKey', 'package:this_package/secrets/keys.json');
}
void main() {
var keys = Keys();
print(keys.env); // anEnvVar
print(keys.json); // aJsonVar
print(await keys.resource); // anotherJsonVar
}
copied to clipboard
The path for a json file must start with a directory on the path to the running script. For example, if the script is at /home/path/to/project/lib/bin/main.dart, you should put the json file somewhere along this path such as /home/path/to/project/secrets/keys.json (there needs to be one overlapping directory). This file can then be included in the extended class as in the example above ('project/secrets/keys.json' -> project is the overlapping directory).
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.