aws-sdk-rails 2.0.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ Description:
2
+ rails generator for aws-record models
3
+
4
+ Pass the name of the model (preferably in singular form), and an optional list of attributes
5
+
6
+ Attributes are declarations of the fields that you wish to store within a model. You can pass
7
+ a type and list of options for each attribtue in the form: `name:type:options` if you do not provide
8
+ a type, it is assumed that the attribute is of type `string_attr`
9
+
10
+ Each model should have an hkey, if one is not present a `uuid:hkey` will be created for you.
11
+
12
+ Timestamps are not added by default but you can add them using the `--timestamps` flag
13
+ More information can be found at: https://github.com/awslabs/aws-record-generator/blob/master/README.md
14
+
15
+ You don't have to think up every attribute up front, but it helps to
16
+ sketch out a few so you can start working with the resource immediately.
17
+
18
+ Example:
19
+ rails generate aws_record:model Forum forum_uuid:hkey post_id:rkey post_title post_body tags:sset:default_value{Set.new} created_at:datetime:d_attr_name{PostCreatedAtTime} moderation:boolean:default_value{false}
20
+
21
+ This will create:
22
+ app/models/forum.rb
23
+ db/table_config/forum_config.rb
24
+ lib/tasks/table_config_migrate_task.rake # This is created once the first time the generator is run
@@ -0,0 +1,21 @@
1
+ require_relative '../base'
2
+
3
+ module AwsRecord
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ def initialize(args, *options)
7
+ self.class.source_root File.expand_path('../templates', __FILE__)
8
+ super
9
+ end
10
+
11
+ def create_model
12
+ template "model.rb", File.join("app/models", class_path, "#{file_name}.rb")
13
+ end
14
+
15
+ def create_table_config
16
+ template "table_config.rb", File.join("db/table_config", class_path, "#{file_name}_config.rb") if options["table_config"]
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require 'aws-record'
2
+ <% if has_validations? -%>
3
+ require 'active_model'
4
+ <% end -%>
5
+
6
+ <% module_namespacing do -%>
7
+ class <%= class_name %>
8
+ include Aws::Record
9
+ <% if options.key? :scaffold -%>
10
+ extend ActiveModel::Naming
11
+ <% end -%>
12
+ <% if has_validations? -%>
13
+ include ActiveModel::Validations
14
+ <% end -%>
15
+ <% if options.key? :password_digest -%>
16
+ include ActiveModel::SecurePassword
17
+ <% end -%>
18
+ <% if mutation_tracking_disabled? -%>
19
+ disable_mutation_tracking
20
+ <% end -%>
21
+
22
+ <% attributes.each do |attribute| -%>
23
+ <%= attribute.type %> :<%= attribute.name %><% *opts, last_opt = attribute.options.to_a %><%= ', ' if last_opt %><% opts.each do |opt| %><%= opt[0] %>: <%= opt[1] %>, <% end %><% if last_opt %><%= last_opt[0] %>: <%= last_opt[1] %><% end %>
24
+ <% end -%>
25
+ <% gsis.each do |index| %>
26
+ global_secondary_index(
27
+ :<%= index.name %>,
28
+ hash_key: :<%= index.hash_key -%>,<%- if index.range_key %>
29
+ range_key: :<%= index.range_key -%>,<%- end %>
30
+ projection: {
31
+ projection_type: <%= index.projection_type %>
32
+ }
33
+ )
34
+ <% end -%>
35
+ <% if !required_attrs.empty? -%>
36
+ validates_presence_of <% *req, last_req = required_attrs -%><% req.each do |required_validation|-%>:<%= required_validation %>, <% end -%>:<%= last_req %>
37
+ <% end -%>
38
+ <% length_validations.each do |attribute, validation| -%>
39
+ validates_length_of :<%= attribute %>, within: <%= validation %>
40
+ <% end -%>
41
+ <% if options['table_name'] -%>
42
+ set_table_name "<%= options['table_name'] %>"
43
+ <% end -%>
44
+ <% if options.key? :password_digest -%>
45
+ has_secure_password
46
+ <% end -%>
47
+ end
48
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ require 'aws-record'
2
+
3
+ module ModelTableConfig
4
+ def self.config
5
+ Aws::Record::TableConfig.define do |t|
6
+ t.model_class <%= class_name %>
7
+
8
+ t.read_capacity_units <%= primary_read_units %>
9
+ t.write_capacity_units <%= primary_write_units %>
10
+ <%- gsis.each do |index| %>
11
+ t.global_secondary_index(:<%= index.name %>) do |i|
12
+ i.read_capacity_units <%= gsi_rw_units[index.name][0] %>
13
+ i.write_capacity_units <%= gsi_rw_units[index.name][1] %>
14
+ end
15
+ <%- end -%>
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ module AwsRecord
2
+ module Generators
3
+ class SecondaryIndex
4
+
5
+ PROJ_TYPES = %w(ALL KEYS_ONLY INCLUDE)
6
+ attr_reader :name, :hash_key, :range_key, :projection_type
7
+
8
+ class << self
9
+ def parse(key_definition)
10
+ name, index_options = key_definition.split(':')
11
+ index_options = index_options.split(',') if index_options
12
+ opts = parse_raw_options(index_options)
13
+
14
+ new(name, opts)
15
+ end
16
+
17
+ private
18
+ def parse_raw_options(raw_opts)
19
+ raw_opts = [] if not raw_opts
20
+ raw_opts.map { |opt| get_option_value(opt) }.to_h
21
+ end
22
+
23
+ def get_option_value(raw_option)
24
+ case raw_option
25
+
26
+ when /hkey\{(\w+)\}/
27
+ return :hash_key, $1
28
+ when /rkey\{(\w+)\}/
29
+ return :range_key, $1
30
+ when /proj_type\{(\w+)\}/
31
+ return :projection_type, $1
32
+ else
33
+ raise ArgumentError.new("Invalid option for secondary index #{raw_option}")
34
+ end
35
+ end
36
+ end
37
+
38
+ def initialize(name, opts)
39
+ raise ArgumentError.new("You must provide a name") if not name
40
+ raise ArgumentError.new("You must provide a hash key") if not opts[:hash_key]
41
+
42
+ if opts.key? :projection_type
43
+ raise ArgumentError.new("Invalid projection type #{opts[:projection_type]}") if not PROJ_TYPES.include? opts[:projection_type]
44
+ raise NotImplementedError.new("ALL is the only projection type currently supported") if opts[:projection_type] != "ALL"
45
+ else
46
+ opts[:projection_type] = "ALL"
47
+ end
48
+
49
+ if opts[:hash_key] == opts[:range_key]
50
+ raise ArgumentError.new("#{opts[:hash_key]} cannot be both the rkey and hkey for gsi #{name}")
51
+ end
52
+
53
+ @name = name
54
+ @hash_key = opts[:hash_key]
55
+ @range_key = opts[:range_key]
56
+ @projection_type = '"' + "#{opts[:projection_type]}" + '"'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Generates a migration file for deleting and a creating a DynamoDB
3
+ sessions table, and a configuration file for the session store.
4
+
5
+ Example:
6
+ rails generate dynamo_db:session_store_migration <MIGRATION_NAME>
7
+
8
+ This will create:
9
+ db/migrate/#{VERSION}_#{MIGRATION_NAME}.rb
10
+ config/dynamo_db_session_store.yml
11
+
12
+ The migration will be run when the command rake db:migrate is run
13
+ in the command line.
@@ -0,0 +1,46 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ # This class generates a migration file for deleting and creating
4
+ # a DynamoDB sessions table.
5
+ module DynamoDb
6
+ module Generators
7
+ # Generates an ActiveRecord migration that creates and deletes a DynamoDB
8
+ # Session table.
9
+ class SessionStoreMigrationGenerator < Rails::Generators::NamedBase
10
+ include Rails::Generators::Migration
11
+
12
+ source_root File.expand_path('templates', __dir__)
13
+
14
+ # Desired name of migration class
15
+ argument :name, type: :string, default: 'create_dynamo_db_sessions_table'
16
+
17
+ # @return [Rails Migration File] migration file for creation and deletion
18
+ # of a DynamoDB session table.
19
+ def generate_migration_file
20
+ migration_template(
21
+ 'session_store_migration.rb',
22
+ "db/migrate/#{name.underscore}.rb"
23
+ )
24
+ end
25
+
26
+ def copy_sample_config_file
27
+ template(
28
+ 'dynamo_db_session_store.yml',
29
+ 'config/dynamo_db_session_store.yml'
30
+ )
31
+ end
32
+
33
+ # Next migration number - must be implemented
34
+ def self.next_migration_number(_dir = nil)
35
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
36
+ end
37
+
38
+ private
39
+
40
+ # @return [String] activerecord migration version
41
+ def migration_version
42
+ "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ # Uncomment and manipulate the key value pairs below
2
+ # in order to configure the DynamoDB Session Store Application.
3
+
4
+ # [String] The secret key for HMAC encryption. This defaults to
5
+ # `Rails.application.secret_key_base`. You can use a different key if desired.
6
+ #
7
+ # secret_key: SECRET_KEY
8
+
9
+ # [String] Session table name.
10
+ #
11
+ # table_name: Sessions
12
+
13
+ # [String] Session table hash key name.
14
+ #
15
+ # table_key: session_id
16
+
17
+ # [Boolean] Define as true or false depending on if you want a strongly
18
+ # consistent read.
19
+ # See AWS DynamoDB documentation for table consistent_read for more
20
+ # information on this setting.
21
+ #
22
+ # consistent_read: true
23
+
24
+ # [Integer] Maximum number of reads consumed per second before
25
+ # DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
26
+ # or table read_capacity for more information on this setting.
27
+ #
28
+ # read_capacity: 10
29
+
30
+ # [Integer] Maximum number of writes consumed per second before
31
+ # DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
32
+ # or table write_capacity for more information on this setting.
33
+ #
34
+ # write_capacity: 5
35
+
36
+ # [Boolean] Define as true or false depending on whether you want all errors to be
37
+ # raised up the stack.
38
+ #
39
+ # raise_errors: false
40
+
41
+ # [Integer] Maximum number of seconds earlier
42
+ # from the current time that a session was created.
43
+ # By default this is 7 days.
44
+ #
45
+ # max_age: 604800
46
+
47
+ # [Integer] Maximum number of seconds
48
+ # before the current time that the session was last accessed.
49
+ # By default this is 5 hours.
50
+ #
51
+ # max_stale: 18000
52
+
53
+ # [Boolean] Define as true or false for whether you want to enable locking
54
+ # for all accesses to session data.
55
+ #
56
+ # enable_locking: false
57
+
58
+ # [Integer] Time in milleseconds after which lock will expire.
59
+ #
60
+ # lock_expiry_time: 500
61
+
62
+ # [Integer] Time in milleseconds to wait before retrying to obtain
63
+ # lock once an attempt to obtain lock has been made and has failed.
64
+ #
65
+ # lock_retry_delay: 500
66
+
67
+ # [Integer] Maximum time in seconds to wait to acquire lock
68
+ # before giving up.
69
+ #
70
+ # lock_max_wait_time: 1
@@ -0,0 +1,9 @@
1
+ class <%= name.camelize %> < ActiveRecord::Migration[<%= migration_version %>]
2
+ def up
3
+ Aws::SessionStore::DynamoDB::Table.create_table
4
+ end
5
+
6
+ def down
7
+ Aws::SessionStore::DynamoDB::Table.delete_table
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ desc 'Run all table configs in table_config folder'
2
+ namespace :aws_record do
3
+ task migrate: :environment do
4
+ Dir[File.join('db', 'table_config', '**/*.rb')].each do |filename|
5
+ puts "running #{filename}"
6
+ require(File.expand_path(filename))
7
+
8
+ table_config = ModelTableConfig.config
9
+ table_config.migrate! unless table_config.compatible?
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ namespace 'dynamo_db' do
2
+ namespace 'session_store' do
3
+ desc 'Clean up old sessions in the Amazon DynamoDB session store table.'
4
+ task clean: :environment do
5
+ Aws::SessionStore::DynamoDB::GarbageCollection.collect_garbage
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-record
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: aws-sdk-ses
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,34 +38,115 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-sqs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sessionstore-dynamodb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: railties
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - ">="
32
74
  - !ruby/object:Gem::Version
