xaases 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/xaases +2 -0
- data/lib/xaases/aws/lambda_js.rb +40 -0
- data/lib/xaases/cli.rb +5 -0
- data/lib/xaases/function.rb +4 -0
- data/lib/xaases/js/function.rb +16 -0
- data/lib/xaases/js.rb +50 -0
- data/lib/xaases/serverless/yaml.rb +5 -2
- data/lib/xaases/version.rb +1 -1
- metadata +6 -4
- data/event-store/events.js +0 -24
- data/event-store/serverless.yml +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3684fb4858709d60739e6cac8bcd89d268c2ca9f14dc8d764b4c48bc24ff3416
|
4
|
+
data.tar.gz: 55e17d9d5c5f8ebd3585b073834407426dc923d77d3f6b047ba944dbc83b1517
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e32dbdd2c7536960700215d6981f4f95c83e14c7107665129e3a5c759f14d277e3faa8942d72191c4072d9fe42ff059def75aeac7d8066ddbc4bc4f020bd461a
|
7
|
+
data.tar.gz: 0edc73e54643a28aad13f456afb28027a653d3b6ab62a60d812fb5639a76a0445125253985ed6934f9d32ec853f26f99c8e30bc884c2bd6be0e95be2bd970e26
|
data/Gemfile.lock
CHANGED
data/exe/xaases
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'xaases/js'
|
2
|
+
module Xaases
|
3
|
+
module Aws
|
4
|
+
class LambdaJs
|
5
|
+
def initialize
|
6
|
+
@js = Xaases::Js.new
|
7
|
+
@js.strict!
|
8
|
+
@js.const(aws: "require('aws-sdk')")
|
9
|
+
end
|
10
|
+
|
11
|
+
def use_dynamo!
|
12
|
+
@js.const(dyn: 'new aws.DynamoDB()')
|
13
|
+
end
|
14
|
+
|
15
|
+
def export(name, content)
|
16
|
+
f = Xaases::Js::Function.new(:eve, :ctx, :cb)
|
17
|
+
@js.export(name, f)
|
18
|
+
end
|
19
|
+
|
20
|
+
def res(status, content)
|
21
|
+
#err = err ? err : 'null'
|
22
|
+
body = Xaases::Js.new.hash('statusCode' => status, 'body' => content)
|
23
|
+
@js.call :callback, 'null', body
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(table, data, handler)
|
27
|
+
params = {
|
28
|
+
'TableName' => "'#{table}'",
|
29
|
+
'Item' => Xaases::Js.new.hash(data)
|
30
|
+
}
|
31
|
+
params_js = Xaases::Js.new.hash(params)
|
32
|
+
@js.call :put, params_js, handler
|
33
|
+
end
|
34
|
+
|
35
|
+
def render
|
36
|
+
@js
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/xaases/cli.rb
CHANGED
@@ -15,6 +15,11 @@ begin
|
|
15
15
|
sls.add_resource name, Xaases::Aws::Dynamodb.new(*options).to_hash
|
16
16
|
sls.write
|
17
17
|
#`sls deploy`
|
18
|
+
when 'func'
|
19
|
+
sls = Xaases::Serverless::Yaml.new('serverless.yml', 'xaases')
|
20
|
+
sls.add_function *options
|
21
|
+
sls.write
|
22
|
+
#`sls deploy`
|
18
23
|
when 'init', 'touch'
|
19
24
|
require 'xaases/cli/init'
|
20
25
|
else
|
data/lib/xaases/js.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'xaases/js/function'
|
2
|
+
module Xaases
|
3
|
+
class Js
|
4
|
+
def initialize
|
5
|
+
@s = ''
|
6
|
+
end
|
7
|
+
|
8
|
+
def strict!
|
9
|
+
@s = "'use strict';"
|
10
|
+
end
|
11
|
+
|
12
|
+
def const(list)
|
13
|
+
@s += 'const ' + list.map do |key, value|
|
14
|
+
key.to_s + '=' + value.to_s
|
15
|
+
end.join(',') + ';'
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(name, *params)
|
19
|
+
@s += "#{name}(#{params.join(',')});"
|
20
|
+
end
|
21
|
+
|
22
|
+
def hash(data)
|
23
|
+
@s += '{' + data.map do |key, value|
|
24
|
+
key.to_s + ':' + value.to_s
|
25
|
+
end.join(',') + '}'
|
26
|
+
end
|
27
|
+
|
28
|
+
def if(*conditions)
|
29
|
+
i = -1
|
30
|
+
conditions.map do |condition|
|
31
|
+
i += 1
|
32
|
+
if i == 0
|
33
|
+
'if{' + condition + '}'
|
34
|
+
elsif i == conditions.length - 1
|
35
|
+
'else{' + condition + '}'
|
36
|
+
else
|
37
|
+
'elsif{' + condition + '}'
|
38
|
+
end
|
39
|
+
end.join
|
40
|
+
end
|
41
|
+
|
42
|
+
def export(name, f)
|
43
|
+
@s += "module.exports.#{name}=(#{f.params.join(',')})=>{#{f.render}};"
|
44
|
+
end
|
45
|
+
|
46
|
+
def render
|
47
|
+
@s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -27,8 +27,11 @@ module Xaases
|
|
27
27
|
@data['resources']['Resources'][name] = rs
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
@data['functions'] =
|
30
|
+
def add_function(file, name, path, method, fn)
|
31
|
+
@data['functions'][file] = {
|
32
|
+
'handler' => "#{file}.#{name}",
|
33
|
+
'events' => [{ 'http' => { 'path' => path, 'method' => method }}]
|
34
|
+
}
|
32
35
|
end
|
33
36
|
|
34
37
|
def write
|
data/lib/xaases/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xaases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- myun2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -74,17 +74,19 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- bin/console
|
76
76
|
- bin/setup
|
77
|
-
- event-store/events.js
|
78
|
-
- event-store/serverless.yml
|
79
77
|
- exe/xaases
|
80
78
|
- lib/xaases.rb
|
81
79
|
- lib/xaases/aws.rb
|
82
80
|
- lib/xaases/aws/dynamodb.rb
|
81
|
+
- lib/xaases/aws/lambda_js.rb
|
83
82
|
- lib/xaases/cli.rb
|
84
83
|
- lib/xaases/cli/color.rb
|
85
84
|
- lib/xaases/cli/help.rb
|
86
85
|
- lib/xaases/cli/init.rb
|
87
86
|
- lib/xaases/conf.rb
|
87
|
+
- lib/xaases/function.rb
|
88
|
+
- lib/xaases/js.rb
|
89
|
+
- lib/xaases/js/function.rb
|
88
90
|
- lib/xaases/name.rb
|
89
91
|
- lib/xaases/serverless.rb
|
90
92
|
- lib/xaases/serverless/yaml.rb
|
data/event-store/events.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const AWS = require('aws-sdk'),
|
4
|
-
db = new AWS.DynamoDB(),
|
5
|
-
TABLE_NAME = 'event-store';
|
6
|
-
|
7
|
-
const indexQueryParams = (organization) => (
|
8
|
-
{
|
9
|
-
TableName: TABLE_NAME,
|
10
|
-
Item: event
|
11
|
-
}
|
12
|
-
);
|
13
|
-
|
14
|
-
module.exports.create = (event, context, callback) => {
|
15
|
-
console.log(event)
|
16
|
-
db.put(putParams(event), (err, data) => {
|
17
|
-
if (err) {
|
18
|
-
callback(err);
|
19
|
-
}
|
20
|
-
else {
|
21
|
-
callback(null, { statusCode: 200, body: 'OK' });
|
22
|
-
}
|
23
|
-
});
|
24
|
-
};
|
data/event-store/serverless.yml
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
service: event-store
|
2
|
-
provider:
|
3
|
-
name: aws
|
4
|
-
runtime: nodejs6.10
|
5
|
-
region: ap-northeast-1
|
6
|
-
profile: serverless-deploy
|
7
|
-
iamRoleStatements:
|
8
|
-
- Effect: Allow
|
9
|
-
Action:
|
10
|
-
- dynamodb:DescribeTable
|
11
|
-
- dynamodb:Query
|
12
|
-
- dynamodb:Scan
|
13
|
-
- dynamodb:GetItem
|
14
|
-
- dynamodb:PutItem
|
15
|
-
- dynamodb:UpdateItem
|
16
|
-
- dynamodb:DeleteItem
|
17
|
-
Resource: "arn:aws:dynamodb:ap-northeast-1:*:table/event-store*"
|
18
|
-
resources:
|
19
|
-
Resources:
|
20
|
-
ActivitiesDynamoDbTable:
|
21
|
-
Type: 'AWS::DynamoDB::Table'
|
22
|
-
Properties:
|
23
|
-
TableName: event-store
|
24
|
-
AttributeDefinitions:
|
25
|
-
-
|
26
|
-
AttributeName: resource_name
|
27
|
-
AttributeType: S
|
28
|
-
-
|
29
|
-
AttributeName: resource_id
|
30
|
-
AttributeType: S
|
31
|
-
KeySchema:
|
32
|
-
-
|
33
|
-
AttributeName: resource_name
|
34
|
-
KeyType: HASH
|
35
|
-
-
|
36
|
-
AttributeName: resource_id
|
37
|
-
KeyType: RANGE
|
38
|
-
ProvisionedThroughput:
|
39
|
-
ReadCapacityUnits: 1
|
40
|
-
WriteCapacityUnits: 1
|
41
|
-
functions:
|
42
|
-
root:
|
43
|
-
handler: events.create
|
44
|
-
events:
|
45
|
-
- http:
|
46
|
-
path: /events
|
47
|
-
method: post
|