Sha256: 3dff2ab70db05118e9e62d600e541b7e3e6575dd813bf86ffd1e051627be5bc0

Contents?: true

Size: 812 Bytes

Versions: 15

Compression:

Stored size: 812 Bytes

Contents

# frozen_string_literal: true

require "service_skeleton/config_variable"

class ServiceSkeleton::ConfigVariable::URL < ServiceSkeleton::ConfigVariable
  def redact?(env)
    !!(env.has_key?(@name.to_s) && (@opts[:sensitive] || URI(env[@name.to_s] || "").password))
  end

  def redact!(env)
    if env.has_key?(@name.to_s)
      super
      uri = URI(env[@name.to_s])
      if uri.password
        uri.password = "*REDACTED*"
        env[@name.to_s] = uri.to_s
      end
    end
  end

  private

  def pluck_value(env)
    maybe_default(env) do
      begin
        v = env[@name.to_s]
        URI(v)
      rescue URI::InvalidURIError
        raise ServiceSkeleton::Error::InvalidEnvironmentError,
              "Value for #{@name} (#{v}) does not appear to be a valid URL"
      end

      v
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
service_skeleton-2.2.0 lib/service_skeleton/config_variable/url.rb
service_skeleton-2.1.0 lib/service_skeleton/config_variable/url.rb
service_skeleton-1.0.5 lib/service_skeleton/config_variable/url.rb
service_skeleton-2.0.2 lib/service_skeleton/config_variable/url.rb
service_skeleton-2.0.1 lib/service_skeleton/config_variable/url.rb
service_skeleton-2.0.0 lib/service_skeleton/config_variable/url.rb
service_skeleton-1.0.4 lib/service_skeleton/config_variable/url.rb
service_skeleton-0.0.0.1.ENOTAG lib/service_skeleton/config_variable/url.rb
service_skeleton-1.0.3 lib/service_skeleton/config_variable/url.rb
service_skeleton-1.0.2 lib/service_skeleton/config_variable/url.rb
service_skeleton-1.0.1 lib/service_skeleton/config_variable/url.rb
service_skeleton-0.0.0.49.g47046b9 lib/service_skeleton/config_variable/url.rb
service_skeleton-0.0.0.48.g4a40599 lib/service_skeleton/config_variable/url.rb
service_skeleton-0.0.0.44.g75d07d7 lib/service_skeleton/config_variable/url.rb
service_skeleton-0.0.0.43.g678698a lib/service_skeleton/config_variable/url.rb