yamp 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/yamp +40 -19
  3. data/lib/yamp.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12d4147065962bc1538c030e019e60e3d0b7f6b0
4
- data.tar.gz: e4d7a5c84938d78bc8b5256d35ce31596b8a331c
3
+ metadata.gz: af599784fb31d967ffc9f696ddc11691a5a294e8
4
+ data.tar.gz: 288685df62e89aa8ec9c77e9b837c06e561b7419
5
5
  SHA512:
6
- metadata.gz: 17ad410c73d0a142e8524b229871ae5411627908fbdd5ddddd044e7ddb877545f336539ffc7b23ffcbadefade141ed28d5c819c4443c88063630cc02657f0912
7
- data.tar.gz: bd62ec4f70c9fdfb76f391f6e0de457aa48014b58f63ee14f76e5ef6f9f85475e1ae7038eb7a0898719d85909276f7b0e81ba049c0e3b25979f35fb6eeef694f
6
+ metadata.gz: 4eec8131dc8f1f9b9c90992e32f6d37aaa79abf9b0092f51048c27669ed7159241cf88c09eb5cbfaad6d8e9bf4b39798523dbc2d2ca4f0f6151f3f3e78302b8d
7
+ data.tar.gz: 91b4c2ed2b91d8ac24eb6cc6b7e7c0ce4df2445400a4a7e62ff1726ebf7fe804fcad9e4a1ae8fc896df42823793e93411863eaf6b206a6552b969c6bf2ca6557
data/bin/yamp CHANGED
@@ -3,9 +3,12 @@
3
3
  require 'io/console'
4
4
  require 'clipboard'
5
5
  require 'optparse'
6
+ require 'yaml'
6
7
  require 'yamp'
7
8
 
8
- trap "SIGINT" do puts "\nByeBye!"; exit(130) end
9
+ ARGV << '-h' if ARGV.empty?
10
+
11
+ trap "SIGINT" do puts "\nk bye!"; exit(130) end
9
12
 
10
13
  class String
11
14
  def red; "\033[31m#{self}\033[0m" end
@@ -13,12 +16,10 @@ class String
13
16
  def yellow; "\033[33m#{self}\033[0m" end
14
17
  end
15
18
 
16
- ARGV << '-h' if ARGV.empty?
19
+ CONFIG = ENV['HOME'] + "/.yamp"
20
+ PASSWORD_CHARS = [*'0'..'9', *'a'..'z',*'A'..'Z','#','!','?','$','/','(',')','[',']']
17
21
 
18
- vault = nil
19
22
  options = {}
20
- password_chars = [*'0'..'9', *'a'..'z',*'A'..'Z','#','!','?','$','/','(',')','[',']']
21
-
22
23
  OptionParser.new do |opts|
23
24
  opts.banner = %q(
24
25
  Usage: yamp [options]
@@ -31,10 +32,10 @@ OptionParser.new do |opts|
31
32
  yamp -g twitter --to-clipboard
32
33
  yamp --delete facebook
33
34
  )
34
- opts.on('-a', '--add ENTRY', 'create an entry') {|id| options[:add] = id}
35
- opts.on('-g', '--get ENTRY', 'read an entry') {|id| options[:get] = id}
36
- opts.on('-u', '--update ENTRY', 'update an entry') {|id| options[:upd] = id}
37
- opts.on('-d', '--delete ENTRY', 'delete an entry') {|id| options[:del] = id}
35
+ opts.on('-a', '--add ENTRY', 'create an entry') {|id| options[:add] = id}
36
+ opts.on('-g', '--get ENTRY', 'read an entry') {|id| options[:get] = id}
37
+ opts.on('-u', '--update ENTRY', 'update an entry') {|id| options[:upd] = id}
38
+ opts.on('-d', '--delete ENTRY', 'delete an entry') {|id| options[:del] = id}
38
39
  opts.on('-p', '--password PWD', 'specify a password') {|pwd| options[:pwd] = pwd}
39
40
  opts.on('-n', '--username USR', 'specify a username') {|usr| options[:usr] = usr}
40
41
  opts.on('-l', '--list', 'list all entries') {options[:lst] = true}
@@ -46,18 +47,38 @@ unless (options.keys & [:add, :del, :upd, :get, :lst]).size == 1
46
47
  exit
47
48
  end
48
49
 
49
- print RUBY_PLATFORM =~ /darwin/ ? "🙈 " : ">"
50
+ unless File.file? CONFIG
51
+ File.open CONFIG, 'w' do |f|
52
+ f.write "ui:\n"
53
+ f.write " prompt: #{RUBY_PLATFORM =~ /darwin/ ? "\"🙈 \"\n" : "\"~>\"\n"}"
54
+ f.write "redis:\n"
55
+ f.write " ip: 127.0.0.1\n"
56
+ f.write " port: 6379\n"
57
+ f.write " db: 0\n"
58
+ f.write " protected: no\n"
59
+ end
60
+ end
61
+ cfg = YAML.load_file(CONFIG)
62
+
63
+ print cfg['ui']['prompt']
50
64
  master = STDIN.noecho(&:gets).chomp!; puts "\n"
65
+ redis = Redis.new(
66
+ url: "redis://" +
67
+ (cfg['redis']['protected'] ? ":#{master}@" : "") +
68
+ "#{cfg['redis']['ip']}:" +
69
+ "#{cfg['redis']['port']}/" +
70
+ "#{cfg['redis']['db']}"
71
+ )
51
72
  begin
52
- vault = YAMP::Vault.new master
73
+ @vault = YAMP::Vault.new master, redis
53
74
  rescue Exception => e
54
75
  puts e.message
55
76
  exit
56
77
  end
57
78
 
58
79
  if id = options[:add]
59
- pwd = options[:pwd] ? options[:pwd] : 32.times.map {password_chars.sample}.join
60
- unless vault.add id, pwd, options[:usr]
80
+ pwd = options[:pwd] ? options[:pwd] : 32.times.map {PASSWORD_CHARS.sample}.join
81
+ unless @vault.add id, pwd, options[:usr]
61
82
  puts "entry already exists"
62
83
  else
63
84
  puts "+".green + " #{id}"
@@ -67,7 +88,7 @@ if id = options[:add]
67
88
  end
68
89
 
69
90
  if id = options[:del]
70
- unless vault.remove id
91
+ unless @vault.remove id
71
92
  puts "no such entry"
72
93
  else
73
94
  puts "-".red + " #{id}"
@@ -83,10 +104,10 @@ if id = options[:upd]
83
104
  pwd_updated = false
84
105
  usr_updated = false
85
106
  if pwd = options[:pwd]
86
- pwd_updated = vault.update id, :pwd, pwd
107
+ pwd_updated = @vault.update id, :pwd, pwd
87
108
  end
88
109
  if usr = options[:usr]
89
- usr_updated = vault.update id, :usr, usr
110
+ usr_updated = @vault.update id, :usr, usr
90
111
  end
91
112
  unless pwd_updated || usr_updated
92
113
  puts "no such entry"
@@ -98,8 +119,8 @@ if id = options[:upd]
98
119
  end
99
120
 
100
121
  if id = options[:get]
101
- password = vault.get id, :pwd
102
- username = vault.get id, :usr
122
+ password = @vault.get id, :pwd
123
+ username = @vault.get id, :usr
103
124
  unless password || username
104
125
  puts "no such entry"
105
126
  else
@@ -114,6 +135,6 @@ if id = options[:get]
114
135
  end
115
136
 
116
137
  if options[:lst]
117
- puts vault.list.sort
138
+ puts @vault.list.sort
118
139
  exit
119
140
  end
data/lib/yamp.rb CHANGED
@@ -13,7 +13,7 @@ module YAMP
13
13
  if master_hash && master_salt
14
14
  @master_key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(master, master_salt, 10000, 32)
15
15
  unless OpenSSL::Digest::SHA512.hexdigest(@master_key) == master_hash
16
- raise ArgumentError, "access denied"
16
+ raise ArgumentError, 'ERR invalid password'
17
17
  end
18
18
  else
19
19
  salt = OpenSSL::Random.random_bytes(32)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Heilig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -61,7 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - bin/yamp
63
63
  - lib/yamp.rb
64
- homepage: http://rubygems.org/gems/yamp
64
+ homepage: https://github.com/HIGHphen/yamp
65
65
  licenses:
66
66
  - MIT
67
67
  metadata: {}