sym 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -3
- data/README.md +20 -10
- data/bin/sym.completion +6 -7
- data/bin/sym.symit +245 -0
- data/lib/sym/app/cli_slop.rb +31 -22
- data/lib/sym/app/commands/bash_completion.rb +21 -32
- data/lib/sym/app/commands/keychain_add_key.rb +1 -1
- data/lib/sym/app/commands/password_protect_key.rb +1 -1
- data/lib/sym/app/commands/print_key.rb +1 -1
- data/lib/sym/constants.rb +14 -10
- data/lib/sym/version.rb +1 -1
- metadata +3 -4
- data/exe/symit +0 -168
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6862ecd0c07b12c1ee20a9d2f2bb070bf8912656
|
|
4
|
+
data.tar.gz: 98edcee0cd5c47c876cd002841b7aa1bff420bee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97c4215175e2afd0ad94f01069cfab3690a2d50c1e9603ea9d6f956becaba8f969fdbaf173326815ab3f88630b9a58702c8d23d40f1c98f032982f5e57faf8d2
|
|
7
|
+
data.tar.gz: ce41e1adb186a492eef492e5d9e6699987fbeab95f0a4ee8271c2fe75a98654374633c33ae7fa11c6b1aa41f0072ede88b619126210ca3e4c7f82e692f481482
|
data/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## [HEAD](https://github.com/kigster/sym/tree/HEAD)
|
|
4
4
|
|
|
5
|
-
[Changes since the last tag](https://github.com/kigster/sym/compare/v2.5.
|
|
5
|
+
[Changes since the last tag](https://github.com/kigster/sym/compare/v2.5.1...HEAD)
|
|
6
6
|
|
|
7
|
-
## [v2.5.
|
|
7
|
+
## [v2.5.1](https://github.com/kigster/sym/tree/v2.5.0) (2017-03-06)
|
|
8
|
+
[Full Changelog](https://github.com/kigster/sym/compare/v2.5.0...v2.5.1)
|
|
9
|
+
|
|
10
|
+
* Moved `symit` into `bin/` folder, and now installing it into `~/.sym.symit` with `-B/--bash-support` flag.
|
|
11
|
+
* `symit` now works as a bash function installed together with the completion.
|
|
12
|
+
* Updated `Sym::Constants` module.
|
|
13
|
+
|
|
14
|
+
## [v2.5.0](https://github.com/kigster/sym/tree/v2.5.0) (2017-03-04)
|
|
8
15
|
[Full Changelog](https://github.com/kigster/sym/compare/v2.4.3...v2.5.0)
|
|
9
16
|
|
|
10
17
|
* Updated README
|
|
@@ -15,7 +22,7 @@
|
|
|
15
22
|
* Reworked `Sym::Application`, removed `--dictionary`, and simplified argument parsing.
|
|
16
23
|
* Refactored `output_proc` to live in `application`.
|
|
17
24
|
|
|
18
|
-
## [v2.4.2](https://github.com/kigster/sym/tree/v2.4.2) (2017-
|
|
25
|
+
## [v2.4.2](https://github.com/kigster/sym/tree/v2.4.2) (2017-03-01)
|
|
19
26
|
[Full Changelog](https://github.com/kigster/sym/compare/v2.4.1...v2.4.2)
|
|
20
27
|
|
|
21
28
|
* Fixing BASH completion for sym to look for files after `--negate` and
|
data/README.md
CHANGED
|
@@ -136,7 +136,7 @@ __BASH Completion__
|
|
|
136
136
|
|
|
137
137
|
Optionally, after gem installation, you can also install bash-completion of gem's command line options, but running the following command (and feel free to use any of the "dot" files you prefer):
|
|
138
138
|
|
|
139
|
-
sym
|
|
139
|
+
sym -B/--bash-support ~/.bashrc
|
|
140
140
|
|
|
141
141
|
Should you choose to install it (this part is optional), you will be able to use "tab-tab" after typing `sym`, and you'll be able to choose from all of the supported flags.
|
|
142
142
|
|
|
@@ -274,35 +274,43 @@ sym -Atf file.enc
|
|
|
274
274
|
This may be a good time to take a look at the full help message for the `sym` tool, shown naturally with a `-h` or `--help` option.
|
|
275
275
|
|
|
276
276
|
```
|
|
277
|
-
Sym (2.5.
|
|
277
|
+
Sym (2.5.1) – encrypt/decrypt data with a private key
|
|
278
278
|
|
|
279
279
|
Usage:
|
|
280
280
|
# Generate a new key, optionally password protected, and save it
|
|
281
281
|
# in one of: keychain, file, or STDOUT (-q turns off STDOUT)
|
|
282
|
-
|
|
282
|
+
|
|
283
|
+
sym -g [ -p/--password ] [ -x keychain | -o file | ] [ -q ]
|
|
283
284
|
|
|
284
285
|
# To specify encryption key, provide the key as
|
|
285
286
|
# 1) a string, 2) a file path, 3) an OS-X Keychain, 4) env variable name
|
|
286
287
|
# 5) use -i to paste/type the key interactively
|
|
287
288
|
# 6) default key file (if present) at /Users/kig/.sym.key
|
|
289
|
+
|
|
288
290
|
KEY-SPEC = -k/--key [ key | file | keychain | environment_variable ]
|
|
289
291
|
-i/--interactive
|
|
290
292
|
|
|
291
293
|
# Encrypt/Decrypt from STDIN/file/args, to STDOUT/file:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
+
|
|
295
|
+
sym -e/--encrypt KEY-SPEC [-f [file | - ] | -s string ] [-o file]
|
|
296
|
+
sym -d/--decrypt KEY-SPEC [-f [file | - ] | -s string ] [-o file]
|
|
294
297
|
|
|
295
298
|
# Auto-detect mode based on a special file extension ".enc"
|
|
296
|
-
|
|
299
|
+
|
|
300
|
+
sym -n/--negate KEY-SPEC file[.enc]
|
|
297
301
|
|
|
298
302
|
# Edit an encrypted file in $EDITOR
|
|
299
|
-
|
|
303
|
+
|
|
304
|
+
sym -t/--edit KEY-SPEC -f file [ -b/--backup ]
|
|
300
305
|
|
|
301
306
|
# Save commonly used flags in a BASH variable. Below we save the KeyChain
|
|
302
307
|
# "staging" as the default key name, and enable password caching.
|
|
303
|
-
|
|
308
|
+
|
|
309
|
+
export SYM_ARGS="-ck staging"
|
|
310
|
+
|
|
304
311
|
# Then activate $SYM_ARGS by using -A/--sym-args flag:
|
|
305
|
-
|
|
312
|
+
|
|
313
|
+
sym -Aef file
|
|
306
314
|
|
|
307
315
|
Modes:
|
|
308
316
|
-e, --encrypt encrypt mode
|
|
@@ -341,11 +349,13 @@ Flags:
|
|
|
341
349
|
-A, --sym-args read more CLI arguments from $SYM_ARGS
|
|
342
350
|
|
|
343
351
|
Utility:
|
|
344
|
-
-B, --bash-
|
|
352
|
+
-B, --bash-support [file] append bash completion & utils to a file
|
|
353
|
+
such as ~/.bash_profile or ~/.bashrc
|
|
345
354
|
|
|
346
355
|
Help & Examples:
|
|
347
356
|
-E, --examples show several examples
|
|
348
357
|
-h, --help show help
|
|
358
|
+
|
|
349
359
|
```
|
|
350
360
|
|
|
351
361
|
### CLI Usage Examples
|
data/bin/sym.completion
CHANGED
|
@@ -16,7 +16,7 @@ for file in ${bash_completion_locations[@]}; do
|
|
|
16
16
|
done
|
|
17
17
|
|
|
18
18
|
_sym_long_opts() {
|
|
19
|
-
sym -h | grep -- '--' | egrep '^ -' | awk '{print $2}' | sort
|
|
19
|
+
sym -h | grep -- '--' | egrep '^ -' | awk '{print $2}' | sort
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
_sym_short_opts() {
|
|
@@ -49,12 +49,12 @@ _sym()
|
|
|
49
49
|
|
|
50
50
|
case "$cur" in
|
|
51
51
|
--*)
|
|
52
|
-
export
|
|
53
|
-
COMPREPLY=($( compgen -W "$
|
|
52
|
+
export _sym_comp_long_options=${_sym_comp_long_options:-$(_sym_long_opts)}
|
|
53
|
+
COMPREPLY=($( compgen -W "$_sym_comp_long_options" -- "$cur" ))
|
|
54
54
|
;;
|
|
55
55
|
-*)
|
|
56
|
-
export
|
|
57
|
-
COMPREPLY=($( compgen -W "$
|
|
56
|
+
export _sym_comp_short_options=${_sym_comp_short_options:-$(_sym_short_opts)}
|
|
57
|
+
COMPREPLY=($( compgen -W "$_sym_comp_short_options" -- "$cur" ))
|
|
58
58
|
;;
|
|
59
59
|
*)
|
|
60
60
|
_filedir
|
|
@@ -62,8 +62,7 @@ _sym()
|
|
|
62
62
|
esac
|
|
63
63
|
|
|
64
64
|
return 0
|
|
65
|
-
} &&
|
|
66
|
-
complete -F _sym $nospace $filenames sym
|
|
65
|
+
} && complete -F _sym $nospace $filenames sym
|
|
67
66
|
|
|
68
67
|
# Local variables:
|
|
69
68
|
# mode: shell-script
|
data/bin/sym.symit
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#==============================================================================
|
|
3
|
+
#
|
|
4
|
+
# (c) 2017 Konstantin Gredeskoul
|
|
5
|
+
# MIT License, distributed as part of `sym` ruby gem.
|
|
6
|
+
# https://github.com/kigster/sym
|
|
7
|
+
#
|
|
8
|
+
#==============================================================================
|
|
9
|
+
# Purpuse of this script is to transparently edit application secrets in a
|
|
10
|
+
# Rails app. It's a simple enough wrapper around sym.
|
|
11
|
+
#
|
|
12
|
+
# What the fuck?
|
|
13
|
+
#
|
|
14
|
+
# 1) This assumes you are storing application secrets in a file, say named,
|
|
15
|
+
# RAILS_ROOT/config/special/secrets/production.yml.enc
|
|
16
|
+
#
|
|
17
|
+
# 2) You want to be able to easily and transparently edit it with sym, without
|
|
18
|
+
# having to remember sym's CLI.
|
|
19
|
+
#
|
|
20
|
+
# 3) You may want to have a search paths to look for the file in...
|
|
21
|
+
#
|
|
22
|
+
# 4) You may want to override the file extension assumed (instead of .yml.enc).
|
|
23
|
+
#
|
|
24
|
+
# SO: here is what you do:
|
|
25
|
+
#
|
|
26
|
+
# export sym__ext="json.enc"
|
|
27
|
+
# export sym__folder="config/special/secrets"
|
|
28
|
+
# export sym__key="application-key"
|
|
29
|
+
#
|
|
30
|
+
# And then
|
|
31
|
+
#
|
|
32
|
+
# symit production
|
|
33
|
+
#
|
|
34
|
+
# ...and vola! You are editing the encrypted file with sym from the root of
|
|
35
|
+
# your Rails application. Neat, no?
|
|
36
|
+
#
|
|
37
|
+
symit::init() {
|
|
38
|
+
[[ -z "${sym__ext}" ]] && export sym__ext="yml.enc"
|
|
39
|
+
[[ -z "${sym__folder}" ]] && export sym__folder="config/settings/secrets"
|
|
40
|
+
|
|
41
|
+
export true=1
|
|
42
|
+
export false=0
|
|
43
|
+
|
|
44
|
+
export txtrst='\e[0m' # Text Reset
|
|
45
|
+
export bldred='\e[1;31m' # Red
|
|
46
|
+
export bldgrn='\e[1;32m' # Green
|
|
47
|
+
export bldylw='\e[1;33m' # Yellow
|
|
48
|
+
export bldblu='\e[1;34m' # Blue
|
|
49
|
+
|
|
50
|
+
unset cli__opts
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
symit::usage() {
|
|
54
|
+
printf "${bldblu}symit: ${txtrst}edit an encrypted file using configuration from environment\n\n"
|
|
55
|
+
|
|
56
|
+
printf " Usage: ${bldgrn}symit ${bldylw}[file-spec] [options]${txtrst}\n\n"
|
|
57
|
+
|
|
58
|
+
printf " Eg: To edit an encrypted file config/settings/secrets/development.yml.enc${txtrst}\n"
|
|
59
|
+
printf " ${bldgrn}symit${bldylw} development${txtrst}\n\n"
|
|
60
|
+
|
|
61
|
+
printf "options: \n"
|
|
62
|
+
printf " -k | --key [key-spec] Pass an alternative key, other than ${sym__key}\n"
|
|
63
|
+
printf " -x | --extension [extension] Use extension other than ${bldylw}${sym__ext}${txtrst}\n"
|
|
64
|
+
printf " -l | --locations Print search locations for [file-spec]\n"
|
|
65
|
+
printf " -i | --install Install the latest version of ${bldylw}sym${txtrst}\n"
|
|
66
|
+
printf " -h | --help Show this help message\n"
|
|
67
|
+
printf " -n | --dry-run Show the generated sym command\n\n"
|
|
68
|
+
|
|
69
|
+
printf "configuration:
|
|
70
|
+
|
|
71
|
+
export sym__ext=yml.enc
|
|
72
|
+
export sym__folder=config/special/secrets
|
|
73
|
+
export sym__key=my-encryption-key
|
|
74
|
+
|
|
75
|
+
And then, eg from RAILS_ROOT of your app:
|
|
76
|
+
|
|
77
|
+
${bldgrn}symit production${txtrst}\n\n"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
symit::error() {
|
|
81
|
+
printf "${bldred}error: $* ${bldylw}\n\n"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
symit::install() {
|
|
85
|
+
if [[ -z "${_symit__installed}" ]]; then
|
|
86
|
+
current_version=$(gem list | grep sym | awk '{print $2}' | sed 's/(//g;s/)//g')
|
|
87
|
+
if [[ -z "${current_version}" ]]; then
|
|
88
|
+
gem install sym
|
|
89
|
+
else
|
|
90
|
+
local help=$(sym -h 2>&1)
|
|
91
|
+
unset SYM_ARGS
|
|
92
|
+
remote_version=$(gem search sym | egrep '^sym \(' | awk '{print $2}' | sed 's/(//g;s/)//g')
|
|
93
|
+
if [[ "${remote_version}" != "${current_version}" ]]; then
|
|
94
|
+
printf "detected an older ${bldgrn}sym (${current_version}), installing ${bldgrn}sym (${remote_version})${txtrst}...\n"
|
|
95
|
+
echo y | gem uninstall sym -a 2>/dev/null
|
|
96
|
+
gem install sym
|
|
97
|
+
export _symit__installed="yes"
|
|
98
|
+
else
|
|
99
|
+
printf "${bldgrn}sym${txtrst} is on the latest version ${remote_version} already\n"
|
|
100
|
+
fi
|
|
101
|
+
fi
|
|
102
|
+
fi
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
symit::locs() {
|
|
106
|
+
if [[ -n ${encrypted_file} ]]; then
|
|
107
|
+
[[ -n ${cli__opts[extension]} ]] && export sym__ext=${cli__opts[extension]}
|
|
108
|
+
declare -a locations=("${sym__folder}/${encrypted_file}.${sym__ext}" "${sym__folder}/${encrypted_file}" "${encrypted_file}")
|
|
109
|
+
fi
|
|
110
|
+
echo -n ${locations[*]}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
symit::exit() {
|
|
114
|
+
code=${1:-0}
|
|
115
|
+
unset encrypted_file
|
|
116
|
+
unset cli__opts
|
|
117
|
+
unset locations
|
|
118
|
+
echo -n ${code}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
symit() {
|
|
122
|
+
[[ -n "${1}" && "${1:0:1}" != "-" ]] && {
|
|
123
|
+
export encrypted_file=$1
|
|
124
|
+
shift
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
symit::init
|
|
128
|
+
|
|
129
|
+
declare -A cli__opts=(
|
|
130
|
+
[verbose]=${true}
|
|
131
|
+
[key]=${sym__key}
|
|
132
|
+
[extension]=${sym__ext}
|
|
133
|
+
[dry_run]=${false}
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
[[ -z ${encrypted_file} && -z $* ]] && symit::usage
|
|
137
|
+
|
|
138
|
+
while :; do
|
|
139
|
+
case $1 in
|
|
140
|
+
-h|-\?|--help)
|
|
141
|
+
shift
|
|
142
|
+
symit::usage
|
|
143
|
+
return $(symit::exit 0)
|
|
144
|
+
;;
|
|
145
|
+
|
|
146
|
+
-k|--key)
|
|
147
|
+
shift
|
|
148
|
+
if [[ -z $1 ]]; then
|
|
149
|
+
symit::error "-k/--key requires an argument" && return $(symit::exit 1)
|
|
150
|
+
else
|
|
151
|
+
cli__opts[key]=$1
|
|
152
|
+
shift
|
|
153
|
+
fi
|
|
154
|
+
;;
|
|
155
|
+
|
|
156
|
+
-x|--extension)
|
|
157
|
+
shift
|
|
158
|
+
if [[ -z $1 ]]; then
|
|
159
|
+
symit::error "-x/--extension requires an argument" && return $(symit::exit 1)
|
|
160
|
+
else
|
|
161
|
+
cli__opts[extension]=${1}
|
|
162
|
+
shift
|
|
163
|
+
fi
|
|
164
|
+
;;
|
|
165
|
+
|
|
166
|
+
-l|--locations)
|
|
167
|
+
shift
|
|
168
|
+
cli__opts[locations]=${true}
|
|
169
|
+
;;
|
|
170
|
+
|
|
171
|
+
-i|--install)
|
|
172
|
+
shift
|
|
173
|
+
symit::install
|
|
174
|
+
return $(symit::exit 0)
|
|
175
|
+
;;
|
|
176
|
+
|
|
177
|
+
-n|--dry-run)
|
|
178
|
+
shift
|
|
179
|
+
cli__opts[dry_run]=${true}
|
|
180
|
+
;;
|
|
181
|
+
|
|
182
|
+
--) # End of all options.
|
|
183
|
+
shift
|
|
184
|
+
break
|
|
185
|
+
;;
|
|
186
|
+
|
|
187
|
+
-?*)
|
|
188
|
+
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
|
|
189
|
+
return $(symit::exit 127)
|
|
190
|
+
shift
|
|
191
|
+
;;
|
|
192
|
+
|
|
193
|
+
*) # Default case: If no more options then break out of the loop.
|
|
194
|
+
break
|
|
195
|
+
shift
|
|
196
|
+
esac
|
|
197
|
+
done
|
|
198
|
+
|
|
199
|
+
declare -a locations=$(symit::locs)
|
|
200
|
+
|
|
201
|
+
if [[ ${cli__opts[locations]} == ${true} ]]; then
|
|
202
|
+
if [[ -z ${encrypted_file} ]]; then
|
|
203
|
+
symit::error "-l/--locations requires file-spec to be provided as the 1st argument"
|
|
204
|
+
return $(symit::exit 2)
|
|
205
|
+
fi
|
|
206
|
+
printf "search locations:\n"
|
|
207
|
+
for loc in ${locations[@]}; do
|
|
208
|
+
if [[ -n "${loc}" ]] ; then
|
|
209
|
+
printf "\t - ${loc}\n"
|
|
210
|
+
fi
|
|
211
|
+
done
|
|
212
|
+
return $(symit::exit 0)
|
|
213
|
+
fi
|
|
214
|
+
|
|
215
|
+
if [[ -z "${encrypted_file}" ]]; then
|
|
216
|
+
symit::error "Missing 1st argument — file name to be loaded, eg 'production', etc."
|
|
217
|
+
return $(symit::exit 3)
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
if [[ -z "${cli__opts[key]}" ]]; then
|
|
221
|
+
symit::error "Key was not defined, pass it with ${bldblu}-k key-spec${bldred} or set it via ${bldgrn}\$sym__key${bldred} variable."
|
|
222
|
+
return $(symit::exit 4)
|
|
223
|
+
fi
|
|
224
|
+
|
|
225
|
+
file=
|
|
226
|
+
for loc in ${locations[@]}; do
|
|
227
|
+
if [[ -s "${loc}" ]] ; then
|
|
228
|
+
file=${loc}
|
|
229
|
+
break
|
|
230
|
+
fi
|
|
231
|
+
done
|
|
232
|
+
|
|
233
|
+
[[ -z "${file}" ]] && {
|
|
234
|
+
symit::error "${encrypted_file} could not be found."
|
|
235
|
+
return $(symit::exit 5)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
command="sym -ck ${cli__opts[key]} -tf ${file}"
|
|
239
|
+
|
|
240
|
+
[[ ${cli_opts[dry_run]} ]] && printf "[dry_run] "
|
|
241
|
+
|
|
242
|
+
printf "${bldgrn}${command}${txtrst}\n"
|
|
243
|
+
|
|
244
|
+
[[ ${cli_opts[dry_run]} ]] || ${command}
|
|
245
|
+
}
|
data/lib/sym/app/cli_slop.rb
CHANGED
|
@@ -9,32 +9,40 @@ module Sym
|
|
|
9
9
|
|
|
10
10
|
o.banner = "Sym (#{Sym::VERSION}) – encrypt/decrypt data with a private key\n".bold.white
|
|
11
11
|
o.separator 'Usage:'.yellow
|
|
12
|
-
o.separator '
|
|
13
|
-
o.separator '
|
|
14
|
-
o.separator '
|
|
12
|
+
o.separator ' Generate a new key, optionally password protected, and save it'.dark
|
|
13
|
+
o.separator ' in one of: keychain, file, or STDOUT (-q turns off STDOUT) '.dark
|
|
14
|
+
o.separator ' '
|
|
15
|
+
o.separator ' sym -g '.green.bold + '[ -p/--password ] [-c] [-x keychain | -o file | ] [-q]'.green
|
|
15
16
|
o.separator ''
|
|
16
|
-
o.separator '
|
|
17
|
-
o.separator '
|
|
18
|
-
o.separator '
|
|
19
|
-
o.separator '
|
|
20
|
-
o.separator '
|
|
21
|
-
o.separator
|
|
17
|
+
o.separator ' To specify encryption key, provide the key as '.dark
|
|
18
|
+
o.separator ' 1) a string, 2) a file path, 3) an OS-X Keychain, 4) env variable name '.dark
|
|
19
|
+
o.separator ' 5) use -i to paste/type the key interactively'.dark
|
|
20
|
+
o.separator ' 6) default key file (if present) at '.dark + Sym.default_key_file.magenta.bold
|
|
21
|
+
o.separator ' '
|
|
22
|
+
o.separator ' ' + key_spec + ' = -k/--key [ key | file | keychain | env variable name ]'.green.bold
|
|
23
|
+
o.separator ' -i/--interactive'.green.bold
|
|
22
24
|
o.separator ''
|
|
23
|
-
o.separator '
|
|
24
|
-
o.separator '
|
|
25
|
-
o.separator '
|
|
25
|
+
o.separator ' Encrypt/Decrypt from STDIN/file/args, to STDOUT/file:'.dark
|
|
26
|
+
o.separator ' '
|
|
27
|
+
o.separator ' sym -e/--encrypt '.green.bold + key_spec + ' [-f [file | - ] | -s string ] [-o file] '.green
|
|
28
|
+
o.separator ' sym -d/--decrypt '.green.bold + key_spec + ' [-f [file | - ] | -s string ] [-o file] '.green
|
|
26
29
|
o.separator ''
|
|
27
|
-
o.separator '
|
|
28
|
-
o.separator '
|
|
30
|
+
o.separator ' Auto-detect mode based on a special file extension '.dark + '".enc"'.dark.bold
|
|
31
|
+
o.separator ' '
|
|
32
|
+
o.separator ' sym -n/--negate '.green.bold + key_spec + ' file[.enc] '.green
|
|
33
|
+
o.separator ' '
|
|
34
|
+
o.separator ' Edit an encrypted file in $EDITOR '.dark
|
|
35
|
+
o.separator ' '
|
|
36
|
+
o.separator ' sym -t/--edit '.green.bold + key_spec + ' -f file [ -b/--backup ]'.green.bold
|
|
37
|
+
o.separator ' '
|
|
38
|
+
o.separator ' Save commonly used flags in a BASH variable. Below we save the KeyChain '.dark
|
|
39
|
+
o.separator ' "staging" as the default key name, and enable password caching.'.dark
|
|
40
|
+
o.separator ' '
|
|
41
|
+
o.separator ' export SYM_ARGS="'.green + '-ck staging'.bold.green + '"'.green
|
|
29
42
|
o.separator ' '
|
|
30
|
-
o.separator '
|
|
31
|
-
o.separator ' sym -t/--edit '.green.bold + key_spec + ' -f file [ -b/--backup ]'.green.bold
|
|
43
|
+
o.separator ' Then activate $SYM_ARGS by using -A/--sym-args flag:'.dark
|
|
32
44
|
o.separator ' '
|
|
33
|
-
o.separator '
|
|
34
|
-
o.separator ' # "staging" as the default key name, and enable password caching.'.dark
|
|
35
|
-
o.separator ' export SYM_ARGS="'.green + '-ck staging'.bold.green + '"'.green
|
|
36
|
-
o.separator ' # Then activate $SYM_ARGS by using -A/--sym-args flag:'.dark
|
|
37
|
-
o.separator ' sym -Aef '.green.bold 'file'.green.bold
|
|
45
|
+
o.separator ' sym -Aef '.green.bold 'file'.green.bold
|
|
38
46
|
|
|
39
47
|
o.separator ' '
|
|
40
48
|
o.separator 'Modes:'.yellow
|
|
@@ -81,7 +89,8 @@ module Sym
|
|
|
81
89
|
|
|
82
90
|
o.separator ' '
|
|
83
91
|
o.separator 'Utility:'.yellow
|
|
84
|
-
o.string '-B', '--bash-
|
|
92
|
+
o.string '-B', '--bash-support', '[file]'.blue + ' append bash completion & utils to a file'+ "\n" +
|
|
93
|
+
' such as ~/.bash_profile or ~/.bashrc'
|
|
85
94
|
|
|
86
95
|
o.separator ' '
|
|
87
96
|
o.separator 'Help & Examples:'.yellow
|
|
@@ -4,50 +4,39 @@ module Sym
|
|
|
4
4
|
module Commands
|
|
5
5
|
class BashCompletion < BaseCommand
|
|
6
6
|
|
|
7
|
-
required_options [:
|
|
7
|
+
required_options [:bash_support]
|
|
8
8
|
try_after :generate_key, :open_editor, :encrypt, :decrypt
|
|
9
9
|
|
|
10
10
|
def execute
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
file = opts[:bash_support]
|
|
12
|
+
|
|
13
|
+
out = ''
|
|
14
|
+
Sym::Constants::Bash::Config.each_pair do |key, config|
|
|
15
|
+
script_name = key.to_s
|
|
16
|
+
FileUtils.cp(config[:source], config[:dest])
|
|
17
|
+
out << if File.exist?(file)
|
|
18
|
+
if File.read(file).include?(config[:script])
|
|
19
|
+
"#{'OK'.bold.green}, #{file.bold.yellow} already has #{script_name.bold.blue} installed\n"
|
|
20
|
+
else
|
|
21
|
+
append_completion_script(file, config[:script])
|
|
22
|
+
"#{'OK'.bold.green}, appended initialization for #{script_name.bold.blue} to #{file.bold.yellow}\n"
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
append_completion_script(file, config[:script])
|
|
26
|
+
"#{'OK'.bold.green}, created new file #{file.bold.yellow}, added #{script_name.bold.blue} initialization.\n"
|
|
27
|
+
end
|
|
23
28
|
end
|
|
29
|
+
out + "Please reload your terminal session to activate bash completion and other installed utilities.\n"
|
|
24
30
|
end
|
|
25
31
|
|
|
26
32
|
private
|
|
27
33
|
|
|
28
|
-
def
|
|
29
|
-
FileUtils.cp(source_file, path)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def append_completion_script(file)
|
|
34
|
+
def append_completion_script(file, script)
|
|
33
35
|
File.open(file, 'a') do |fd|
|
|
34
|
-
fd.write(script)
|
|
36
|
+
fd.write(script + "\n")
|
|
35
37
|
end
|
|
36
38
|
end
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
def script
|
|
40
|
-
Sym::Constants::Completion::Config[:script]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def source_file
|
|
44
|
-
Sym::Constants::Completion::Config[:file]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def path
|
|
48
|
-
Sym::Constants::Completion::PATH
|
|
49
|
-
end
|
|
50
|
-
|
|
51
40
|
end
|
|
52
41
|
end
|
|
53
42
|
end
|
|
@@ -8,7 +8,7 @@ module Sym
|
|
|
8
8
|
|
|
9
9
|
required_options [:key, :interactive],
|
|
10
10
|
:keychain
|
|
11
|
-
incompatible_options %i(examples help version
|
|
11
|
+
incompatible_options %i(examples help version bash_support)
|
|
12
12
|
try_after :generate_key, :encrypt, :decrypt, :password_protect_key
|
|
13
13
|
|
|
14
14
|
def execute
|
|
@@ -6,7 +6,7 @@ module Sym
|
|
|
6
6
|
class PasswordProtectKey < BaseCommand
|
|
7
7
|
|
|
8
8
|
required_options %i(key interactive), :password
|
|
9
|
-
incompatible_options %i(examples help version
|
|
9
|
+
incompatible_options %i(examples help version bash_support)
|
|
10
10
|
try_after :generate_key, :encrypt, :decrypt
|
|
11
11
|
|
|
12
12
|
def execute
|
|
@@ -5,7 +5,7 @@ module Sym
|
|
|
5
5
|
module Commands
|
|
6
6
|
class PrintKey < BaseCommand
|
|
7
7
|
required_options %i(keychain key)
|
|
8
|
-
incompatible_options %i(examples help version
|
|
8
|
+
incompatible_options %i(examples help version bash_support)
|
|
9
9
|
try_after :show_examples, :generate_key, :encrypt, :decrypt, :password_protect_key, :keychain_add_key
|
|
10
10
|
|
|
11
11
|
def execute
|
data/lib/sym/constants.rb
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
require 'logger'
|
|
2
2
|
module Sym
|
|
3
3
|
module Constants
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
PATH = "#{ENV['HOME']}/#{FILE}".freeze
|
|
7
|
-
Config = {
|
|
8
|
-
file: File.expand_path('../../../bin/sym.completion', __FILE__),
|
|
9
|
-
script: "[[ -f '#{PATH}' ]] && source '#{PATH}'",
|
|
10
|
-
}.freeze
|
|
4
|
+
module Bash
|
|
5
|
+
Config = {}
|
|
11
6
|
|
|
7
|
+
BASH_FILES = Dir.glob("#{File.expand_path('../../../bin', __FILE__)}/sym.*").freeze
|
|
8
|
+
BASH_FILES.each do |bash_file|
|
|
9
|
+
source_file = File.basename(bash_file)
|
|
10
|
+
home_file = "#{ENV['HOME']}/.#{source_file}"
|
|
11
|
+
|
|
12
|
+
Config[source_file.gsub(/sym\./, '').to_sym] = {
|
|
13
|
+
dest: home_file,
|
|
14
|
+
source: bash_file,
|
|
15
|
+
script: "[[ -f #{home_file} ]] && source #{home_file}"
|
|
16
|
+
}
|
|
17
|
+
end
|
|
12
18
|
end
|
|
13
19
|
|
|
14
20
|
module Log
|
|
@@ -17,8 +23,6 @@ module Sym
|
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
ENV_ARGS_VARIABLE_NAME = 'SYM_ARGS'.freeze
|
|
20
|
-
SYM_KEY_FILE
|
|
26
|
+
SYM_KEY_FILE = "#{ENV['HOME']}/.sym.key"
|
|
21
27
|
end
|
|
22
28
|
end
|
|
23
|
-
|
|
24
|
-
|
data/lib/sym/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sym
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konstantin Gredeskoul
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-03-
|
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colored2
|
|
@@ -221,7 +221,6 @@ email:
|
|
|
221
221
|
executables:
|
|
222
222
|
- keychain
|
|
223
223
|
- sym
|
|
224
|
-
- symit
|
|
225
224
|
extensions: []
|
|
226
225
|
extra_rdoc_files: []
|
|
227
226
|
files:
|
|
@@ -240,9 +239,9 @@ files:
|
|
|
240
239
|
- bin/console
|
|
241
240
|
- bin/setup
|
|
242
241
|
- bin/sym.completion
|
|
242
|
+
- bin/sym.symit
|
|
243
243
|
- exe/keychain
|
|
244
244
|
- exe/sym
|
|
245
|
-
- exe/symit
|
|
246
245
|
- lib/sym.rb
|
|
247
246
|
- lib/sym/app.rb
|
|
248
247
|
- lib/sym/app/args.rb
|
data/exe/symit
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
# (c) 2017 Konstantin Gredeskoul
|
|
5
|
-
# MIT License, distributed as part of `sym` ruby gem
|
|
6
|
-
#
|
|
7
|
-
# https://github.com/kigster/sym
|
|
8
|
-
#
|
|
9
|
-
#====================================================================================
|
|
10
|
-
# Purpuse of this script is to transparently edit application secrets in a Rails app.
|
|
11
|
-
#
|
|
12
|
-
# Modify the `default*` variables below and then you can use the script like so:
|
|
13
|
-
#
|
|
14
|
-
# bin/secred <production | staging | development> [ key-spec ]
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# SET THE VALUE BELOW WITH THE NAME OF YOUR KEY (actual key, environment variable,
|
|
18
|
-
# keychain name, etc)
|
|
19
|
-
|
|
20
|
-
[[ -n $1 && ${1:0:1} != "-" ]] && {
|
|
21
|
-
encrypted_file=$1
|
|
22
|
-
shift
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
symit::init() {
|
|
26
|
-
symit::install
|
|
27
|
-
|
|
28
|
-
export default_key=
|
|
29
|
-
export default_extension="yml.enc"
|
|
30
|
-
export default_folder=config/settings/secrets
|
|
31
|
-
|
|
32
|
-
export true=1
|
|
33
|
-
export false=0
|
|
34
|
-
|
|
35
|
-
export txtrst='\e[0m' # Text Reset
|
|
36
|
-
export bldred='\e[1;31m' # Red
|
|
37
|
-
export bldgrn='\e[1;32m' # Green
|
|
38
|
-
export bldylw='\e[1;33m' # Yellow
|
|
39
|
-
export bldblu='\e[1;34m' # Blue
|
|
40
|
-
|
|
41
|
-
unset cli__opts
|
|
42
|
-
declare -A cli__opts=(
|
|
43
|
-
[verbose]=${true}
|
|
44
|
-
[key]=${default_key}
|
|
45
|
-
[extension]=${default_extension}
|
|
46
|
-
[dry_run]=${false}
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
symit::usage() {
|
|
51
|
-
printf "${bldblu}symit: ${txtrst}edit an encrypted file using a pre-defined key\n\n"
|
|
52
|
-
|
|
53
|
-
printf " Usage: ${bldgrn}symit ${bldylw}[file-spec] [options]${txtrst}\n\n"
|
|
54
|
-
|
|
55
|
-
printf " # To edit an encrypted file config/settings/secrets/development.yml.enc${txtrst}\n"
|
|
56
|
-
printf " ${bldgrn}symit${bldylw} development${txtrst}\n\n"
|
|
57
|
-
|
|
58
|
-
printf "options: \n"
|
|
59
|
-
printf " -k | --key [key-spec] Pass an alternative key, other than ${default_key}\n"
|
|
60
|
-
printf " -x | --extension [extension] Pass an alternative default extension, other than ${bldylw}${default_extension}${txtrst}\n"
|
|
61
|
-
printf " -l | --locations Print locations where [file-spec] is searched\n"
|
|
62
|
-
printf " -h | --help Show this help message\n"
|
|
63
|
-
printf " -n | --dry-run Show the generated sym command\n"
|
|
64
|
-
exit 1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
symit::error() {
|
|
68
|
-
printf "${bldred}error: $* ${bldylw}\n"
|
|
69
|
-
exit 255
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
symit::install() {
|
|
73
|
-
if [[ -z "${_symit__installed}" ]] ; then
|
|
74
|
-
[[ -n "$(gem list | grep sym)" ]] || gem install sym
|
|
75
|
-
[[ -z $(sym -h 2>&1 | grep -- '-k, --key' | grep keychain) ]] && {
|
|
76
|
-
printf "detected missing or an older version of ${bldgrn}sym${txtrst}... upgrading...\n"
|
|
77
|
-
echo y | gem uninstall sym -a 2>/dev/null
|
|
78
|
-
gem install sym --verbose
|
|
79
|
-
}
|
|
80
|
-
fi
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
symit::show_locations() {
|
|
84
|
-
printf "Search path: \n"
|
|
85
|
-
for loc in ${locations[@]}; do
|
|
86
|
-
printf " - ${loc}\n"
|
|
87
|
-
done
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
symit::locs() {
|
|
92
|
-
if [[ -n ${encrypted_file} ]]; then
|
|
93
|
-
declare -a locations=("${default_folder}/${encrypted_file}.${default_extension}"
|
|
94
|
-
"${default_folder}/${encrypted_file}"
|
|
95
|
-
"${encrypted_file}")
|
|
96
|
-
fi
|
|
97
|
-
echo -n ${locations[*]}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
symit::init
|
|
101
|
-
|
|
102
|
-
[[ -z ${encrypted_file} && -z $* ]] && symit::usage
|
|
103
|
-
|
|
104
|
-
while :; do
|
|
105
|
-
case $1 in
|
|
106
|
-
-h|-\?|--help)
|
|
107
|
-
shift
|
|
108
|
-
symit::usage
|
|
109
|
-
;;
|
|
110
|
-
|
|
111
|
-
-k|--key)
|
|
112
|
-
shift
|
|
113
|
-
[[ -n $1 ]] || symit::error "-k/--key requires an argument"
|
|
114
|
-
cli__opts[key]=$1
|
|
115
|
-
;;
|
|
116
|
-
|
|
117
|
-
-x|--extension)
|
|
118
|
-
shift
|
|
119
|
-
[[ -n $1 ]] || symit::error "-x/--extension requires an argument"
|
|
120
|
-
cli__opts[extension]=$1
|
|
121
|
-
;;
|
|
122
|
-
|
|
123
|
-
-l|--locations)
|
|
124
|
-
shift
|
|
125
|
-
[[ -n ${encrypted_file} ]] || symit::error "-l/--locations requires file-spec to be provided as the 1st argument"
|
|
126
|
-
declare -a locations=$(symit::locs)
|
|
127
|
-
symit::show_locations
|
|
128
|
-
exit 0
|
|
129
|
-
;;
|
|
130
|
-
-n|--dry-run)
|
|
131
|
-
shift
|
|
132
|
-
cli__opts[dry_run]=${true}
|
|
133
|
-
;;
|
|
134
|
-
|
|
135
|
-
--) # End of all options.
|
|
136
|
-
shift
|
|
137
|
-
break
|
|
138
|
-
;;
|
|
139
|
-
-?*)
|
|
140
|
-
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
|
|
141
|
-
exit 127
|
|
142
|
-
shift
|
|
143
|
-
;;
|
|
144
|
-
*) # Default case: If no more options then break out of the loop.
|
|
145
|
-
break
|
|
146
|
-
shift
|
|
147
|
-
esac
|
|
148
|
-
done
|
|
149
|
-
|
|
150
|
-
declare -a locations=$(symit::locs)
|
|
151
|
-
|
|
152
|
-
file=
|
|
153
|
-
for loc in ${locations[@]}; do
|
|
154
|
-
if [[ -s "${loc}" ]] ; then
|
|
155
|
-
file=${loc}
|
|
156
|
-
break
|
|
157
|
-
fi
|
|
158
|
-
done
|
|
159
|
-
|
|
160
|
-
[[ -z $file ]] && symit::error "${encrypted_file} could not be found."
|
|
161
|
-
|
|
162
|
-
command="sym -ck $cli__opts[key] -tf ${file}"
|
|
163
|
-
|
|
164
|
-
${cli_opts[dry_run]} && printf "[dry_run] "
|
|
165
|
-
|
|
166
|
-
printf "${bldgrn}${command}${txtrst}\n"
|
|
167
|
-
|
|
168
|
-
${cli_opts[dry_run]} || ${command}
|