Module: BellaBaxter

Defined in:
lib/bella_baxter.rb,
lib/bella_baxter/e2ee.rb,
lib/bella_baxter/client.rb,
lib/bella_baxter/errors.rb,
lib/bella_baxter/models.rb,
lib/bella_baxter/railtie.rb,
lib/bella_baxter/version.rb,
lib/bella_baxter/webhook_signature.rb,
lib/bella_baxter/hmac_auth_provider.rb,
lib/bella_baxter/e2ee_faraday_middleware.rb

Defined Under Namespace

Modules: E2EE, WebhookSignature Classes: AllSecretsResponse, ApiError, Client, Configuration, ConfigurationError, DecryptionError, E2EEFaradayMiddleware, Error, HmacAuthProvider, InvalidApiKeyError, Railtie, SecretsVersionResponse, TotpKeyInfo, WebhookSignatureError

Constant Summary collapse

VERSION =
"0.1.1-preview.50"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Optional global configuration. When set, BellaBaxter.client uses it instead of ENV vars.



16
17
18
# File 'lib/bella_baxter.rb', line 16

def configuration
  @configuration
end

Class Method Details

.auto_load_from_env!Object

Called automatically by the Rails Railtie before_configuration hook. Silently skips if BELLA_API_KEY is not set (no-op in dev without Bella).



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bella_baxter.rb', line 45

def auto_load_from_env!
  return unless ENV["BELLA_API_KEY"]

  c = config_from_env
  if c.baxter_url.empty?
    logger.warn "[BellaBaxter] BELLA_API_KEY set but BELLA_BAXTER_URL missing — skipping"
    return
  end

  begin
    client = Client.new(config: c, private_key: ENV["BELLA_BAXTER_PRIVATE_KEY"])
    count  = client.load_into_env!
    ctx    = client.key_context
    logger.info "[BellaBaxter] Loaded #{count} secret(s) into ENV " \
                "(project=#{ctx['projectSlug']} env=#{ctx['environmentSlug']})"
  rescue BellaBaxter::Error => e
    logger.warn "[BellaBaxter] Failed to load secrets: #{e.message}"
  end
end

.clientBellaBaxter::Client

Returns a singleton client built from the global configuration.

Returns:



31
32
33
# File 'lib/bella_baxter.rb', line 31

def client
  @client ||= Client.new(config: configuration || config_from_env)
end

.configure {|configuration| ... } ⇒ Object

Yields:



18
19
20
21
22
23
24
25
26
27
# File 'lib/bella_baxter.rb', line 18

def configure
  self.configuration ||= Configuration.new(
    baxter_url:   ENV.fetch("BELLA_BAXTER_URL", ""),
    api_key:      ENV.fetch("BELLA_API_KEY", ""),
    project:      ENV.fetch("BELLA_PROJECT", ""),
    environment:  ENV.fetch("BELLA_ENV", "")
  )
  yield configuration
  self
end

.load_into_env!(overwrite: false) ⇒ Integer

Shorthand: fetch all secrets and inject into ENV. Existing ENV values are NOT overwritten unless overwrite: true.

Returns:

  • (Integer)

    number of secrets injected



39
40
41
# File 'lib/bella_baxter.rb', line 39

def load_into_env!(overwrite: false)
  client.load_into_env!(overwrite: overwrite)
end