vaultkit 1.1.5 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1d59f182a1b48be74a0e73fd35c23c7e32c8d453acc810c359c9d20ebe1570e
4
- data.tar.gz: 466d3f664c8eb9104db19536d4c2c372fb456c2b01e9e080c9120f50087bdc7e
3
+ metadata.gz: 42e3300980d3a6c3041304eea365fad63d8bfb2a5b56a49c32ccb89d21366ec8
4
+ data.tar.gz: f353b00284834a0c3eed06f4af09da181d4bb3f622f61bbcfcc949d4014bf109
5
5
  SHA512:
6
- metadata.gz: 32dbb26e53c3b110b15ea4d92e75a7fc871b39647fb4c5f7b8d6c7e2832647b34dce8c1f1a0e2156ce73d9bd7af625150ddd48db588665e81e7e11bcb8afeb96
7
- data.tar.gz: 7c30f17e8e4af03dd89464dff02c1aa861006a870883c026fac492be82f3728b41d682dbce33e0764fa70e0cb5a1bbbd4747f147406c68094a8dabde415f2243
6
+ metadata.gz: fcf5ba06e5f6256f705de1d228b70c52a94fe4ce26c11d82d3e2dbab30397119ea33d511acdac0d1e383cb3e501c1286e303490f3035a2b9991cee8b04863d87
7
+ data.tar.gz: 537cf82edb8000c9a0c5d273c14e1958198022a16a6918b5f5f2ac7f673b1f9df7b1b26c5daf95acbb6bc0a6f3395ff430e73cc09ee6f8934f2179336b09789a
data/README.md CHANGED
@@ -200,6 +200,38 @@ Clear stored credentials and end session.
200
200
  vkit logout