33
- version: '3'
75
+ version: 5.2.0
34
76
  type: :runtime
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
80
  - - ">="
39
81
  - !ruby/object:Gem::Version
40
- version: '3'
41
- description: Provides helpers to integrate the AWS SDK for Ruby with Ruby on Rails.
82
+ version: 5.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: concurrent-ruby
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Integrates the AWS Ruby SDK with Ruby on Rails
42
112
  email:
43
- - alexwood@amazon.com
44
- executables: []
113
+ - mamuller@amazon.com
114
+ - alexwoo@amazon.com
115
+ executables:
116
+ - aws_sqs_active_job
45
117
  extensions: []
46
118
  extra_rdoc_files: []
47
119
  files:
120
+ - VERSION
121
+ - bin/aws_sqs_active_job
122
+ - lib/action_dispatch/session/dynamodb_store.rb
123
+ - lib/active_job/queue_adapters/amazon_sqs_adapter.rb
48
124
  - lib/aws-sdk-rails.rb
49
125
  - lib/aws/rails/mailer.rb
126
+ - lib/aws/rails/notifications.rb
127
+ - lib/aws/rails/railtie.rb
128
+ - lib/aws/rails/sqs_active_job/configuration.rb
129
+ - lib/aws/rails/sqs_active_job/executor.rb
130
+ - lib/aws/rails/sqs_active_job/job_runner.rb
131
+ - lib/aws/rails/sqs_active_job/poller.rb
132
+ - lib/generators/aws_record/base.rb
133
+ - lib/generators/aws_record/generated_attribute.rb
134
+ - lib/generators/aws_record/model/USAGE
135
+ - lib/generators/aws_record/model/model_generator.rb
136
+ - lib/generators/aws_record/model/templates/model.rb
137
+ - lib/generators/aws_record/model/templates/table_config.rb
138
+ - lib/generators/aws_record/secondary_index.rb
139
+ - lib/generators/dynamo_db/session_store_migration/USAGE
140
+ - lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb
141
+ - lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml
142
+ - lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.rb
143
+ - lib/tasks/aws_record/migrate.rake
144
+ - lib/tasks/dynamo_db/session_store.rake
50
145
  homepage: https://github.com/aws/aws-sdk-rails
51
146
  licenses:
52
- - Apache 2.0
147
+ - Apache-2.0
53
148
  metadata: {}
54
- post_install_message:
149
+ post_install_message:
55
150
  rdoc_options: []
56
151
  require_paths:
57
152
  - lib
@@ -66,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
161
  - !ruby/object:Gem::Version
67
162
  version: '0'
68
163
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.5.2
71
- signing_key:
164
+ rubygems_version: 3.0.3
165
+ signing_key:
72
166
  specification_version: 4
73
- summary: AWS SDK for Ruby Rails Plugin
167
+ summary: AWS SDK for Ruby on Rails Plugin
74
168
  test_files: []