Class: Capsium::Reactor::Deploy

Inherits:
Object
  • Object
show all
Defined in:
lib/capsium/reactor/deploy.rb,
sig/capsium/reactor/deploy.rbs

Overview

Reactor-side deployment configuration (deploy.json): everything that must NOT ship in the package — OAuth2 client secrets, the session signing secret, role assignments, an alternate htpasswd file, the public base URL.

Constant Summary collapse

FILE =

Returns:

  • (String)
"deploy.json"
ENV_VAR =

Returns:

  • (String)
"CAPSIUM_DEPLOY"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Deploy

Returns a new instance of Deploy.

Parameters:

  • config (Hash[String, untyped])


40
41
42
# File 'lib/capsium/reactor/deploy.rb', line 40

def initialize(config)
  @config = config
end

Instance Attribute Details

#configHash[String, untyped] (readonly)

Returns the value of attribute config.

Returns:

  • (Hash[String, untyped])


28
29
30
# File 'lib/capsium/reactor/deploy.rb', line 28

def config
  @config
end

Class Method Details

.load(source) ⇒ Deploy

Loads from an explicit path, an already-parsed Hash, or the CAPSIUM_DEPLOY environment variable; empty when unconfigured.

Parameters:

  • source (Hash[String, untyped], String, nil)

Returns:



15
16
17
18
19
20
21
22
23
# File 'sig/capsium/reactor/deploy.rbs', line 15

def self.load(source)
  return new(source) if source.is_a?(Hash)

  path = source || ENV.fetch(ENV_VAR, nil)
  return new({}) if path.nil? || path.to_s.empty?
  raise Error, "deploy configuration not found: #{path}" unless File.file?(path)

  new(JSON.parse(File.read(path)))
end

Instance Method Details

#authenticationHash[String, untyped]

Returns:

  • (Hash[String, untyped])


44
45
46
# File 'lib/capsium/reactor/deploy.rb', line 44

def authentication
  config["authentication"] || {}
end

#base_urlString?

Returns:

  • (String, nil)


48
49
50
# File 'lib/capsium/reactor/deploy.rb', line 48

def base_url
  config["baseUrl"]
end

#client_secretString?

Returns:

  • (String, nil)


52
53
54
# File 'lib/capsium/reactor/deploy.rb', line 52

def client_secret
  authentication.dig("oauth2", "clientSecret")
end

#passwd_fileString?

Returns:

  • (String, nil)


60
61
62
# File 'lib/capsium/reactor/deploy.rb', line 60

def passwd_file
  authentication.dig("basicAuth", "passwdFile")
end

#rolesHash[String, Array[String]]

Role assignments keyed by identity name (basic-auth username, OAuth2 email or subject): ["admin", "user"].

Returns:

  • (Hash[String, Array[String]])


66
67
68
# File 'lib/capsium/reactor/deploy.rb', line 66

def roles
  authentication["roles"] || {}
end

#session_secretString?

Returns:

  • (String, nil)


56
57
58
# File 'lib/capsium/reactor/deploy.rb', line 56

def session_secret
  authentication["sessionSecret"]
end