201
201
  ```
202
202
 
203
+ ### Credentials from the environment
204
+
205
+ `vkit` normally uses the login saved by `vkit login`, in your OS keychain or
206
+ `~/.vkit/credentials.json`. Scripts, CI jobs and demos can supply credentials for
207
+ a single command or shell instead, without replacing your saved login:
208
+
209
+ ```bash
210
+ export VKIT_ENDPOINT=http://localhost:3300
211
+ export VKIT_TOKEN=<a VaultKit user token>
212
+ vkit request < query.json
213
+ ```
214
+
215
+ - **Both variables are needed.** When both are set, they replace the saved login
216
+ for every command except `vkit login` and `vkit logout`, which always work on
217
+ the saved login.
218
+ - **One alone is an error.** `vkit` stops and names the missing variable, rather
219
+ than mixing the environment with your saved login.
220
+ - **A notice goes to stderr** once per command while the override is active.
221
+ The token is never printed.
222
+ - **Unset both** (`unset VKIT_ENDPOINT VKIT_TOKEN`) to go back to your saved login.
223
+
224
+ To act as someone else for one command, override the token on that command only.
225
+ For example, a reviewer approving a request from the same shell:
226
+
227
+ ```bash
228
+ VKIT_TOKEN="$APPROVER_TOKEN" vkit approval:list
229
+ VKIT_TOKEN="$APPROVER_TOKEN" vkit approval:approve 42
230
+ ```
231
+
232
+ `vkit login --endpoint` still reads `VKIT_ENDPOINT` as its default endpoint when
233
+ `VKIT_TOKEN` isn't set.
234
+
203
235
  ---
204
236
 
205
237
  ## 🔄 Core Workflows
@@ -21,7 +21,7 @@ module Vkit
21
21
  endpoint =
22
22
  @endpoint ||
23
23
  ENV["VKIT_ENDPOINT"] ||
24
- credential_store.endpoint ||
24
+ credential_store.stored_payload&.dig("endpoint") ||
25
25
  prompt("VaultKit Control Plane URL")
26
26
  client = Vkit::Core::AuthClient.new(base_url: endpoint)
27
27
 
@@ -2,13 +2,15 @@ module Vkit
2
2
  module CLI
3
3
  module Commands
4
4
  class LogoutCommand < BaseCommand
5
+ # Always the saved login, even when VKIT_ENDPOINT/VKIT_TOKEN are set.
5
6
  def call
6
- token = credential_store.token
7
+ saved = credential_store.stored_payload || {}
8
+ token = saved["token"]
7
9
 
8
10
  if token
9
11
  begin
10
12
  client = Vkit::Core::AuthClient.new(
11
- base_url: credential_store.endpoint
13
+ base_url: saved["endpoint"]
12
14
  )
13
15
 
14
16
  client.logout(token)
@@ -2,13 +2,26 @@ require "json"
2
2
  require "fileutils"
3
3
  require "open3"
4
4
  require "rbconfig"
5
+ require_relative "auth_client"
6
+ require_relative "../cli/errors"
5
7
 
6
8
  module Vkit
7
9
  module Core
10
+ # Where vkit keeps its login: the OS keychain (or ~/.vkit), unless
11
+ # VKIT_ENDPOINT and VKIT_TOKEN are both set, which then take over for
12
+ # reading credentials without touching the saved login. That's for
13
+ # scripts, CI and demos that shouldn't replace a person's own login.
14
+ # `vkit login` and `vkit logout` always work on the saved login.
8
15
  class CredentialStore
9
16
  SERVICE = "vkit"
10
17
  ACCOUNT = "credentials"
11
18
 
19
+ @override_noticed = false
20
+
21
+ class << self
22
+ attr_accessor :override_noticed
23
+ end
24
+
12
25
  def initialize
13
26
  @os = RbConfig::CONFIG["host_os"]
14
27
  @fallback_path = File.join(Dir.home, ".vkit", "credentials.json")
@@ -34,6 +47,11 @@ module Vkit
34
47
  end
35
48
 
36
49
  def save_user(user)
50
+ if env_override
51
+ @override_user = user
52
+ return
53
+ end
54
+
37
55
  payload = load_payload
38
56
  return unless payload
39
57
 
@@ -58,13 +76,34 @@ module Vkit
58
76
  end
59
77
 
60
78
  def user
61
- load_payload&.dig("user")
79
+ override = env_override
80
+ return override_user(override) if override
81
+
82
+ stored_payload&.dig("user")
62
83
  end
63
84
 
64
85
  def logged_in?
65
86
  !!(endpoint && token)
66
87
  end
67
88
 
89
+ # { "endpoint", "token" } from the environment, or nil when neither
90
+ # variable is set. Exactly one of them set is a mistake worth stopping on.
91
+ def env_override
92
+ endpoint = ENV.fetch("VKIT_ENDPOINT", "").strip
93
+ token = ENV.fetch("VKIT_TOKEN", "").strip
94
+ return nil if endpoint.empty? && token.empty?
95
+
96
+ if endpoint.empty? || token.empty?
97
+ missing, given = endpoint.empty? ? %w[VKIT_ENDPOINT VKIT_TOKEN] : %w[VKIT_TOKEN VKIT_ENDPOINT]
98
+ raise Vkit::CLI::Error,
99
+ "#{given} is set but #{missing} isn't. Set both to use credentials from the environment, " \
100
+ "or unset #{given} to use your saved login."
101
+ end
102
+
103
+ notice_override(endpoint)
104
+ { "endpoint" => endpoint, "token" => token }
105
+ end
106
+
68
107
  def clear!
69
108
  case
70
109
  when mac?
@@ -77,7 +116,7 @@ module Vkit
77
116
  end
78
117
 
79
118
  def clear_token!
80
- payload = load_payload
119
+ payload = stored_payload
81
120
  return unless payload
82
121
 
83
122
  payload.delete("token")
@@ -92,7 +131,13 @@ module Vkit
92
131
  end
93
132
  end
94
133
 
134
+ # endpoint and token only; the user is looked up separately (#user),
135
+ # so reading the token never makes a network call.
95
136
  def load_payload
137
+ env_override || stored_payload
138
+ end
139
+
140
+ def stored_payload
96
141
  case
97
142
  when mac?
98
143
  mac_keychain_load
@@ -103,6 +148,17 @@ module Vkit
103
148
  end
104
149
  end
105
150
 
151
+ def override_user(override)
152
+ @override_user ||= AuthClient.new(base_url: override["endpoint"]).whoami(override["token"])
153
+ end
154
+
155
+ def notice_override(endpoint)
156
+ return if self.class.override_noticed
157
+
158
+ self.class.override_noticed = true
159
+ warn "vkit: using VKIT_ENDPOINT (#{endpoint}) and VKIT_TOKEN from the environment; your saved login is not used."
160
+ end
161
+
106
162
  def mac?
107
163
  @os =~ /darwin/
108
164
  end
@@ -58,8 +58,10 @@ module Vkit
58
58
  end
59
59
 
60
60
  # Normalization
61
+ # Unknown values (a repo with no origin remote) are left out: the
62
+ # bundle schema requires strings where they are present.
61
63
  def self.normalize_source(source)
62
- { "type" => "git" }.merge(source.transform_keys(&:to_s))
64
+ { "type" => "git" }.merge(source.transform_keys(&:to_s).compact)
63
65
  end
64
66
 
65
67
  def self.normalize_policies(policies)
@@ -163,12 +165,12 @@ module Vkit
163
165
  end
164
166
  end
165
167
 
168
+ # The control plane's methods (full, partial, hash) pass through; the
169
+ # older names map onto them. Anything else masks fully.
166
170
  def self.normalize_mask_method(method)
167
171
  case method.to_s
168
- when "redact" then "full"
169
- when "hash" then "hash"
172
+ when "full", "partial", "hash" then method.to_s
170
173
  when "truncate" then "partial"
171
- when "nullify" then "full"
172
174
  else "full"
173
175
  end
174
176
  end
data/lib/vkit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vkit
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaultkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nnamdi Ogundu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-28 00:00:00.000000000 Z
11
+ date: 2026-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor