aws-sdk-rails 3.2.1 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,129 @@
1
+ module AwsRecord
2
+ module Generators
3
+ class GeneratedAttribute
4
+
5
+ OPTS = %w(hkey rkey persist_nil db_attr_name ddb_type default_value)
6
+ INVALID_HKEY_TYPES = %i(map_attr list_attr numeric_set_attr string_set_attr)
7
+ attr_reader :name, :type
8
+ attr_accessor :options
9
+
10
+ def field_type
11
+ case @type
12
+ when :integer_attr then :number_field
13
+ when :date_attr then :date_select
14
+ when :datetime_attr then :datetime_select
15
+ when :boolean_attr then :check_box
16
+ else :text_field
17
+ end
18
+ end
19
+
20
+ class << self
21
+
22
+ def parse(field_definition)
23
+ name, type, opts = field_definition.split(':')
24
+ type = "string" if not type
25
+ type, opts = "string", type if OPTS.any? { |opt| type.include? opt }
26
+
27
+ opts = opts.split(',') if opts
28
+ type, opts = parse_type_and_options(name, type, opts)
29
+ validate_opt_combs(name, type, opts)
30
+
31
+ new(name, type, opts)
32
+ end
33
+
34
+ private
35
+
36
+ def validate_opt_combs(name, type, opts)
37
+ if opts
38
+ is_hkey = opts.key?(:hash_key)
39
+ is_rkey = opts.key?(:range_key)
40
+
41
+ raise ArgumentError.new("Field #{name} cannot be a range key and hash key simultaneously") if is_hkey && is_rkey
42
+ raise ArgumentError.new("Field #{name} cannot be a hash key and be of type #{type}") if is_hkey and INVALID_HKEY_TYPES.include? type
43
+ end
44
+ end
45
+
46
+ def parse_type_and_options(name, type, opts)
47
+ opts = [] if not opts
48
+ return parse_type(name, type), opts.map { |opt| parse_option(name, opt) }.to_h
49
+ end
50
+
51
+ def parse_option(name, opt)
52
+ case opt
53
+
54
+ when "hkey"
55
+ return :hash_key, true
56
+ when "rkey"
57
+ return :range_key, true
58
+ when "persist_nil"
59
+ return :persist_nil, true
60
+ when /db_attr_name\{(\w+)\}/
61
+ return :database_attribute_name, '"' + $1 + '"'
62
+ when /ddb_type\{(S|N|B|BOOL|SS|NS|BS|M|L)\}/i
63
+ return :dynamodb_type, '"' + $1.upcase + '"'
64
+ when /default_value\{(.+)\}/
65
+ return :default_value, $1
66
+ else
67
+ raise ArgumentError.new("You provided an invalid option for #{name}: #{opt}")
68
+ end
69
+ end
70
+
71
+ def parse_type(name, type)
72
+ case type.downcase
73
+
74
+ when "bool", "boolean"
75
+ :boolean_attr
76
+ when "date"
77
+ :date_attr
78
+ when "datetime"
79
+ :datetime_attr
80
+ when "float"
81
+ :float_attr
82
+ when "int", "integer"
83
+ :integer_attr
84
+ when "list"
85
+ :list_attr
86
+ when "map"
87
+ :map_attr
88
+ when "num_set", "numeric_set", "nset"
89
+ :numeric_set_attr
90
+ when "string_set", "s_set", "sset"
91
+ :string_set_attr
92
+ when "string"
93
+ :string_attr
94
+ else
95
+ raise ArgumentError.new("Invalid type for #{name}: #{type}")
96
+ end
97
+ end
98
+ end
99
+
100
+ def initialize(name, type = :string_attr, options = {})
101
+ @name = name
102
+ @type = type
103
+ @options = options
104
+ @digest = options.delete(:digest)
105
+ end
106
+
107
+ # Methods used by rails scaffolding
108
+ def password_digest?
109
+ @digest
110
+ end
111
+
112
+ def polymorphic?
113
+ false
114
+ end
115
+
116
+ def column_name
117
+ if @name == "password_digest"
118
+ "password"
119
+ else
120
+ @name
121
+ end
122
+ end
123
+
124
+ def human_name
125
+ name.humanize
126
+ end
127
+ end
128
+ end
129
+ end
@@ -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,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
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: 3.2.1
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-13 00:00:00.000000000 Z
11
+ date: 2021-06-08 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,6 +38,20 @@ 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'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: aws-sessionstore-dynamodb
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
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'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rails
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -70,19 +112,38 @@ description: Integrates the AWS Ruby SDK with Ruby on Rails
70
112
  email:
71
113
  - mamuller@amazon.com
72
114
  - alexwoo@amazon.com
73
- executables: []
115
+ executables:
116
+ - aws_sqs_active_job
74
117
  extensions: []
75
118
  extra_rdoc_files: []
76
119
  files:
120
+ - VERSION
121
+ - bin/aws_sqs_active_job
77
122
  - lib/action_dispatch/session/dynamodb_store.rb
123
+ - lib/active_job/queue_adapters/amazon_sqs_adapter.rb
124
+ - lib/active_job/queue_adapters/amazon_sqs_async_adapter.rb
78
125
  - lib/aws-sdk-rails.rb
79
126
  - lib/aws/rails/mailer.rb
127
+ - lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb
80
128
  - lib/aws/rails/notifications.rb
81
129
  - lib/aws/rails/railtie.rb
130
+ - lib/aws/rails/sqs_active_job/configuration.rb
131
+ - lib/aws/rails/sqs_active_job/executor.rb
132
+ - lib/aws/rails/sqs_active_job/job_runner.rb
133
+ - lib/aws/rails/sqs_active_job/lambda_handler.rb
134
+ - lib/aws/rails/sqs_active_job/poller.rb
135
+ - lib/generators/aws_record/base.rb
136
+ - lib/generators/aws_record/generated_attribute.rb
137
+ - lib/generators/aws_record/model/USAGE
138
+ - lib/generators/aws_record/model/model_generator.rb
139
+ - lib/generators/aws_record/model/templates/model.rb
140
+ - lib/generators/aws_record/model/templates/table_config.rb
141
+ - lib/generators/aws_record/secondary_index.rb
82
142
  - lib/generators/dynamo_db/session_store_migration/USAGE
83
143
  - lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb
84
144
  - lib/generators/dynamo_db/session_store_migration/templates/dynamo_db_session_store.yml
85
145
  - lib/generators/dynamo_db/session_store_migration/templates/session_store_migration.rb
146
+ - lib/tasks/aws_record/migrate.rake
86
147
  - lib/tasks/dynamo_db/session_store.rake
87
148
  homepage: https://github.com/aws/aws-sdk-rails
88
149
  licenses:
@@ -103,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
164
  - !ruby/object:Gem::Version
104
165
  version: '0'
105
166
  requirements: []
106
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.2.3
107
168
  signing_key:
108
169
  specification_version: 4
109
170
  summary: AWS SDK for Ruby on Rails Plugin