2pass 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/2pass.gemspec +2 -0
- data/bin/2pass +8 -0
- data/lib/2pass/version.rb +1 -1
- data/lib/2pass.rb +48 -46
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 671d7c33b6f4e5e79ef13a88986405674f456dc06e23f5cc7450fb495ecdcb71
|
4
|
+
data.tar.gz: 415390e6ac546a6af7678058e1231a4ade807df151dca0b163aa4023da8fe229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f865bb6fac54e13f4ac4c7c917680b0a0ef92194d1a2f1f97cc72333de8215466d4ab598a0a2ddb5360bc61b489c9a0231fa2ec3d53afd98b7e9f15aecb58fb1
|
7
|
+
data.tar.gz: e01b0c574e69fcd8096605c7b7a2f383aad580dbbfd72ec6a89701573ee75a182303b5bd6349bc8022a9354e4a4bc042a090435016bba213aca0c37d54fcf5eb
|
data/2pass.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = ["2pass"]
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = ">= 3.3"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 2.0"
|
22
24
|
spec.add_development_dependency "rake", "~> 13.0"
|
23
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
data/bin/2pass
CHANGED
@@ -20,6 +20,9 @@ OptionParser.new do |opts|
|
|
20
20
|
opts.on("-h", "--help", "Display this help message") do
|
21
21
|
options[:help] = true
|
22
22
|
end
|
23
|
+
opts.on("-v", "--version", "Display the version") do
|
24
|
+
options[:version] = true
|
25
|
+
end
|
23
26
|
end.parse!
|
24
27
|
|
25
28
|
if options[:help]
|
@@ -27,6 +30,11 @@ if options[:help]
|
|
27
30
|
exit
|
28
31
|
end
|
29
32
|
|
33
|
+
if options[:version]
|
34
|
+
puts TwoPass::VERSION
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
30
38
|
if ARGV.length < 2
|
31
39
|
help_message
|
32
40
|
exit(1)
|
data/lib/2pass/version.rb
CHANGED
data/lib/2pass.rb
CHANGED
@@ -9,61 +9,63 @@ require_relative "2pass/version"
|
|
9
9
|
module TwoPass
|
10
10
|
VAULT_DIR = "#{Dir.home}/.2pass"
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class << self
|
13
|
+
def create_symlink(vault_name, target_path)
|
14
|
+
FileUtils.mkdir_p(VAULT_DIR)
|
15
|
+
symlink_path = "#{VAULT_DIR}/#{vault_name}.yml"
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if File.exist?(symlink_path)
|
18
|
+
puts "Symlink already exists: #{symlink_path}"
|
19
|
+
else
|
20
|
+
File.symlink(target_path, symlink_path)
|
21
|
+
puts "Created symlink: #{symlink_path} -> #{target_path}"
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def load_vault(vault_name)
|
26
|
+
file_path = "#{VAULT_DIR}/#{vault_name}.yml"
|
27
|
+
return [] unless File.exist?(file_path)
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
YAML.load_file(file_path, symbolize_names: true) || []
|
30
|
+
rescue Psych::SyntaxError => e
|
31
|
+
STDERR.puts "Error parsing YAML file: #{e.message}"
|
32
|
+
[]
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def save_vault(vault_name, data)
|
36
|
+
FileUtils.mkdir_p(VAULT_DIR)
|
37
|
+
file_path = "#{VAULT_DIR}/#{vault_name}.yml"
|
38
|
+
File.write(file_path, YAML.dump(data))
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def list_content(vault_name)
|
42
|
+
vault = load_vault(vault_name)
|
43
|
+
JSON.pretty_generate(vault)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
def add_secret(vault_name, id, value)
|
47
|
+
new_secret = {
|
48
|
+
id: id,
|
49
|
+
value: value,
|
50
|
+
uuid: SecureRandom.uuid
|
51
|
+
}
|
52
|
+
data = load_vault(vault_name)
|
53
|
+
existing_entry_id = data.find_index { |hash| hash[:id] == new_secret[:id] }
|
54
|
+
if existing_entry_id
|
55
|
+
raise "The secret already exists"
|
56
|
+
end
|
57
|
+
data << new_secret
|
58
|
+
save_vault(vault_name, data)
|
55
59
|
end
|
56
|
-
data << new_secret
|
57
|
-
save_vault(vault_name, data)
|
58
|
-
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
def get_secret(vault_name, id)
|
62
|
+
vault = load_vault(vault_name)
|
63
|
+
entry = vault.find { |hash| hash[:id] == id }
|
64
|
+
if entry
|
65
|
+
entry[:value]
|
66
|
+
else
|
67
|
+
raise "Entry not found"
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 2pass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '3.3'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - ">="
|