sumomo 0.6.4 → 0.7.1
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.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/data/sumomo/api_modules/node_modules/.bin/uuid +1 -0
- data/data/sumomo/api_modules/real_script.js +72 -1
- data/data/sumomo/api_modules/test_script.js +30 -1
- data/lib/sumomo.rb +3 -2
- data/lib/sumomo/api.rb +6 -2
- data/lib/sumomo/ec2.rb +2 -2
- data/lib/sumomo/stack.rb +2 -2
- data/lib/sumomo/version.rb +1 -1
- metadata +3 -3
- data/data/sumomo/api_modules/node_modules/.bin/uuid +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af1b2093782a8048484a483a3df1f032ffe2e975
|
4
|
+
data.tar.gz: 554b97c4ed4fc116fc5923937433e0266e8db3d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba55671ca59b064cfae0773e09d9093d23bb9fbb30959aeb565b47e790d1af763b3e519ed5ec548eb7f38c3321e4bee39d4d7caa162761cd681334f73a35e676
|
7
|
+
data.tar.gz: 8b95431d9b3e5438c5e5b81675abd319b5bac7d22bde8307ef6a74388ad2400cd523460699cd4e131862f23f1017c78d464d8b39f6dadd014dca8e2530ff2f4e
|
data/README.md
CHANGED
@@ -119,6 +119,12 @@ end
|
|
119
119
|
output "APIURL", api
|
120
120
|
```
|
121
121
|
|
122
|
+
You can test your API now
|
123
|
+
|
124
|
+
```bash
|
125
|
+
$ sumomo testapi -a TestGenAPI
|
126
|
+
```
|
127
|
+
|
122
128
|
## Development
|
123
129
|
|
124
130
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1 @@
|
|
1
|
+
data/sumomo/api_modules/node_modules/.bin/../uuid/bin/uuid
|
@@ -5,10 +5,81 @@ var os = require('os');
|
|
5
5
|
var http = require('http');
|
6
6
|
var url = require('url');
|
7
7
|
var merge = require('utils-merge');
|
8
|
-
var Router = require('router')
|
8
|
+
var Router = require('router');
|
9
|
+
var aws = require("aws-sdk");
|
9
10
|
|
10
11
|
var router = Router();
|
11
12
|
|
13
|
+
// S3 store
|
14
|
+
function Storage()
|
15
|
+
{
|
16
|
+
var s3 = new aws.S3({region: "{{ REGION }}"});
|
17
|
+
|
18
|
+
this.get = function(key, onComplete, onError)
|
19
|
+
{
|
20
|
+
s3.getObject({
|
21
|
+
Bucket: "{{ BUCKET }}",
|
22
|
+
Key: "data/{{ STORE_PREFIX }}/" + key
|
23
|
+
}, function(err, data) {
|
24
|
+
if (err)
|
25
|
+
{
|
26
|
+
if (onError)
|
27
|
+
{
|
28
|
+
onError(err);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
else
|
32
|
+
{
|
33
|
+
if (onComplete)
|
34
|
+
{
|
35
|
+
try
|
36
|
+
{
|
37
|
+
var val = JSON.parse(data.Body.toString());
|
38
|
+
onComplete(val.value);
|
39
|
+
}
|
40
|
+
catch(e)
|
41
|
+
{
|
42
|
+
if (onError)
|
43
|
+
{
|
44
|
+
onError(e);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
this.set = function(key, value, onComplete, onError)
|
53
|
+
{
|
54
|
+
var val = { value: value };
|
55
|
+
|
56
|
+
s3.putObject({
|
57
|
+
Bucket: "{{ BUCKET }}",
|
58
|
+
Key: "data/{{ STORE_PREFIX }}/" + key,
|
59
|
+
Body: JSON.stringify(val)
|
60
|
+
}, function(err, data) {
|
61
|
+
if (err)
|
62
|
+
{
|
63
|
+
if (onError)
|
64
|
+
{
|
65
|
+
onError(err);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
if (onComplete)
|
71
|
+
{
|
72
|
+
onComplete(key);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
|
78
|
+
return this;
|
79
|
+
}
|
80
|
+
|
81
|
+
var Store = new Storage();
|
82
|
+
|
12
83
|
function prepare(handler)
|
13
84
|
{
|
14
85
|
return function(request, callback)
|
@@ -8,6 +8,34 @@ var url = require('url');
|
|
8
8
|
var merge = require('utils-merge');
|
9
9
|
var Router = require('router')
|
10
10
|
|
11
|
+
// Simulated store
|
12
|
+
function Storage()
|
13
|
+
{
|
14
|
+
var store = {}
|
15
|
+
|
16
|
+
this.get = function(key, onComplete, onError)
|
17
|
+
{
|
18
|
+
if (store[key] === undefined)
|
19
|
+
{
|
20
|
+
onError({err: "no_such_key"});
|
21
|
+
}
|
22
|
+
else
|
23
|
+
{
|
24
|
+
onComplete(store[key]);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
this.set = function(key, value, onComplete, onError)
|
29
|
+
{
|
30
|
+
store[key] = value;
|
31
|
+
onComplete(key);
|
32
|
+
}
|
33
|
+
|
34
|
+
return this;
|
35
|
+
}
|
36
|
+
|
37
|
+
var Store = new Storage();
|
38
|
+
|
11
39
|
var router = Router();
|
12
40
|
|
13
41
|
var response_sent = false;
|
@@ -143,4 +171,5 @@ function prepare(handler)
|
|
143
171
|
|
144
172
|
// {{ ROUTES }}
|
145
173
|
|
146
|
-
|
174
|
+
console.log("Listening on port 5000")
|
175
|
+
server.listen(5000)
|
data/lib/sumomo.rb
CHANGED
@@ -212,12 +212,13 @@ module Sumomo
|
|
212
212
|
puts "Testing API #{test_name}"
|
213
213
|
apigen = Stack::APIGenerator.new(pretty_print: pretty_print, &tester.apis[test_name])
|
214
214
|
|
215
|
-
|
215
|
+
|
216
|
+
script = File.read(File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "api_modules", "test_script.js"))
|
216
217
|
script.sub!("// {{ ROUTES }}", apigen.generate);
|
217
218
|
|
218
219
|
File.write(".test.js", script)
|
219
220
|
|
220
|
-
exec "NODE_PATH=#{File.join(Gem.
|
221
|
+
exec "NODE_PATH=#{File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "api_modules", "node_modules")} node .test.js"
|
221
222
|
end
|
222
223
|
end
|
223
224
|
|
data/lib/sumomo/api.rb
CHANGED
@@ -78,12 +78,16 @@ module Sumomo
|
|
78
78
|
Name name
|
79
79
|
end
|
80
80
|
|
81
|
-
script ||= File.read(File.join(Gem.
|
81
|
+
script ||= File.read(File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "api_modules", "real_script.js"))
|
82
82
|
|
83
83
|
apigen = APIGenerator.new(&block);
|
84
84
|
script.sub!("// {{ ROUTES }}", apigen.generate);
|
85
85
|
|
86
|
-
|
86
|
+
script.gsub!("{{ REGION }}", @region);
|
87
|
+
script.gsub!("{{ BUCKET }}", @bucket_name);
|
88
|
+
script.gsub!("{{ STORE_PREFIX }}", "functions/" + name);
|
89
|
+
|
90
|
+
module_dir = File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "api_modules")
|
87
91
|
|
88
92
|
files = Dir[File.join(module_dir, "**/*")].select{|x| File.file?(x)}.map do |x|
|
89
93
|
{ name: x.sub(/^#{module_dir}\//, ""), code: File.read(x) }
|
data/lib/sumomo/ec2.rb
CHANGED
@@ -494,8 +494,8 @@ aws ec2 associate-address --region `cat /etc/aws_region` --instance-id `curl htt
|
|
494
494
|
end
|
495
495
|
|
496
496
|
if spot_price and ec2_sns_arn
|
497
|
-
watcher = File.read( File.join( Gem.
|
498
|
-
poller = File.read( File.join( Gem.
|
497
|
+
watcher = File.read( File.join( Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "sources", "spot-watcher.sh" ) )
|
498
|
+
poller = File.read( File.join( Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "sources", "spot-watcher-poller.sh" ) )
|
499
499
|
|
500
500
|
file "/etc/init.d/spot-watcher", content: watcher, mode: "000700"
|
501
501
|
file "/bin/spot-watcher", content: poller, mode: "000700", context: {
|
data/lib/sumomo/stack.rb
CHANGED
@@ -75,7 +75,7 @@ module Sumomo
|
|
75
75
|
files:[
|
76
76
|
{
|
77
77
|
name: "index.js",
|
78
|
-
code: File.read( File.join(Gem.
|
78
|
+
code: File.read( File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "custom_resource_utils.js") ).sub("{{ CODE }}", code)
|
79
79
|
}
|
80
80
|
],
|
81
81
|
description: "CF Resource Custom::#{name}",
|
@@ -99,7 +99,7 @@ module Sumomo
|
|
99
99
|
if match
|
100
100
|
if !@custom_resources[type]
|
101
101
|
|
102
|
-
resource_function_source = File.join(Gem.
|
102
|
+
resource_function_source = File.join(Gem.loaded_specs['sumomo'].full_gem_path, "data", "sumomo", "custom_resources", "#{match[:name]}.js")
|
103
103
|
|
104
104
|
if File.exists? resource_function_source
|
105
105
|
define_custom_resource(name: match[:name], code: File.read(resource_function_source))
|
data/lib/sumomo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sumomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Siaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -2558,7 +2558,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
2558
2558
|
version: '0'
|
2559
2559
|
requirements: []
|
2560
2560
|
rubyforge_project:
|
2561
|
-
rubygems_version: 2.
|
2561
|
+
rubygems_version: 2.6.14
|
2562
2562
|
signing_key:
|
2563
2563
|
specification_version: 4
|
2564
2564
|
summary: An advanced infrastructure description language for AWS
|
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
var path = require('path');
|
4
|
-
var uuid = require(path.join(__dirname, '..'));
|
5
|
-
|
6
|
-
var arg = process.argv[2];
|
7
|
-
|
8
|
-
if ('--help' === arg) {
|
9
|
-
console.log('\n USAGE: uuid [version] [options]\n\n');
|
10
|
-
console.log(' options:\n');
|
11
|
-
console.log(' --help Display this message and exit\n');
|
12
|
-
process.exit(0);
|
13
|
-
}
|
14
|
-
|
15
|
-
if (null == arg) {
|
16
|
-
console.log(uuid());
|
17
|
-
process.exit(0);
|
18
|
-
}
|
19
|
-
|
20
|
-
if ('v1' !== arg && 'v4' !== arg) {
|
21
|
-
console.error('Version must be RFC4122 version 1 or version 4, denoted as "v1" or "v4"');
|
22
|
-
process.exit(1);
|
23
|
-
}
|
24
|
-
|
25
|
-
console.log(uuid[arg]());
|
26
|
-
process.exit(0);
|