2pass 2.1.0 → 2.2.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/2pass/version.rb +1 -1
  3. data/lib/2pass.rb +31 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 135196a393e121fb8b71d5295fdedc19f3bccb24885ce81cf630be59d2b7c64e
4
- data.tar.gz: 7f5684e81780732115fcf6b9d5a071cfd1e8a05eaa48246e35f7fd3841a702ce
3
+ metadata.gz: 280272cc90ded8e3572ad707e7a254e9bd8a599c3a11515178a9dfd5386feefb
4
+ data.tar.gz: 8e2510cb1d55f80f8035897759d701690276999aabc5d45eebc73b85b625545e
5
5
  SHA512:
6
- metadata.gz: e1c997e62173b57c596adf21c9636bfd7ed3417a5f0611d497db1caa486a18e113ad37b234bec8b3334fcea282c5f99f2ec9dbd1b4e328222b1439f281629586
7
- data.tar.gz: 9697b86fe839dc5d29f7786ab2e278986fbdb64bd2fc89e142f6e8bc812f919a66d3b57afcb97e71e099d806cc1411c56c12f5117facf6174ee780de71812b14
6
+ metadata.gz: 42fe8d2ed4e7e39ffaca9b868593ebdedf0a1760b7c05b1a26290225c693dba3a18aec07452b957802b70c84cb254c6ced00880538b8831d584897d9dea83d39
7
+ data.tar.gz: a23ea61addd2651fe02b13c0a66a6c4b55a4313bee8abac04ff78af45cc8a5d81df65ba6b9d31e52795af4a4e6721dfd741a5694aa283285390e36fea0686b4f
data/lib/2pass/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TwoPass
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
data/lib/2pass.rb CHANGED
@@ -84,7 +84,7 @@ module TwoPass
84
84
  id: id,
85
85
  value: value
86
86
  }
87
- data = load_vault(vault_name, env: env)
87
+ data = load_vault(vault_name, env: env, allow_missing: true)
88
88
  existing_entry_id = data.find_index { |hash| hash[:id] == new_secret[:id] }
89
89
  if existing_entry_id
90
90
  raise "The secret already exists"
@@ -121,9 +121,13 @@ module TwoPass
121
121
 
122
122
  private
123
123
 
124
- def load_vault(vault_name, env: nil)
124
+ def load_vault(vault_name, env: nil, allow_missing: false)
125
125
  file_path = self.vault_file_path(vault_name, env: env)
126
- return [] unless File.exist?(file_path)
126
+ unless File.exist?(file_path)
127
+ return [] if allow_missing
128
+
129
+ raise missing_vault_error_message(vault_name, file_path, env: env)
130
+ end
127
131
 
128
132
  YAML.load_file(file_path, symbolize_names: true) || []
129
133
  rescue Errno::EACCES, Errno::EPERM => e
@@ -133,6 +137,30 @@ module TwoPass
133
137
  []
134
138
  end
135
139
 
140
+ def missing_vault_error_message(vault_name, file_path, env: nil)
141
+ link_args = [vault_name, "<path-to-vault>", env].compact.join(" ")
142
+ add_args = [vault_name, "<id>", "<value>", env].compact.join(" ")
143
+
144
+ if File.symlink?(file_path)
145
+ target = File.expand_path(File.readlink(file_path), File.dirname(file_path))
146
+ message = +"Vault symlink is broken: #{file_path} -> #{target}"
147
+ message << "\nThe symlink exists but its target is missing."
148
+ message << "\nIf the vault is in a synced location (iCloud, Dropbox, etc.), it may not have"
149
+ message << "\ndownloaded yet, or it was moved or deleted."
150
+ message << "\nRe-create the link once the file is available:"
151
+ message << "\n 2pass link #{link_args}"
152
+ return message
153
+ end
154
+
155
+ message = +"Vault not found: #{file_path}"
156
+ message << "\nNo vault file or symlink exists at this path."
157
+ message << "\nCreate it by adding your first secret:"
158
+ message << "\n 2pass add #{add_args}"
159
+ message << "\nOr, if the vault already lives in a synced location (iCloud, Dropbox, etc.), link it:"
160
+ message << "\n 2pass link #{link_args}"
161
+ message
162
+ end
163
+
136
164
  def vault_file_path(vault_name, env: nil)
137
165
  [
138
166
  VAULT_DIR,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 2pass
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier