lex-vault 0.1.3 → 0.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.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/vault/auth/helpers/login'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Vault
8
+ module Auth
9
+ module Runners
10
+ module AppRole
11
+ include Legion::Extensions::Vault::Auth::Helpers::Login
12
+
13
+ def login(role_id:, secret_id:, mount: 'approle', **)
14
+ vault_normalize(vault_login(mount: mount,
15
+ body: { role_id: role_id, secret_id: secret_id },
16
+ **))
17
+ end
18
+
19
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
20
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/vault/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Vault
8
+ module Auth
9
+ module Runners
10
+ module Token
11
+ include Legion::Extensions::Vault::Helpers::Client
12
+
13
+ def validate(token:, **)
14
+ vault_normalize(connection(token: token, **).post('/v1/auth/token/lookup', { token: token }).body)
15
+ end
16
+
17
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
18
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/vault/auth/helpers/login'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Vault
8
+ module Auth
9
+ module Runners
10
+ module UserPass
11
+ include Legion::Extensions::Vault::Auth::Helpers::Login
12
+
13
+ def login(username:, password:, mount: 'ldap', **)
14
+ vault_normalize(vault_login(mount: mount,
15
+ body: { username: username, password: password },
16
+ **))
17
+ end
18
+
19
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
20
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/vault/auth/helpers/login'
4
+ require 'legion/extensions/vault/auth/runners/token'
5
+ require 'legion/extensions/vault/auth/runners/user_pass'
6
+ require 'legion/extensions/vault/auth/runners/app_role'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module Vault
11
+ module Auth
12
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core, false
13
+
14
+ # Declared independently of the root Vault extension: singleton
15
+ # methods do not cross nested module boundaries. Same rationale —
16
+ # no AMQP/meta-actor dispatch surface for the auth runners.
17
+ def self.remote_invocable?
18
+ false
19
+ end
20
+
21
+ def self.default_settings
22
+ {
23
+ runners: {
24
+ token: { desc: 'Validate a Vault token' },
25
+ user_pass: { desc: 'LDAP login (username/password)' },
26
+ app_role: { desc: 'AppRole login (role_id/secret_id)' }
27
+ }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,6 +7,7 @@ require 'legion/extensions/vault/runners/token'
7
7
  require 'legion/extensions/vault/runners/transit'
8
8
  require 'legion/extensions/vault/runners/pki'
9
9
  require 'legion/extensions/vault/runners/leases'
10
+ require 'legion/extensions/vault/runners/namespaces'
10
11
 
11
12
  module Legion
12
13
  module Extensions
@@ -21,14 +22,23 @@ module Legion
21
22
  include Runners::Leases
22
23
  include Runners::Namespaces
23
24
 
25
+ # The dynamic engines (Consul/Nomad) and the auth runners are not
26
+ # mixed in: they share generic method names (create_role/login, ...)
27
+ # that would shadow each other in one class. They are framework-level
28
+ # units (own meta-actors/MCP surface); standalone auth uses the
29
+ # auth: descriptor (Client.new(auth: { method: :user_pass, ... })).
30
+
24
31
  attr_reader :opts
25
32
 
26
33
  def initialize(address: 'http://127.0.0.1:8200', token: nil, namespace: nil, **extra)
27
34
  @opts = { address: address, token: token, namespace: namespace, **extra }
28
35
  end
29
36
 
30
- def connection(**override)
31
- super(**@opts.merge(override))
37
+ # Standalone base: the constructor kwargs ARE the credential context.
38
+ # Overrides Helpers::Auth#default_credentials so standalone execution
39
+ # never touches Legion::Settings (spec §7).
40
+ def default_credentials
41
+ @opts
32
42
  end
33
43
  end
34
44
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'legion/json'
5
+ require 'legion/json/helper'
6
+
7
+ module Legion
8
+ module Extensions
9
+ module Vault
10
+ module Errors
11
+ class AuthUnresolved < StandardError; end
12
+ class ReadOnlyError < StandardError; end
13
+
14
+ class APIError < StandardError
15
+ attr_reader :code
16
+
17
+ def initialize(code, message)
18
+ @code = code
19
+ super(message)
20
+ end
21
+ end
22
+
23
+ class Raiser < Faraday::Middleware
24
+ include Legion::JSON::Helper
25
+
26
+ def on_complete(env)
27
+ status = env[:status].to_i
28
+ return if status < 400
29
+
30
+ raise APIError.new(status, message_from(env[:body]))
31
+ end
32
+
33
+ private
34
+
35
+ def message_from(body)
36
+ return 'vault error' unless body.is_a?(String) && !body.empty?
37
+
38
+ parsed = json_load(body)
39
+ errors = parsed[:errors] if parsed.is_a?(Hash)
40
+ errors.is_a?(Array) && errors.first.is_a?(String) ? errors.first : 'vault error'
41
+ end
42
+ end
43
+
44
+ Faraday::Response.register_middleware(vault_raiser: Raiser)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/settings'
4
+ require 'legion/extensions/vault/errors'
5
+
6
+ module Legion
7
+ module Extensions
8
+ module Vault
9
+ module Helpers
10
+ module Auth
11
+ # Resolve credentials for a single call. Precedence: explicit token:
12
+ # > auth: descriptor > settings (spec §4.3). The returned hash is the
13
+ # complete credential context; a minted token is ephemeral (C4).
14
+ def auth_resolve(**opts)
15
+ resolved = default_credentials.merge(opts.slice(:address, :token, :namespace, :auth).compact)
16
+
17
+ return resolved if resolved[:token]
18
+
19
+ descriptor = resolved[:auth]
20
+ if descriptor.is_a?(Hash) && descriptor[:method]
21
+ runner = auth_dispatch.fetch(descriptor[:method]) do
22
+ raise Legion::Extensions::Vault::Errors::AuthUnresolved,
23
+ "unsupported auth method: #{descriptor[:method]}"
24
+ end
25
+ response = runner.login(**descriptor.except(:method),
26
+ address: resolved[:address],
27
+ namespace: resolved[:namespace])
28
+ # Vault's login envelope is contract-guaranteed: auth.client_token
29
+ # on success. The Raiser means non-2xx never reaches here.
30
+ token = response[:auth][:client_token]
31
+ unless token
32
+ raise Legion::Extensions::Vault::Errors::AuthUnresolved,
33
+ "auth method #{descriptor[:method]} returned no client_token"
34
+ end
35
+
36
+ # Ephemeral (C4): the minted token exists only in this return
37
+ # value. Nothing memoizes, caches, or retains it.
38
+ resolved[:token] = token
39
+ return resolved
40
+ end
41
+
42
+ raise Legion::Extensions::Vault::Errors::AuthUnresolved,
43
+ 'no vault credentials resolvable (token, auth descriptor, or settings)'
44
+ end
45
+
46
+ # Auth method → runner module. Lazy: no load-order fragility, and the
47
+ # set changes with deferred methods (Jwt/K8s/Tls). Direct module
48
+ # call — the same send the framework uses, minus the tasker (D2).
49
+ def auth_dispatch
50
+ {
51
+ user_pass: Legion::Extensions::Vault::Auth::Runners::UserPass,
52
+ app_role: Legion::Extensions::Vault::Auth::Runners::AppRole
53
+ }
54
+ end
55
+
56
+ # The base credential context. Pure bracket access — build_settings
57
+ # guarantees Legion::Settings[:extensions][:vault] with defaults in any
58
+ # framework context. Client overrides this to return @opts (spec §7).
59
+ def default_credentials
60
+ vault = Legion::Settings[:extensions][:vault]
61
+ { address: vault[:address], token: vault[:token], namespace: vault[:namespace] }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,20 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'legion/json'
5
+ require 'legion/json/helper'
6
+ require 'legion/extensions/vault/errors'
7
+ require 'legion/extensions/vault/helpers/auth'
4
8
 
5
9
  module Legion
6
10
  module Extensions
7
11
  module Vault
8
12
  module Helpers
9
13
  module Client
10
- def connection(address: 'http://127.0.0.1:8200', token: nil, namespace: nil, **_opts)
14
+ include Legion::JSON::Helper
15
+ include Legion::Extensions::Vault::Helpers::Auth
16
+
17
+ # Pure Faraday builder. address is required — the resolver guarantees
18
+ # presence. token: nil skips the header (the login path relies on it).
19
+ # raise_errors: false is for informational endpoints whose non-200
20
+ # statuses are data (sys/health, sys/seal-status).
21
+ def build_connection(address:, token: nil, namespace: nil, raise_errors: true)
11
22
  Faraday.new(url: address) do |conn|
12
23
  conn.request :json
13
24
  conn.response :json, content_type: /\bjson$/
25
+ conn.response :vault_raiser if raise_errors
14
26
  conn.headers['X-Vault-Token'] = token if token
15
27
  conn.headers['X-Vault-Namespace'] = namespace if namespace
16
28
  end
17
29
  end
30
+
31
+ # The only pipe entry point for runner methods: resolve credentials,
32
+ # build the connection. Runners never touch credential keys.
33
+ def connection(**)
34
+ resolved = auth_resolve(**)
35
+ build_connection(address: resolved[:address],
36
+ token: resolved[:token],
37
+ namespace: resolved[:namespace])
38
+ end
39
+
40
+ # Symbol-key round-trip (workspace invariant). Works in framework,
41
+ # spec, and standalone contexts.
42
+ def vault_normalize(thing)
43
+ json_load(json_dump(thing))
44
+ end
18
45
  end
19
46
  end
20
47
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/vault/errors'
4
+ require 'legion/extensions/vault/helpers/client'
5
+
6
+ module Legion
7
+ module Extensions
8
+ module Vault
9
+ module Runners
10
+ module Consul
11
+ include Legion::Extensions::Vault::Helpers::Client
12
+
13
+ # The Consul server's own token is a business kwarg (consul_token:) —
14
+ # it is not the Vault credential pipe's token.
15
+ # rubocop:disable-next Metrics/ParameterLists -- the Vault consul config/access schema
16
+ def configure(address:, consul_token:, scheme: 'https', ca_cert: nil, client_cert: nil, client_key: nil,
17
+ mount: 'consul', read_only: false, **)
18
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
19
+
20
+ body = { address: address, scheme: scheme, token: consul_token,
21
+ ca_cert: ca_cert, client_cert: client_cert, client_key: client_key }.compact
22
+ { status: connection(**).post("/v1/#{mount}/config/access", body).status }
23
+ end
24
+
25
+ # rubocop:disable-next Metrics/ParameterLists -- the Vault consul role schema
26
+ def create_role(name:, partition: 'default', node_identities: nil, consul_namespace: nil,
27
+ consul_roles: nil, service_identities: nil, consul_policies: nil, local: true,
28
+ ttl: '31d', max_ttl: '1y', mount: 'consul', read_only: false, **)
29
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
30
+
31
+ body = { partition: partition, node_identities: node_identities, consul_namespace: consul_namespace,
32
+ consul_roles: consul_roles, service_identities: service_identities,
33
+ consul_policies: consul_policies, local: local, ttl: ttl, max_ttl: max_ttl }.compact
34
+ { status: connection(**).post("/v1/#{mount}/roles/#{name}", body).status }
35
+ end
36
+
37
+ def read_role(name:, mount: 'consul', **)
38
+ vault_normalize(connection(**).get("/v1/#{mount}/roles/#{name}").body)
39
+ end
40
+
41
+ def list_roles(mount: 'consul', **)
42
+ vault_normalize(connection(**).get("/v1/#{mount}/roles", { list: true }).body)
43
+ end
44
+
45
+ def delete_role(name:, mount: 'consul', read_only: false, **)
46
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
47
+
48
+ { status: connection(**).delete("/v1/#{mount}/roles/#{name}").status }
49
+ end
50
+
51
+ def generate_credential(role:, mount: 'consul', **)
52
+ vault_normalize(connection(**).get("/v1/#{mount}/creds/#{role}").body)
53
+ end
54
+
55
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
56
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'legion/json'
4
+ require 'legion/extensions/vault/errors'
3
5
  require 'legion/extensions/vault/helpers/client'
4
6
 
5
7
  module Legion
@@ -10,72 +12,78 @@ module Legion
10
12
  include Legion::Extensions::Vault::Helpers::Client
11
13
 
12
14
  def read_secret(path:, mount: 'secret', version: nil, **)
13
- url = "/v1/#{mount}/data/#{path}"
14
15
  params = version ? { version: version } : {}
15
- response = connection(**).get(url, params)
16
- { result: response.body }
16
+ vault_normalize(connection(**).get("/v1/#{mount}/data/#{path}", params).body)
17
17
  end
18
18
 
19
- def write_secret(path:, data:, mount: 'secret', cas: nil, **)
20
- url = "/v1/#{mount}/data/#{path}"
19
+ def write_secret(path:, data:, mount: 'secret', cas: nil, read_only: false, **)
20
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
21
+
21
22
  body = { data: data }
22
23
  body[:options] = { cas: cas } if cas
23
- response = connection(**).post(url, body)
24
- { result: response.body }
24
+ vault_normalize(connection(**).post("/v1/#{mount}/data/#{path}", body).body)
25
25
  end
26
26
 
27
- def patch_secret(path:, data:, mount: 'secret', **)
28
- url = "/v1/#{mount}/data/#{path}"
27
+ def patch_secret(path:, data:, mount: 'secret', read_only: false, **)
28
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
29
+
29
30
  conn = connection(**)
30
31
  conn.headers['Content-Type'] = 'application/merge-patch+json'
31
- response = conn.patch(url, { data: data })
32
- { result: response.body }
32
+ # Explicit serialize: with a non-json Content-Type pre-set,
33
+ # Faraday's json middleware skips body serialization.
34
+ response = conn.patch("/v1/#{mount}/data/#{path}", json_dump({ data: data }))
35
+ vault_normalize(response.body)
33
36
  end
34
37
 
35
- def delete_secret(path:, mount: 'secret', **)
36
- response = connection(**).delete("/v1/#{mount}/data/#{path}")
37
- { result: response.status == 204 }
38
+ def delete_secret(path:, mount: 'secret', read_only: false, **)
39
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
40
+
41
+ { status: connection(**).delete("/v1/#{mount}/data/#{path}").status }
38
42
  end
39
43
 
40
- def delete_versions(path:, versions:, mount: 'secret', **)
41
- response = connection(**).post("/v1/#{mount}/delete/#{path}", { versions: versions })
42
- { result: response.status == 204 }
44
+ def delete_versions(path:, versions:, mount: 'secret', read_only: false, **)
45
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
46
+
47
+ { status: connection(**).post("/v1/#{mount}/delete/#{path}", { versions: versions }).status }
43
48
  end
44
49
 
45
- def undelete_versions(path:, versions:, mount: 'secret', **)
46
- response = connection(**).post("/v1/#{mount}/undelete/#{path}", { versions: versions })
47
- { result: response.status == 204 }
50
+ def undelete_versions(path:, versions:, mount: 'secret', read_only: false, **)
51
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
52
+
53
+ { status: connection(**).post("/v1/#{mount}/undelete/#{path}", { versions: versions }).status }
48
54
  end
49
55
 
50
- def destroy_versions(path:, versions:, mount: 'secret', **)
51
- response = connection(**).put("/v1/#{mount}/destroy/#{path}", { versions: versions })
52
- { result: response.status == 204 }
56
+ def destroy_versions(path:, versions:, mount: 'secret', read_only: false, **)
57
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
58
+
59
+ { status: connection(**).put("/v1/#{mount}/destroy/#{path}", { versions: versions }).status }
53
60
  end
54
61
 
55
62
  def list_secrets(path:, mount: 'secret', **)
56
- response = connection(**).get("/v1/#{mount}/metadata/#{path}", { list: true })
57
- { result: response.body }
63
+ vault_normalize(connection(**).get("/v1/#{mount}/metadata/#{path}", { list: true }).body)
58
64
  end
59
65
 
60
66
  def read_metadata(path:, mount: 'secret', **)
61
- response = connection(**).get("/v1/#{mount}/metadata/#{path}")
62
- { result: response.body }
67
+ vault_normalize(connection(**).get("/v1/#{mount}/metadata/#{path}").body)
63
68
  end
64
69
 
65
- def write_metadata(path:, mount: 'secret', max_versions: nil, cas_required: nil, delete_version_after: nil, **)
70
+ def write_metadata(path:, max_versions: nil, cas_required: nil, delete_version_after: nil,
71
+ mount: 'secret', read_only: false, **)
72
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
73
+
66
74
  body = { max_versions: max_versions, cas_required: cas_required,
67
75
  delete_version_after: delete_version_after }.compact
68
- response = connection(**).post("/v1/#{mount}/metadata/#{path}", body)
69
- { result: response.status == 204 }
76
+ { status: connection(**).post("/v1/#{mount}/metadata/#{path}", body).status }
70
77
  end
71
78
 
72
- def delete_metadata(path:, mount: 'secret', **)
73
- response = connection(**).delete("/v1/#{mount}/metadata/#{path}")
74
- { result: response.status == 204 }
79
+ def delete_metadata(path:, mount: 'secret', read_only: false, **)
80
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
81
+
82
+ { status: connection(**).delete("/v1/#{mount}/metadata/#{path}").status }
75
83
  end
76
84
 
77
- include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
78
- Legion::Extensions::Helpers.const_defined?(:Lex)
85
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
86
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
79
87
  end
80
88
  end
81
89
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'legion/extensions/vault/errors'
3
4
  require 'legion/extensions/vault/helpers/client'
4
5
 
5
6
  module Legion
@@ -10,28 +11,28 @@ module Legion
10
11
  include Legion::Extensions::Vault::Helpers::Client
11
12
 
12
13
  def lookup_lease(lease_id:, **)
13
- response = connection(**).put('/v1/sys/leases/lookup', { lease_id: lease_id })
14
- { result: response.body }
14
+ vault_normalize(connection(**).put('/v1/sys/leases/lookup', { lease_id: lease_id }).body)
15
15
  end
16
16
 
17
- def renew_lease(lease_id:, increment: nil, **)
17
+ def renew_lease(lease_id:, increment: nil, read_only: false, **)
18
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
19
+
18
20
  body = { lease_id: lease_id, increment: increment }.compact
19
- response = connection(**).put('/v1/sys/leases/renew', body)
20
- { result: response.body }
21
+ vault_normalize(connection(**).put('/v1/sys/leases/renew', body).body)
21
22
  end
22
23
 
23
- def revoke_lease(lease_id:, **)
24
- response = connection(**).put('/v1/sys/leases/revoke', { lease_id: lease_id })
25
- { result: response.status == 204 }
24
+ def revoke_lease(lease_id:, read_only: false, **)
25
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
26
+
27
+ { status: connection(**).put('/v1/sys/leases/revoke', { lease_id: lease_id }).status }
26
28
  end
27
29
 
28
30
  def list_leases(prefix:, **)
29
- response = connection(**).get("/v1/sys/leases/lookup/#{prefix}", { list: true })
30
- { result: response.body }
31
+ vault_normalize(connection(**).get("/v1/sys/leases/lookup/#{prefix}", { list: true }).body)
31
32
  end
32
33
 
33
- include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
34
- Legion::Extensions::Helpers.const_defined?(:Lex)
34
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
35
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
35
36
  end
36
37
  end
37
38
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'legion/extensions/vault/errors'
3
4
  require 'legion/extensions/vault/helpers/client'
4
5
 
5
6
  module Legion
@@ -10,27 +11,27 @@ module Legion
10
11
  include Legion::Extensions::Vault::Helpers::Client
11
12
 
12
13
  def list_namespaces(**)
13
- response = connection(**).get('/v1/sys/namespaces')
14
- { result: response.body }
14
+ vault_normalize(connection(**).get('/v1/sys/namespaces').body)
15
15
  end
16
16
 
17
17
  def get_namespace(name:, **)
18
- response = connection(**).get("/v1/sys/namespaces/#{name}")
19
- { result: response.body }
18
+ vault_normalize(connection(**).get("/v1/sys/namespaces/#{name}").body)
20
19
  end
21
20
 
22
- def create_namespace(name:, **)
23
- response = connection(**).post("/v1/sys/namespaces/#{name}")
24
- { result: response.body }
21
+ def create_namespace(name:, read_only: false, **)
22
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
23
+
24
+ vault_normalize(connection(**).post("/v1/sys/namespaces/#{name}").body)
25
25
  end
26
26
 
27
- def delete_namespace(name:, **)
28
- response = connection(**).delete("/v1/sys/namespaces/#{name}")
29
- { result: response.status == 204 }
27
+ def delete_namespace(name:, read_only: false, **)
28
+ raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
29
+
30
+ { status: connection(**).delete("/v1/sys/namespaces/#{name}").status }
30
31
  end
31
32
 
32
- include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
33
- Legion::Extensions::Helpers.const_defined?(:Lex)
33
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
34
+ Legion::Extensions::Helpers.const_defined?(:Lex, false)
34
35
  end
35
36
  end
36
37
  end