keychain 0.0.5 copy "keychain: ^0.0.5" to clipboard
keychain: ^0.0.5 copied to clipboard

outdated

Utility to store and retrieve environment variables.

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

/home/path/to/project/secrets/keys.json

{
  "object": {
    "key": "aJsonVar"
  }
}

/home/path/to/project/lib/bin/main.dart

import "package:keychain/keychain.dart"

class Keys extends Keychain {

  final String str = Keychain.fromString('aString');
  final String env = Keychain.fromEnv('ENV_VAR');
  final String json = Keychain.fromJsonFile('key', 'project/secrets/keys.json');

}

void main() {
  var keys = Keys();
  print(keys.str); // aString
  print(keys.env); // anEnvVar
  print(keys.json); // aJsonVar
}

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).

KeychainLight does not import dart:io but therefore only supports String keys currently. To use KeychainLight:

import 'package:keychain/keychain_light.dart'

class Keys extends KeychainLight {
  final String str = KeychainLight.fromString('aString');
}

void main() {
  var keys = Keys();
  print(keys.str); // aString
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Utility to store and retrieve environment variables.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

bottom_line

More

Packages that depend on keychain