class RestClient::Resource

@api private

Public Instance Methods

conjur_api() click to toggle source

Creates a Conjur API from this resource’s authorization header.

The new API is created using the token, so it will not be able to refresh when the token expires (after about 8 minutes). This is equivalent to creating an {Conjur::API} instance with {Conjur::API.new_from_token}.

@return {Conjur::API} the new api

# File lib/conjur/api.rb, line 73
def conjur_api
  api = Conjur::API.new_from_token token, remote_ip: remote_ip
  api
end
remote_ip() click to toggle source
# File lib/conjur/api.rb, line 95
def remote_ip
  options[:headers][:x_forwarded_for]
end
to_json(options = {}) click to toggle source

@api private This method exists so that all {RestClient::Resource}s support JSON serialization. It returns an empty hash. @return [Hash] the empty hash

# File lib/conjur/api.rb, line 62
def to_json(options = {})
  {}
end
token() click to toggle source

Get an authentication token from the clients Authorization header.

Useful fields in the token include ‘“data”`, which holds the username for which the token was issued, and `“timestamp”`, which contains the time at which the token was issued. The token will expire 8 minutes after timestamp, but we recommend you treat the lifespan as about 5 minutes to account for time differences.

@return [Hash] the parsed authentication token

# File lib/conjur/api.rb, line 86
def token
  authorization = options[:headers][:authorization]
  if authorization && authorization.to_s[/^Token token="(.*)"/]
    JSON.parse(Base64.decode64($1))
  else
    raise AuthorizationError.new("Authorization missing")
  end
end
username() click to toggle source

The username this resource authenticates as.

@return [String] the username

# File lib/conjur/api.rb, line 102
def username
  options[:user] || options[:username]
end