Class: AWS::SessionStore::DynamoDB::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/session_store/dynamo_db/configuration.rb

Overview

This class provides a Configuration object for all DynamoDB transactions by pulling configuration options from Runtime, a YAML file, the ENV and default settings.

Environment Variables

The Configuration object can load default values from your environment. An example of setting and environment variable is below:

export DYNAMO_DB_SESSION_TABLE_NAME='Sessions'

Handling Errors

There are two configurable options for error handling: :raise_errors and :error_handler.

If you would like to use the Default Error Handler, you can decide to set :raise_errors to true or false depending on whether you want all errors, regadless of class, to be raised up the stack and essentially throw a 500.

If you decide to use your own Error Handler. You may pass it in for the value of the key :error_handler as a cofniguration object. You must implement the BaseErrorHandler class.

Locking Strategy

By default, locking is not implemented for the session store. You must trigger the locking strategy through the configuration of the session store. Pessimistic locking, in this case, means that only one read can be made on a session at once. While the session is being read by the process with the lock, other processes may try to obtain a lock on the same session but will be blocked. See the accessors with lock in their name for how to configure the pessimistic locking strategy to your needs.

DynamoDB Specific Options

You may configure the table name and table hash key value of your session table with the :table_name and :table_key options. You may also configure performance options for your table with the :consistent_read, :read_capacity, write_capacity. For more information about these configurations see CreateTable method for Amazon DynamoDB.

See Also:

  • Interface for Error Handling for DynamoDB Session Store.

Constant Summary collapse

DEFAULTS =

Default configuration options

{
  :table_name => "sessions",
  :table_key => "session_id",
  :consistent_read => true,
  :read_capacity => 10,
  :write_capacity => 5,
  :raise_errors => false,
  # :max_age => 7*3600*24,
  # :max_stale => 3600*5,
  :enable_locking => false,
  :lock_expiry_time => 500,
  :lock_retry_delay => 500,
  :lock_max_wait_time => 1,
  :secret_key => nil,
  :api_version => '2012-08-10'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Provides configuration object that allows access to options defined during Runtime, in a YAML file, in the ENV and by default.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :table_name (String) — default: "Sessions"

    Name of the session table.

  • :table_key (String) — default: "id"

    The hash key of the sesison table.

  • :consistent_read (Boolean) — default: true

    If true, a strongly consistent read is used. If false, an eventually consistent read is used.

  • :read_capacity (Integer) — default: 10

    The maximum number of strongly consistent reads consumed per second before DynamoDB raises a ThrottlingException. See AWS DynamoDB documentation for table read_capacity for more information on this setting.

  • :write_capacity (Integer) — default: 5

    The maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation for table write_capacity for more information on this setting.

  • :dynamo_db_client (DynamoDB Client) — default: AWS::DynamoDB::ClientV2

    DynamoDB client used to perform database operations inside of middleware application.

  • :raise_errors (Boolean) — default: false

    If true, all errors are raised up the stack when default ErrorHandler. If false, Only specified errors are raised up the stack when default ErrorHandler is used.

  • :error_handler (Error Handler) — default: DefaultErrorHandler

    An error handling object that handles all exceptions thrown during execution of the AWS DynamoDB Session Store Rack Middleware. For more information see the Handling Errors Section.

  • :max_age (Integer) — default: nil

    Maximum number of seconds earlier from the current time that a session was created.

  • :max_stale (Integer) — default: nil

    Maximum number of seconds before current time that session was last accessed.

  • :secret_key (String) — default: nil

    Secret key for HMAC encription.

  • :enable_locking (Integer) — default: false

    If true, a pessimistic locking strategy will be implemented for all session accesses. If false, no locking strategy will be implemented for all session accesses.

  • :lock_expiry_time (Integer) — default: 500

    Time in milliseconds after which lock expires on session.

  • :lock_retry_delay (Integer) — default: 500

    Time in milleseconds to wait before retrying to obtain lock once an attempt to obtain lock has been made and has failed.

  • :lock_max_wait_time (Integer) — default: 500

    Maximum time in seconds to wait to acquire lock before giving up.

  • :secret_key (String) — default: SecureRandom.hex(64)

    Secret key for HMAC encription.



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 184

def initialize(options = {})
  @options = default_options.merge(
  env_options.merge(
      file_options(options).merge(
        symbolize_keys(options)
       )
     )
   )
  @options = client_error.merge(@options)
  set_attributes(@options)
end

Instance Attribute Details

#consistent_readtrue, false (readonly)

See AWS DynamoDB documentation for table consistent_read for more information on this setting.

Returns:

  • (true)

    If a strongly consistent read is used

  • (false)

    If an eventually consistent read is used.



83
84
85
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 83

def consistent_read
  @consistent_read
end

#dynamo_db_clientDynamoDB Client (readonly)

Returns DynamoDB client.

Returns:

  • (DynamoDB Client)

    DynamoDB client.



102
103
104
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 102

def dynamo_db_client
  @dynamo_db_client
end

#enable_lockingtrue, false (readonly)

Returns:

  • (true)

    Pessimistic locking strategy will be implemented for all session accesses.

  • (false)

    No locking strategy will be implemented for all session accesses.



124
125
126
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 124

def enable_locking
  @enable_locking
end

#error_handlerError Handler (readonly)

Returns An error handling object that handles all exceptions thrown during execution of the AWS DynamoDB Session Store Rack Middleware. For more information see the Handling Errors Section.

Returns:

  • (Error Handler)

    An error handling object that handles all exceptions thrown during execution of the AWS DynamoDB Session Store Rack Middleware. For more information see the Handling Errors Section.



107
108
109
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 107

def error_handler
  @error_handler
end

#lock_expiry_timeInteger (readonly)

Returns Time in milleseconds after which lock will expire.

Returns:

  • (Integer)

    Time in milleseconds after which lock will expire.



127
128
129
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 127

def lock_expiry_time
  @lock_expiry_time
end

#lock_max_wait_timeInteger (readonly)

Returns Maximum time in seconds to wait to acquire lock before giving up.

Returns:

  • (Integer)

    Maximum time in seconds to wait to acquire lock before giving up.



135
136
137
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 135

def lock_max_wait_time
  @lock_max_wait_time
end

#lock_retry_delayInteger (readonly)

Returns Time in milleseconds to wait before retrying to obtain lock once an attempt to obtain lock has been made and has failed.

Returns:

  • (Integer)

    Time in milleseconds to wait before retrying to obtain lock once an attempt to obtain lock has been made and has failed.



131
132
133
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 131

def lock_retry_delay
  @lock_retry_delay
end

#max_ageInteger (readonly)

Returns Maximum number of seconds earlier from the current time that a session was created.

Returns:

  • (Integer)

    Maximum number of seconds earlier from the current time that a session was created.



111
112
113
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 111

def max_age
  @max_age
end

#max_staleInteger (readonly)

Returns Maximum number of seconds before the current time that the session was last accessed.

Returns:

  • (Integer)

    Maximum number of seconds before the current time that the session was last accessed.



115
116
117
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 115

def max_stale
  @max_stale
end

#raise_errorstrue, false (readonly)

Returns:

  • (true)

    All errors are raised up the stack when default ErrorHandler is used.

  • (false)

    Only specified errors are raised up the stack when default ErrorHandler is used.



99
100
101
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 99

def raise_errors
  @raise_errors
end

#read_capacityInteger (readonly)

Returns Maximum number of reads consumed per second before DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation for table read_capacity for more information on this setting.

Returns:

  • (Integer)

    Maximum number of reads consumed per second before DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation for table read_capacity for more information on this setting.



88
89
90
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 88

def read_capacity
  @read_capacity
end

#secret_keyString (readonly)

Returns The secret key for HMAC encryption.

Returns:

  • (String)

    The secret key for HMAC encryption.



118
119
120
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 118

def secret_key
  @secret_key
end

#table_keyString (readonly)

Returns Session table hash key name.

Returns:

  • (String)

    Session table hash key name.



77
78
79
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 77

def table_key
  @table_key
end

#table_nameString (readonly)

Returns Session table name.

Returns:

  • (String)

    Session table name.



74
75
76
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 74

def table_name
  @table_name
end

#write_capacityInteger (readonly)

Returns Maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation for table write_capacity for more information on this setting.

Returns:

  • (Integer)

    Maximum number of writes consumed per second before DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation for table write_capacity for more information on this setting.



93
94
95
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 93

def write_capacity
  @write_capacity
end

Instance Method Details

#to_hashHash

Returns The merged configuration hash.

Returns:

  • (Hash)

    The merged configuration hash.



197
198
199
# File 'lib/aws/session_store/dynamo_db/configuration.rb', line 197

def to_hash
  @options.dup
end