summaryrefslogtreecommitdiff
path: root/posts/pwutil.md
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-08-03 17:43:40 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-08-03 17:43:40 +0200
commit52b67951f1e8a7f1af9b85d4ae8e7689d194574a (patch)
tree88076113c7020e8483e5f47afa618d6449034f7e /posts/pwutil.md
parent230688a0b842cf57b316a7ba62910ca387afbce7 (diff)
downloaddirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.gz
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.bz2
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.xz
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.zip
Working prototype in hakyll
Diffstat (limited to 'posts/pwutil.md')
-rw-r--r--posts/pwutil.md119
1 files changed, 0 insertions, 119 deletions
diff --git a/posts/pwutil.md b/posts/pwutil.md
deleted file mode 100644
index 176ffdc..0000000
--- a/posts/pwutil.md
+++ /dev/null
@@ -1,119 +0,0 @@
1% A Tool to Manage a Set of YAML Objects Representing Account Information — pwutil
2
3A long time ago I wrote a bunch of scripts (first in bash, then zsh, and later perl) to manage a, sometimes encrypted, file containing account information I get asked to create and remember on a daily basis—accounts for shopping websites spring to mind.
4
5[pwutil](git://git.yggdrasil.li/pwutil) is the newest iteration in this line of bunches of scripts.
6
7## Features
8
9 * Support for embedding common operation in any kind of record keeping
10
11 Thus support for almost any encryption known to man (with absolutely no online security), version control, and synchronisation
12 * [Human read- and writeable](https://en.wikipedia.org/wiki/YAML) backstore
13 * Machine parseable output
14 * [Command Line Interface](https://en.wikipedia.org/wiki/Command-line_interface)-only
15 * New accounts can be partially generated by user defined functions with out of the box support for [pwgen](http://sourceforge.net/projects/pwgen/) and SSH
16
17## Usage
18
19~~~
20pwget [<searchTerm> …]
21Looks up and returns all accounts which contain any <searchTerm> anywhere in their representation — case insensitive.
22
23pwadd [[--gen-<generator> [<generatorArgument> …] …] --] <identifier> [<attributeKey> <attributeValue> …]
24Adds an account to the store — does not overwrite.
25~~~
26
27## Documentation
28
29I shall document the project in a partial and file-wise fashion—amendments available on request.
30
31### Structure
32
33~~~ {#DirTree}
34pwutil
35├── default.nix
36├── PWAdd.hs
37├── PWGet.hs
38├── PWUtil
39│   ├── Extra
40│   │   ├── PWGen.hs
41│   │   └── SSHCmd.hs
42│   ├── Types.hs
43│   └── Util.hs
44├── pwutil.hs
45├── PWUtil.hs
46└── pwutil.nix
47~~~
48
49### `pwutil.nix`
50is a [nix](https://nixos.org/nix) expression allowing easy installation using the nix package manager.
51A `~/.nixpkgs/config.nix` allowing one to do so might look thus:
52
53~~~ {.numberLines}
54{
55 packageOverrides = pkgs: {
56 pwutil = pkgs.callPackage /path/to/pwutil.nix {};
57 };
58}
59~~~
60
61The derivation takes some arguments (write those in `{}` above):
62
63`main ? null`
64 ~ Overwrite `pwutil.hs` with a file path
65
66`with<Package> ? false`
67 ~ `<Package>` is one of Pwgen, or Ssh a the current time.
68 If `true` wraps executables to have `$PATH` include `<Package>`.
69
70### `Types.hs`
71
72Introducing `PW` (much as [xmonad](https://xmonad.org) did with `X`) is an easy way to keep track of the `PWConfig` without resorting to function arguments.
73`BackStore` is our (new and improved) way of encapsulating store access in a totally customisable way—`plain`, which is essential `readFile` and `writeFile` as provided by `ByteString`, is provided for convenience in `Util.hs`.
74`PWConfig` most importantly contains a definition of generators (called by passing `--gen-…` to `pwadd`).
75
76~~~ {#Types.hs .haskell .numberLines}
77module PWUtil.Types (
78 PW(..),
79 BackStore(..),
80 PWConfig(..),
81 Generator(..)
82 ) where
83
84import Control.Monad.State
85import qualified Data.Map as M
86import Data.Yaml
87import Data.ByteString
88
89type PW = StateT PWConfig IO
90
91data BackStore = BackStore
92 { readContents :: PW ByteString
93 , writeContents :: ByteString -> PW ()
94 }
95
96data PWConfig = PWConfig
97 { generators :: M.Map String Generator
98 , backstore :: BackStore
99 }
100
101type Generator = [String] -> PW Value
102~~~
103
104
105### `pwutil.hs`
106
107is, in a [xmonad](http://xmonad.org) kind of way, the configuration file—the shipped default is reproduced below as a template for custom configs.
108
109~~~ {#pwutil.hs .haskell .numberLines}
110import PWUtil
111
112import System.FilePath ((</>))
113import System.Directory (getHomeDirectory)
114
115main :: IO ()
116main = do
117 h <- getHomeDirectory
118 runPW (emptyConfig { backstore = plain (h </> "accounts.yaml") }) pwutil
119~~~