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.
- checksums.yaml +4 -4
- data/lib/2pass/version.rb +1 -1
- data/lib/2pass.rb +31 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 280272cc90ded8e3572ad707e7a254e9bd8a599c3a11515178a9dfd5386feefb
|
|
4
|
+
data.tar.gz: 8e2510cb1d55f80f8035897759d701690276999aabc5d45eebc73b85b625545e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42fe8d2ed4e7e39ffaca9b868593ebdedf0a1760b7c05b1a26290225c693dba3a18aec07452b957802b70c84cb254c6ced00880538b8831d584897d9dea83d39
|
|
7
|
+
data.tar.gz: a23ea61addd2651fe02b13c0a66a6c4b55a4313bee8abac04ff78af45cc8a5d81df65ba6b9d31e52795af4a4e6721dfd741a5694aa283285390e36fea0686b4f
|
data/lib/2pass/version.rb
CHANGED
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
|
-
|
|
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,
|