keylime 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8af60ec7922e369b972ab3eae64e1063956b773ba1cde45131ded4c0bf1baec
4
- data.tar.gz: fddc7005a80a749421a203ece9224dfd403afd6202713f5c7ab4e49e1b2f6415
3
+ metadata.gz: d004d9691c61d8045986433d201264fbcca3a61fcf612402c833dedd39c68859
4
+ data.tar.gz: 26d2014a6565b5d17d13870e28fe1e56409391dbbb3acaf280aa12d16bbbcae4
5
5
  SHA512:
6
- metadata.gz: 7764cbb02639c030cb8fd0e3fcc0a3cf54c9189e94c5adda4cdd50322aead224caa1d282f5dcc3a4b71422431ac49343c9f6443d9d8b531601093cfc37541716
7
- data.tar.gz: 3ec97ad17d192783958236eb62ddcf3329d039d0db1a3e5eea8ef8671dd2ae9691a2d4d5662cc70eaa06e12bd53e6122cc12842a4bb8960752325b4ed1c712fc
6
+ metadata.gz: fdf95c3ff6aa9c16043749270921270a4d6155c6b12b3026a16e103ce5b66930cb485a947b8b64b26daedb8bd9e99ce523ba95c0bf2941b00a629a337b138d77
7
+ data.tar.gz: 2ec581fcc40e01c6abdeaec643d7bacc870d0a9b5fcf9f10131205686f45523af04f3ca1e8920a392f92d5ba4ade23318f2607c77e30f15e5305f7e52863a057
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'keylime'
3
- s.version = '0.1.2'
3
+ s.version = '0.2.0'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
 
6
6
  s.summary = 'Simple wrapper for using Mac Keychain'
@@ -21,5 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'goodcop', '~> 0.4.0'
22
22
  s.add_development_dependency 'rake', '~> 12.3.0'
23
23
  s.add_development_dependency 'rspec', '~> 3.7.0'
24
- s.add_development_dependency 'rubocop', '~> 0.53.0'
24
+ s.add_development_dependency 'rubocop', '~> 0.54.0'
25
25
  end
@@ -1,4 +1,5 @@
1
1
  require 'userinput'
2
+ require 'yaml'
2
3
 
3
4
  module Keylime
4
5
  ENABLED = begin
@@ -47,7 +48,7 @@ module Keylime
47
48
 
48
49
  def keychain
49
50
  return @keychain if @keychain
50
- @keychain = StubKeychain.new unless Keylime::ENABLED
51
+ @keychain = FileKeychain.new(@options[:keychain]) unless Keylime::ENABLED
51
52
  @keychain ||= Keychain.open(@options[:keychain]) if @options[:keychain]
52
53
  @keychain ||= Keychain
53
54
  end
@@ -63,9 +64,13 @@ module Keylime
63
64
 
64
65
  ##
65
66
  # Stub keychain for if keylime is running on a non-Mac
66
- class StubKeychain
67
+ class FileKeychain
68
+ def initialize(keychain)
69
+ @keychain = keychain
70
+ end
71
+
67
72
  def segment
68
- StubKeychainSegment.new
73
+ @segment ||= FileKeychainSegment.new(@keychain)
69
74
  end
70
75
  alias internet_passwords segment
71
76
  alias generic_passwords segment
@@ -73,11 +78,85 @@ module Keylime
73
78
 
74
79
  ##
75
80
  # Stub segment for if keylime is running on a non-Mac
76
- class StubKeychainSegment
77
- def where(_)
78
- []
81
+ class FileKeychainSegment
82
+ def initialize(keychain)
83
+ @keychain = keychain || '~/.keylime'
84
+ end
85
+
86
+ def where(fields = {})
87
+ fields = stringify(fields)
88
+ entries.select do |x|
89
+ fields.all? { |k, v| x[k] == v }
90
+ end
91
+ end
92
+
93
+ def create(fields = {})
94
+ raise('No fields given') if fields.empty?
95
+ fields = stringify(fields)
96
+ fields['ref'] = self
97
+ new = FileKeychainObject.new(fields)
98
+ write_file! entries + [new]
99
+ new
100
+ end
101
+
102
+ def delete(fields = {})
103
+ raise('No fields given') if fields.empty?
104
+ fields = stringify(fields)
105
+ new = entries.select do |x|
106
+ fields.any? { |k, v| x[k] != v }
107
+ end
108
+ write_file! new
109
+ end
110
+
111
+ private
112
+
113
+ def entries
114
+ create_file! unless File.exist? file
115
+ YAML.safe_load(File.read(file))['credentials'].map do |x|
116
+ x['ref'] = self
117
+ FileKeychainObject.new(x)
118
+ end
119
+ end
120
+
121
+ def create_file!
122
+ write_file!([])
123
+ end
124
+
125
+ def write_file!(entries)
126
+ File.open(file, 'w') do |fh|
127
+ fh << YAML.dump('credentials' => entries.map(&:fields))
128
+ end
79
129
  end
80
130
 
81
- def create(_) end
131
+ def file
132
+ @file ||= File.expand_path @keychain
133
+ end
134
+
135
+ def stringify(fields)
136
+ fields.map { |k, v| [k.to_s, v] }.to_h
137
+ end
138
+ end
139
+
140
+ ##
141
+ # Object for stub file keychain
142
+ class FileKeychainObject
143
+ attr_reader :fields
144
+
145
+ def initialize(params = {})
146
+ @ref = params.delete('ref')
147
+ @fields = params
148
+ end
149
+
150
+ def delete
151
+ @ref.delete(@fields)
152
+ end
153
+
154
+ def respond_to_missing?(method, _)
155
+ @fields.include?(method.to_s) || super
156
+ end
157
+
158
+ def method_missing(sym, *args, &block)
159
+ @fields[sym.to_s] || super
160
+ end
82
161
  end
83
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keylime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-keychain
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.53.0
117
+ version: 0.54.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.53.0
124
+ version: 0.54.0
125
125
  description: Simple wrapper for using Mac Keychain
126
126
  email: me@lesaker.org
127
127
  executables: []