vaultez-cli 0.2.1 → 0.3.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/vaultez/cli.rb +7 -13
- data/lib/vaultez/client.rb +10 -2
- data/lib/vaultez/config.rb +20 -2
- data/lib/vaultez/version.rb +1 -1
- 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: 824ab321c6ff7b03bd1495461f6c545bc15aa07d596c863e3388fc5d8383622f
|
|
4
|
+
data.tar.gz: 5417e6a9394622242c58608eddd1186629dc63586fc9ba4545702e1168e8f5f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d06a027b38872fb4b9e02ee827b03589d4ddffa9d8a0fbfca87fe00e71a5e7b64eedd63d48b5dbfcd9f4c5d195f3628bfaec74b4846a463a7b675721695e9e5
|
|
7
|
+
data.tar.gz: 7808de1486e94c49eb163317f1d488de5e581fe83b1fc5dd9bf804d9d12d7a103401f2a59e6ad6c0ebb68f3b514f8539b4daf05dd7e143f63e905cf1fa435dea
|
data/lib/vaultez/cli.rb
CHANGED
|
@@ -12,14 +12,6 @@ module Vaultez
|
|
|
12
12
|
|
|
13
13
|
map %w[--version -v] => :__version
|
|
14
14
|
|
|
15
|
-
class_option :token, type: :string, banner: "TOKEN",
|
|
16
|
-
desc: "Use a project token instead of the saved session"
|
|
17
|
-
|
|
18
|
-
def initialize(*args)
|
|
19
|
-
super
|
|
20
|
-
ENV["VAULTEZ_TOKEN"] = options[:token] if options[:token]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
15
|
desc "login", "Authenticate with email, password, and 2FA code"
|
|
24
16
|
long_desc <<~DESC, wrap: false
|
|
25
17
|
Authenticate with your Vaultez account. You will be prompted for your
|
|
@@ -55,14 +47,17 @@ module Vaultez
|
|
|
55
47
|
vaultez fetch --company="Acme" --project="Backend"
|
|
56
48
|
vaultez fetch --company="Acme" --project="Backend" --secret="DATABASE_URL"
|
|
57
49
|
|
|
58
|
-
PROJECT TOKEN (VAULTEZ_TOKEN env var
|
|
50
|
+
PROJECT TOKEN (VAULTEZ_TOKEN env var):
|
|
59
51
|
When a project token is active, it already knows which project to use.
|
|
60
52
|
No --project flag is needed.
|
|
61
53
|
|
|
62
54
|
VAULTEZ_TOKEN=vz_... vaultez fetch
|
|
63
|
-
vaultez fetch --
|
|
55
|
+
VAULTEZ_TOKEN=vz_... vaultez fetch --secret="DATABASE_URL"
|
|
64
56
|
|
|
65
57
|
Project tokens can be created in the Tokens tab of your project settings.
|
|
58
|
+
Always pass the token via the VAULTEZ_TOKEN environment variable, never
|
|
59
|
+
as a command-line flag — CLI arguments are visible to other local users
|
|
60
|
+
via `ps` and get saved in shell history.
|
|
66
61
|
DESC
|
|
67
62
|
option :companies, type: :boolean, desc: "List all your companies"
|
|
68
63
|
option :company, type: :string, desc: "Company name"
|
|
@@ -103,15 +98,14 @@ module Vaultez
|
|
|
103
98
|
puts " help Show help for any command"
|
|
104
99
|
puts
|
|
105
100
|
puts "Options:"
|
|
106
|
-
puts " --token Use a project token instead of the saved session"
|
|
107
101
|
puts " --version Show the installed CLI version"
|
|
108
102
|
puts
|
|
109
103
|
puts "Examples:"
|
|
110
104
|
puts " vaultez login"
|
|
111
105
|
puts " vaultez fetch --project=\"Backend\""
|
|
112
106
|
puts " vaultez fetch --project=\"Backend\" --secret=\"DATABASE_URL\""
|
|
113
|
-
puts "
|
|
114
|
-
puts "
|
|
107
|
+
puts " VAULTEZ_TOKEN=\"vz_...\" vaultez fetch"
|
|
108
|
+
puts " VAULTEZ_TOKEN=\"vz_...\" vaultez fetch --secret=\"DATABASE_URL\""
|
|
115
109
|
end
|
|
116
110
|
end
|
|
117
111
|
end
|
data/lib/vaultez/client.rb
CHANGED
|
@@ -51,7 +51,9 @@ module Vaultez
|
|
|
51
51
|
def request(method, path, body = nil, authenticated: true)
|
|
52
52
|
uri = URI("#{@api_url}#{path}")
|
|
53
53
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
54
|
-
http.use_ssl
|
|
54
|
+
http.use_ssl = uri.scheme == "https"
|
|
55
|
+
http.open_timeout = 10
|
|
56
|
+
http.read_timeout = 15
|
|
55
57
|
|
|
56
58
|
req = build_request(method, uri)
|
|
57
59
|
req["Content-Type"] = "application/json"
|
|
@@ -65,7 +67,13 @@ module Vaultez
|
|
|
65
67
|
|
|
66
68
|
req.body = body.to_json if body
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
begin
|
|
71
|
+
response = http.request(req)
|
|
72
|
+
rescue StandardError => error
|
|
73
|
+
raise Vaultez::ApiError, "Could not reach the Vaultez API: #{error.message}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
parse_response(response)
|
|
69
77
|
end
|
|
70
78
|
|
|
71
79
|
def build_request(method, uri)
|
data/lib/vaultez/config.rb
CHANGED
|
@@ -41,12 +41,30 @@ module Vaultez
|
|
|
41
41
|
|
|
42
42
|
def self.read
|
|
43
43
|
return {} unless File.exist?(CONFIG_PATH)
|
|
44
|
+
tighten_permissions
|
|
44
45
|
YAML.safe_load(File.read(CONFIG_PATH)) || {}
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
def self.write(data)
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
dir = File.dirname(CONFIG_PATH)
|
|
50
|
+
FileUtils.mkdir_p(dir, mode: 0o700)
|
|
51
|
+
# The mode argument to mkdir_p/File.open only applies at creation time,
|
|
52
|
+
# so explicitly chmod too - this also retroactively tightens a config
|
|
53
|
+
# directory/file that was created before this fix, which would
|
|
54
|
+
# otherwise stay world-readable forever (0644/0755 by default umask).
|
|
55
|
+
File.chmod(0o700, dir)
|
|
56
|
+
File.open(CONFIG_PATH, File::CREAT | File::TRUNC | File::WRONLY, 0o600) do |f|
|
|
57
|
+
f.write(data.to_yaml)
|
|
58
|
+
end
|
|
59
|
+
File.chmod(0o600, CONFIG_PATH)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.tighten_permissions
|
|
63
|
+
dir = File.dirname(CONFIG_PATH)
|
|
64
|
+
File.chmod(0o700, dir) if File.directory?(dir) && (File.stat(dir).mode & 0o777) != 0o700
|
|
65
|
+
File.chmod(0o600, CONFIG_PATH) if (File.stat(CONFIG_PATH).mode & 0o777) != 0o600
|
|
66
|
+
rescue StandardError
|
|
67
|
+
nil # best-effort; never block a read over a permissions fix
|
|
50
68
|
end
|
|
51
69
|
end
|
|
52
70
|
end
|
data/lib/vaultez/version.rb
CHANGED