Module: Conjur

Extended by:
Conjur
Included in:
Conjur
Defined in:
lib/conjur/log.rb,
lib/conjur/env.rb,
lib/conjur/base.rb,
lib/conjur/host.rb,
lib/conjur/role.rb,
lib/conjur/user.rb,
lib/conjur/group.rb,
lib/conjur/escape.rb,
lib/conjur/exists.rb,
lib/conjur/has_id.rb,
lib/conjur/secret.rb,
lib/conjur/core-api.rb,
lib/conjur/resource.rb,
lib/conjur/variable.rb,
lib/conjur/api/authn.rb,
lib/conjur/api/hosts.rb,
lib/conjur/api/roles.rb,
lib/conjur/api/users.rb,
lib/conjur/authn-api.rb,
lib/conjur/authz-api.rb,
lib/conjur/has_owner.rb,
lib/conjur/api/groups.rb,
lib/conjur/log_source.rb,
lib/conjur/path_based.rb,
lib/conjur/role_grant.rb,
lib/conjur-api/version.rb,
lib/conjur/api/secrets.rb,
lib/conjur/acts_as_role.rb,
lib/conjur/acts_as_user.rb,
lib/conjur/acts_as_asset.rb,
lib/conjur/api/resources.rb,
lib/conjur/api/variables.rb,
lib/conjur/has_attributes.rb,
lib/conjur/has_identifier.rb,
lib/conjur/acts_as_resource.rb,
lib/conjur/standard_methods.rb,
lib/conjur/build_from_response.rb

Overview

Logging mechanism borrowed from rest-client

Defined Under Namespace

Modules: ActsAsAsset, ActsAsResource, ActsAsRole, ActsAsUser, Authn, Authz, BuildFromResponse, Core, Escape, Exists, HasAttributes, HasId, HasIdentifier, HasOwner, LogSource, PathBased, StandardMethods Classes: API, Group, Host, InvalidToken, Resource, Role, RoleGrant, Secret, User, Variable

Constant Summary collapse

@@env_log =
create_log ENV['CONJURAPI_LOG']
@@log =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_log(param) ⇒ Object

Create a log that respond to << like a logger param can be 'stdout', 'stderr', a string (then we will log to that file) or a logger (then we return it)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/conjur/log.rb', line 10

def self.create_log param
  if param
    if param.is_a? String
      if param == 'stdout'
        stdout_logger = Class.new do
          def << obj
            STDOUT.write obj
          end
        end
        stdout_logger.new
      elsif param == 'stderr'
        stderr_logger = Class.new do
          def << obj
            STDERR.write obj
          end
        end
        stderr_logger.new
      else
        file_logger = Class.new do
          attr_writer :target_file

          def << obj
            File.open(@target_file, 'a') { |f| f.write obj }
          end
        end
        logger = file_logger.new
        logger.target_file = param
        logger
      end
    else
      param
    end
  end
end

.logObject

:nodoc:



49
50
51
# File 'lib/conjur/log.rb', line 49

def self.log # :nodoc:
  @@env_log || @@log
end

.log=(log) ⇒ Object

You can also configure logging by the environment variable CONJURAPI_LOG.



4
5
6
# File 'lib/conjur/log.rb', line 4

def self.log= log
  @@log = create_log log
end

Instance Method Details

#accountObject



8
9
10
# File 'lib/conjur/env.rb', line 8

def 
  ENV['CONJUR_ACCOUNT'] or raise "No CONJUR_ACCOUNT defined"
end

#envObject



12
13
14
# File 'lib/conjur/env.rb', line 12

def env
  ENV['CONJUR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development"
end

#service_base_portObject



4
5
6
# File 'lib/conjur/env.rb', line 4

def service_base_port
  (ENV['CONJUR_SERVICE_BASE_PORT'] || 5000 ).to_i
end

#stackObject



16
17
18
19
20
21
22
23
# File 'lib/conjur/env.rb', line 16

def stack
  ENV['CONJUR_STACK'] || case env
  when "production"
    "v3"
  else
    env
  end
end