Sha256: bc9208d1e82b8b90d8d49d60bdca60f87d96b6a0691a7f7d66d1f0c9f73bc9bb

Contents?: true

Size: 1.17 KB

Versions: 83

Compression:

Stored size: 1.17 KB

Contents

# A class for holding a secret. The main goal is to prevent the common mistake
# of accidentally logging or printing passwords or other secrets.
#
# See
# <https://github.com/jordansissel/software-patterns/blob/master/dont-log-secrets/ruby/>
# for a discussion of why this implementation is useful.
module Stud
  class Secret
    # Initialize a new secret with a given value.
    #
    # value - anything you want to keep secret from loggers, etc.
    def initialize(secret_value)
      # Redefine the 'value' method on this instance. This exposes no instance
      # variables to be accidentally leaked by things like awesome_print, etc.
      # This makes any #value call return the secret value.
      (class << self; self; end).class_eval do
        define_method(:value) { secret_value }
      end
    end # def initialize

    # Emit simply "<secret>" when printed or logged.
    def to_s
      return "<secret>"
    end # def to_s

    alias_method :inspect, :to_s

    # Get the secret value.
    def value
      # Nothing, this will be filled in by Secret.new
      # But we'll still document this so rdoc/yard know the method exists.
    end # def value
  end # class Secret
end # class Stud

Version data entries

83 entries across 79 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/secret.rb