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

Utility to cache environment and file 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"
  }
}

project/lib/secrets/keys.json

{
  "object": {
    "anotherKey": "anotherJsonVar"
  }
}

/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
}

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

0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Utility to cache environment and file variables.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

resource

More

Packages that depend on keychain