stax-examples 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/Staxfile +2 -0
- data/lib/generators/dynamo/dynamo_generator.rb +75 -0
- data/lib/generators/dynamo/templates/dyn.rb.tt +41 -0
- data/lib/stax/examples/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24633f07dfc8e723207c73df66cc4177a4d7013f6f2d41349ce1cf8baeed28ad
|
4
|
+
data.tar.gz: 47dda42ed26b9555691b1ea2abdfcee2d6c42cd808cd668c1fe753f23017bf07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c517ecf8372a860bd62e66e0299bcea8684fa7cce6ea5e9ba5918bd3d24314953058d63e8bff6a1f7e3e8efb478d0ea5ece0570cff2670fe22842f7de1d0d5
|
7
|
+
data.tar.gz: 36a6fee26fc2421707121f4b9b45440cadc3e45184d072329312db9de295ceb20166875a55df04be8f915baea63dbe08e24fae4680e322a8680d6f29f6429cf3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stax-examples (0.0.
|
4
|
+
stax-examples (0.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -60,7 +60,7 @@ GEM
|
|
60
60
|
addressable (>= 2.3.5, < 2.6)
|
61
61
|
faraday (~> 0.8, < 1.0)
|
62
62
|
semantic (1.6.1)
|
63
|
-
stax (0.0.
|
63
|
+
stax (0.0.7)
|
64
64
|
aws-sdk (~> 2)
|
65
65
|
cfer
|
66
66
|
git_clone_url
|
data/Staxfile
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
module Stax
|
2
|
+
module Generators
|
3
|
+
class DynamoGenerator < Base
|
4
|
+
desc 'dynamo generator.'
|
5
|
+
|
6
|
+
class_option :stack, type: :string, default: nil, desc: 'stack to install table'
|
7
|
+
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
attr_accessor :stack, :table, :id, :attributes, :hash, :range
|
11
|
+
|
12
|
+
def check_args
|
13
|
+
usage! unless args.size == 1
|
14
|
+
@table = args.first
|
15
|
+
@id = "Dyn#{table.capitalize}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def ask_for_options
|
19
|
+
@stack = options[:stack] || ask('stack to use or create', default: 'dynamo')
|
20
|
+
end
|
21
|
+
|
22
|
+
def ask_for_attributes
|
23
|
+
@attributes = []
|
24
|
+
loop do
|
25
|
+
name = ask('attribute name (blank when done)?')
|
26
|
+
break if name.empty?
|
27
|
+
type = ask('attribute type?', default: 'S')
|
28
|
+
@attributes << [name, type]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def ask_for_key_schema
|
33
|
+
@hash = ask('hash key?', default: attributes[0].first)
|
34
|
+
@range = ask('range key?', default: attributes[1].first)
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_to_staxfile
|
38
|
+
append_to_file 'Staxfile', "stack :#{@stack}, include: %w[DynamoDB]\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def append_include_template
|
42
|
+
file = File.join('cf', "#{stack}.rb")
|
43
|
+
create_file file, "description 'Dynamo tables'\n" unless File.exists?(file)
|
44
|
+
append_to_file file, "include_template '#{stack}/dyn_#{table}.rb'\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_table_template
|
48
|
+
template('dyn.rb.tt', File.join('cf', stack, "dyn_#{table}.rb"))
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.banner(*args)
|
54
|
+
"#{basename} generate #{command_name} TABLENAME"
|
55
|
+
end
|
56
|
+
|
57
|
+
# see https://www.rubydoc.info/github/wycats/thor/Thor/Actions for methods
|
58
|
+
|
59
|
+
# def create_file
|
60
|
+
# create_file(filename) do
|
61
|
+
# content
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
|
65
|
+
# def create_template
|
66
|
+
# template(src, dest)
|
67
|
+
# end
|
68
|
+
|
69
|
+
# def create_dir
|
70
|
+
# empty_directory(path)
|
71
|
+
# end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
resource :<%= id %>, 'AWS::DynamoDB::Table' do
|
2
|
+
attribute_definitions [
|
3
|
+
<%- attributes.each do |a| -%>
|
4
|
+
{ AttributeName: :<%= a[0].to_sym %>, AttributeType: :<%= a[1].upcase.to_sym %> },
|
5
|
+
<%- end -%>
|
6
|
+
]
|
7
|
+
key_schema [
|
8
|
+
{ AttributeName: :<%= hash %>, KeyType: :HASH },
|
9
|
+
{ AttributeName: :<%= range %>, KeyType: :RANGE },
|
10
|
+
]
|
11
|
+
# global_secondary_indexes [
|
12
|
+
# {
|
13
|
+
# IndexName: :by_indexName,
|
14
|
+
# KeySchema: [
|
15
|
+
# { AttributeName: :indexName, KeyType: :HASH }
|
16
|
+
# ],
|
17
|
+
# Projection: {
|
18
|
+
# NonKeyAttributes: [ :a, :b ],
|
19
|
+
# ProjectionType: :INCLUDE,
|
20
|
+
# },
|
21
|
+
# ProvisionedThroughput: {
|
22
|
+
# ReadCapacityUnits: 1,
|
23
|
+
# WriteCapacityUnits: 1,
|
24
|
+
# }
|
25
|
+
# }
|
26
|
+
# ]
|
27
|
+
provisioned_throughput do
|
28
|
+
read_capacity_units 1
|
29
|
+
write_capacity_units 1
|
30
|
+
end
|
31
|
+
# stream_specification do
|
32
|
+
# stream_view_type :NEW_IMAGE
|
33
|
+
# end
|
34
|
+
SSE_specification(
|
35
|
+
SSEEnabled: true
|
36
|
+
)
|
37
|
+
tag :Stack, Fn::ref('AWS::StackName')
|
38
|
+
end
|
39
|
+
|
40
|
+
output :<%= id %>, Fn::ref(:<%= id %>), export: Fn::sub('${AWS::StackName}-<%= id %>')
|
41
|
+
output :<%= id %>Arn, Fn::get_att(:<%= id %>, :Arn), export: Fn::sub('${AWS::StackName}-<%= id %>Arn')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stax-examples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- Staxfile
|
83
|
+
- lib/generators/dynamo/dynamo_generator.rb
|
84
|
+
- lib/generators/dynamo/templates/dyn.rb.tt
|
83
85
|
- lib/generators/vpc/templates/%stack_name%.rb.tt
|
84
86
|
- lib/generators/vpc/templates/%stack_name%/endpoints.rb
|
85
87
|
- lib/generators/vpc/templates/%stack_name%/subnets.rb.tt
|