sumomo 0.8.3 → 0.8.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5afe976ced95ce2651431c9125cf3cb98bcb2dc2
4
- data.tar.gz: 5013187886398f934a3bd239e7daca669c0d1006
2
+ SHA256:
3
+ metadata.gz: 85ea8b9717493794761cd6651e7595ea4056994972508fd8af43965852a7a653
4
+ data.tar.gz: 5ceac9bf30af9b4e632a680bb0c414daca770b05c35ed5fd1aa29700f5227a51
5
5
  SHA512:
6
- metadata.gz: 2e869be9ae97deaa9022d783e690710a233bed41a2e0599c93b04592ade931b834943397b90da1ee7ab9eaf30b7cd422a5ed417480ff8682d65eecbbde9f2670
7
- data.tar.gz: 1fe0ba94f74065bf35148ed131a492e22d98fdb60f7e44ec47e188fc7e3467c42248c8ea4590842d1b653a0ed5a3e1b99a1476e6cdf80aa27766a6b462a32dd9
6
+ metadata.gz: cdf4b4055e84d51971a94a479830bb3cc5e8bfdab565fec391db7bca5426e720489b5a7f95e4da899c2a9ebfead5ea120e2873efb544f38c549b53584cf668f9
7
+ data.tar.gz: d819e57bec186f3e3c08a54b50f379ade66b9e9cc5e4b362ba427e0c12ac85a0ddcde969d9aa2ee89b407fd41a42c16679559a9448df92a426c2b898287d2766
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,169 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-11-05 10:31:48 +0900 using RuboCop version 0.76.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
12
+ # SupportedStylesAlignWith: keyword, variable, start_of_line
13
+ Layout/EndAlignment:
14
+ Exclude:
15
+ - 'exe/sumomo'
16
+ - 'lib/sumomo/ec2.rb'
17
+ - 'lib/sumomo/ecs.rb'
18
+
19
+ # Offense count: 3
20
+ Lint/AmbiguousBlockAssociation:
21
+ Exclude:
22
+ - 'lib/sumomo/ec2.rb'
23
+ - 'lib/sumomo/ecs.rb'
24
+
25
+ # Offense count: 2
26
+ Lint/ParenthesesAsGroupedExpression:
27
+ Exclude:
28
+ - 'lib/sumomo/api.rb'
29
+
30
+ # Offense count: 11
31
+ # Cop supports --auto-correct.
32
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
33
+ Lint/UnusedMethodArgument:
34
+ Exclude:
35
+ - 'lib/sumomo.rb'
36
+ - 'lib/sumomo/ec2.rb'
37
+
38
+ # Offense count: 3
39
+ Lint/UselessAssignment:
40
+ Exclude:
41
+ - 'exe/sumomo'
42
+ - 'lib/sumomo/ecs.rb'
43
+ - 'lib/sumomo/stack.rb'
44
+
45
+ # Offense count: 15
46
+ Metrics/AbcSize:
47
+ Max: 137
48
+
49
+ # Offense count: 10
50
+ # Configuration parameters: CountComments, ExcludedMethods.
51
+ # ExcludedMethods: refine
52
+ Metrics/BlockLength:
53
+ Max: 146
54
+
55
+ # Offense count: 1
56
+ # Configuration parameters: CountComments.
57
+ Metrics/ClassLength:
58
+ Max: 101
59
+
60
+ # Offense count: 5
61
+ Metrics/CyclomaticComplexity:
62
+ Max: 19
63
+
64
+ # Offense count: 19
65
+ # Configuration parameters: CountComments, ExcludedMethods.
66
+ Metrics/MethodLength:
67
+ Max: 213
68
+
69
+ # Offense count: 6
70
+ # Configuration parameters: CountComments.
71
+ Metrics/ModuleLength:
72
+ Max: 423
73
+
74
+ # Offense count: 9
75
+ # Configuration parameters: CountKeywordArgs.
76
+ Metrics/ParameterLists:
77
+ Max: 27
78
+
79
+ # Offense count: 6
80
+ Metrics/PerceivedComplexity:
81
+ Max: 19
82
+
83
+ # Offense count: 1
84
+ Naming/AccessorMethodName:
85
+ Exclude:
86
+ - 'lib/sumomo/ec2.rb'
87
+
88
+ # Offense count: 2
89
+ # Configuration parameters: EnforcedStyle.
90
+ # SupportedStyles: snake_case, normalcase, non_integer
91
+ Naming/VariableNumber:
92
+ Exclude:
93
+ - 'lib/sumomo/ec2.rb'
94
+
95
+ # Offense count: 2
96
+ Security/Eval:
97
+ Exclude:
98
+ - 'exe/sumomo'
99
+
100
+ # Offense count: 1
101
+ Style/CommentedKeyword:
102
+ Exclude:
103
+ - 'lib/sumomo/ecs.rb'
104
+
105
+ # Offense count: 1
106
+ # Cop supports --auto-correct.
107
+ # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
108
+ # SupportedStyles: assign_to_condition, assign_inside_condition
109
+ Style/ConditionalAssignment:
110
+ Exclude:
111
+ - 'lib/sumomo/ecs.rb'
112
+
113
+ # Offense count: 14
114
+ Style/Documentation:
115
+ Exclude:
116
+ - 'spec/**/*'
117
+ - 'test/**/*'
118
+ - 'lib/sumomo.rb'
119
+ - 'lib/sumomo/api.rb'
120
+ - 'lib/sumomo/cdn.rb'
121
+ - 'lib/sumomo/dns.rb'
122
+ - 'lib/sumomo/ec2.rb'
123
+ - 'lib/sumomo/ecs.rb'
124
+ - 'lib/sumomo/momo_extensions/resource.rb'
125
+ - 'lib/sumomo/momo_extensions/stack.rb'
126
+ - 'lib/sumomo/network.rb'
127
+ - 'lib/sumomo/stack.rb'
128
+
129
+ # Offense count: 3
130
+ # Configuration parameters: MinBodyLength.
131
+ Style/GuardClause:
132
+ Exclude:
133
+ - 'lib/sumomo.rb'
134
+ - 'sumomo.gemspec'
135
+
136
+ # Offense count: 5
137
+ # Cop supports --auto-correct.
138
+ Style/IfUnlessModifier:
139
+ Exclude:
140
+ - 'lib/sumomo/ec2.rb'
141
+ - 'lib/sumomo/ecs.rb'
142
+ - 'lib/sumomo/network.rb'
143
+
144
+ # Offense count: 1
145
+ Style/MethodMissingSuper:
146
+ Exclude:
147
+ - 'lib/sumomo.rb'
148
+
149
+ # Offense count: 2
150
+ Style/MissingRespondToMissing:
151
+ Exclude:
152
+ - 'lib/sumomo.rb'
153
+ - 'lib/sumomo/api.rb'
154
+
155
+ # Offense count: 1
156
+ # Cop supports --auto-correct.
157
+ # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
158
+ # SupportedStyles: predicate, comparison
159
+ Style/NumericPredicate:
160
+ Exclude:
161
+ - 'spec/**/*'
162
+ - 'lib/sumomo/ec2.rb'
163
+
164
+ # Offense count: 71
165
+ # Cop supports --auto-correct.
166
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
167
+ # URISchemes: http, https
168
+ Metrics/LineLength:
169
+ Max: 153
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in sumomo.gemspec
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "sumomo"
4
+ require 'bundler/setup'
5
+ require 'sumomo'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "sumomo"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -1 +1 @@
1
- data/sumomo/api_modules/node_modules/.bin/../uuid/bin/uuid
1
+ ../uuid/bin/uuid
@@ -75,11 +75,47 @@ function Storage()
75
75
  });
76
76
  }
77
77
 
78
+ this.list = function(prefix, start_after, onComplete, onError)
79
+ {
80
+ var params = {
81
+ Bucket: "{{ BUCKET }}",
82
+ Prefix: "data/{{ STORE_PREFIX }}/" + prefix
83
+ }
84
+
85
+ if (start_after)
86
+ {
87
+ params.StartAfter = start_after;
88
+ }
89
+
90
+ s3.listObjectsV2(params, function(err, data) {
91
+ if (err)
92
+ {
93
+ if (onError)
94
+ {
95
+ onError(err);
96
+ }
97
+ }
98
+ else
99
+ {
100
+ if (onComplete)
101
+ {
102
+ onComplete(data.Contents.map(function(x){ return x.Key; }));
103
+ }
104
+ }
105
+ });
106
+ }
107
+
78
108
  return this;
79
109
  }
80
110
 
81
111
  var Store = new Storage();
82
112
 
113
+ function decode_component(str) {
114
+ str = str.replace(/\+/g, '%20');
115
+ str = decodeURIComponent(str);
116
+ return str;
117
+ }
118
+
83
119
  function parseQuery(queryString) {
84
120
  try
85
121
  {
@@ -91,7 +127,7 @@ function parseQuery(queryString) {
91
127
  var pairs = queryString.split('&');
92
128
  for (var i = 0; i < pairs.length; i++) {
93
129
  var pair = pairs[i].split('=');
94
- query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
130
+ query[decode_component(pair[0])] = decode_component(pair[1] || '');
95
131
  }
96
132
  return query;
97
133
  }
@@ -12,50 +12,81 @@ var fs = require('fs')
12
12
  // Simulated store
13
13
  function Storage()
14
14
  {
15
- var store = {}
16
-
17
- try
18
- {
19
- var store_contents = fs.readFileSync(".store")
20
- store = JSON.parse(store_contents)
21
- }
22
- catch (e)
23
- {
24
- console.log("Error reading .store; will start with blank store")
25
- console.log(e)
26
- }
27
-
28
- this.get = function(key, onComplete, onError)
29
- {
30
- if (store[key] === undefined)
31
- {
32
- if (onError)
33
- {
34
- onError({err: "no_such_key"});
35
- }
36
- }
37
- else
38
- {
39
- if (onComplete)
40
- {
41
- onComplete(store[key]);
42
- }
43
- }
44
- }
45
-
46
- this.set = function(key, value, onComplete, onError)
47
- {
48
- store[key] = value;
49
- fs.writeFile(".store", JSON.stringify(store), function()
50
- {
51
- if (onComplete)
52
- {
53
- onComplete(key);
54
- }
55
- })
56
- }
57
-
58
- return this;
15
+ var store = {}
16
+
17
+ try
18
+ {
19
+ var store_contents = fs.readFileSync(".store")
20
+ store = JSON.parse(store_contents)
21
+ }
22
+ catch (e)
23
+ {
24
+ console.log("Error reading .store; will start with blank store")
25
+ console.log(e)
26
+ }
27
+
28
+ this.get = function(key, onComplete, onError)
29
+ {
30
+ if (store[key] === undefined)
31
+ {
32
+ if (onError)
33
+ {
34
+ onError({err: "no_such_key"});
35
+ }
36
+ }
37
+ else
38
+ {
39
+ if (onComplete)
40
+ {
41
+ onComplete(store[key]);
42
+ }
43
+ }
44
+ }
45
+
46
+ this.set = function(key, value, onComplete, onError)
47
+ {
48
+ store[key] = value;
49
+ fs.writeFile(".store", JSON.stringify(store), function()
50
+ {
51
+ if (onComplete)
52
+ {
53
+ onComplete(key);
54
+ }
55
+ })
56
+ }
57
+
58
+ this.list = function(prefix, start_after, onComplete, onError)
59
+ {
60
+ var result = [];
61
+ var start = true;
62
+ if (start_after)
63
+ {
64
+ start = false;
65
+ }
66
+ var count = 0;
67
+ var keys = Object.keys(store);
68
+ for (var i in keys)
69
+ {
70
+ var x = keys[i];
71
+ if (x === start_after)
72
+ {
73
+ start = true;
74
+ }
75
+
76
+ if (start && x.indexOf(prefix) === 0)
77
+ {
78
+ result.push(x);
79
+ count += 1;
80
+ }
81
+ };
82
+
83
+ if (onComplete)
84
+ {
85
+ onComplete(result);
86
+ }
87
+ }
88
+
89
+ return this;
59
90
  }
60
91
 
61
92
  var Store = new Storage();
@@ -66,34 +97,40 @@ var response_sent = false;
66
97
 
67
98
  var server = http.createServer(function(req, res) {
68
99
 
69
- var request = {
70
- _native_req: req,
71
- url: req.url,
72
- method: req.method,
73
- params: {}
74
- }
100
+ var request = {
101
+ _native_req: req,
102
+ url: req.url,
103
+ method: req.method,
104
+ params: {}
105
+ }
75
106
 
76
- router(request, res, function(err) {
107
+ router(request, res, function(err) {
77
108
 
78
- res.statusCode = 404;
79
- res.end(JSON.stringify({message: "File not found"}));
80
- });
109
+ res.statusCode = 404;
110
+ res.end(JSON.stringify({message: "File not found"}));
111
+ });
81
112
  });
82
113
 
114
+ function decode_component(str) {
115
+ str = str.replace(/\+/g, '%20');
116
+ str = decodeURIComponent(str);
117
+ return str;
118
+ }
119
+
83
120
  function parseQuery(queryString) {
84
- try
85
- {
86
- var res = JSON.parse(queryString)
87
- return res;
88
- }
89
- catch(e) { }
90
- var query = {};
91
- var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
92
- for (var i = 0; i < pairs.length; i++) {
93
- var pair = pairs[i].split('=');
94
- query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
95
- }
96
- return query;
121
+ try
122
+ {
123
+ var res = JSON.parse(queryString)
124
+ return res;
125
+ }
126
+ catch(e) { }
127
+ var query = {};
128
+ var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
129
+ for (var i = 0; i < pairs.length; i++) {
130
+ var pair = pairs[i].split('=');
131
+ query[decode_component(pair[0])] = decode_component(pair[1] || '');
132
+ }
133
+ return query;
97
134
  }
98
135
 
99
136
  {{ SCRIPT }}
@@ -101,114 +138,114 @@ function parseQuery(queryString) {
101
138
  // Simulate API Gateway Lambda Proxy Event
102
139
  function prepare(handler)
103
140
  {
104
- return function(request, res)
105
- {
106
- var body = [];
107
- var req = request._native_req;
108
-
109
- function callback(exception, response)
110
- {
111
- if (response.headers)
112
- {
113
- for (var key in response.headers)
114
- {
115
- res.setHeader(key, response.headers[key]);
116
- }
117
- }
118
- res.statusCode = response.statusCode || 404;
119
- res.end(response.body || null);
120
- }
121
-
122
- req.on('data', function(chunk) {
123
- body.push(chunk);
124
-
125
- }).on('end', function() {
126
-
127
- var completed_body = Buffer.concat(body).toString();
128
-
129
- var parsed_url = url.parse(req.url, true);
130
-
131
- var headers = {};
132
-
133
- headers["Accept"] = "*/*";
134
- headers["CloudFront-Forwarded-Proto"] = "https";
135
- headers["CloudFront-Is-Desktop-Viewer"] = "true";
136
- headers["CloudFront-Is-Mobile-Viewer"] = "false";
137
- headers["CloudFront-Is-SmartTV-Viewer"] = "false";
138
- headers["CloudFront-Is-Tablet-Viewer"] = "false";
139
- headers["CloudFront-Viewer-Country"] = "US";
140
- headers["Content-Type"] = "";
141
- headers["Host"] = "";
142
- headers["User-Agent"] = "";
143
- headers["Via"] = "1.1 1234567890abcdefghijklmnopqrstuv.cloudfront.net (CloudFront)";
144
- headers["X-Amz-Cf-Id"] = "0000000000000000000000000-000000000-000000000000000000==";
145
- headers["X-Amzn-Trace-Id"] = "Root=1-00000000-ffffffffffffffffffffffff";
146
- headers["X-Forwarded-For"] = req.connection.remoteAddress;
147
- headers["X-Forwarded-Port"] = "443";
148
- headers["X-Forwarded-Proto"] = "https";
149
-
150
- for(var key in req.headers)
151
- {
152
- var uppercased = key.replace(/(^|-)[a-z]/g, function(text){ return text.toUpperCase(); });
153
-
154
- headers[uppercased] = req.headers[key];
155
- }
156
-
157
- var request_event = {
158
- resource: "/{proxy+}",
159
- path: parsed_url.pathname,
160
- httpMethod: req.method,
161
- headers: headers,
162
- queryStringParameters: url.parse(req.url, true).query,
163
- pathParameters: request.params,
164
- stageVariables: null,
165
- requestContext: {
166
- path: parsed_url.pathname,
167
- accountId: "000000000000",
168
- resourceId: "123abc",
169
- stage: "test",
170
- requestId: "00000000-0000-0000-0000-000000000000",
171
- identity: {
172
- cognitoIdentityId: null,
173
- accountId: null,
174
- cognitoIdentityId: null,
175
- caller: null,
176
- apiKey: "",
177
- sourceIp: req.connection.remoteAddress,
178
- accessKey: null,
179
- cognitoAuthenticationType: null,
180
- cognitoAuthenticationProvider: null,
181
- userArn: null,
182
- userAgent: headers["User-Agent"],
183
- user: null
184
-
185
- },
186
- resourcePath: "/{proxy+}",
187
- httpMethod: req.method,
188
- apiId: "12345abcde"
189
- },
190
-
191
- body: completed_body,
192
- isBase64Encoded: false
193
-
194
- };
195
-
196
- req._native_req = undefined;
197
-
198
- try
199
- {
200
- handler(request_event, callback);
201
- }
202
- catch (e)
203
- {
204
- console.log(e);
205
- callback(e, {
206
- statusCode: 500,
207
- body: JSON.stringify({message: "Internal Server Error"}, null, 2)
208
- });
209
- }
210
- });
211
- };
141
+ return function(request, res)
142
+ {
143
+ var body = [];
144
+ var req = request._native_req;
145
+
146
+ function callback(exception, response)
147
+ {
148
+ if (response.headers)
149
+ {
150
+ for (var key in response.headers)
151
+ {
152
+ res.setHeader(key, response.headers[key]);
153
+ }
154
+ }
155
+ res.statusCode = response.statusCode || 404;
156
+ res.end(response.body || null);
157
+ }
158
+
159
+ req.on('data', function(chunk) {
160
+ body.push(chunk);
161
+
162
+ }).on('end', function() {
163
+
164
+ var completed_body = Buffer.concat(body).toString();
165
+
166
+ var parsed_url = url.parse(req.url, true);
167
+
168
+ var headers = {};
169
+
170
+ headers["Accept"] = "*/*";
171
+ headers["CloudFront-Forwarded-Proto"] = "https";
172
+ headers["CloudFront-Is-Desktop-Viewer"] = "true";
173
+ headers["CloudFront-Is-Mobile-Viewer"] = "false";
174
+ headers["CloudFront-Is-SmartTV-Viewer"] = "false";
175
+ headers["CloudFront-Is-Tablet-Viewer"] = "false";
176
+ headers["CloudFront-Viewer-Country"] = "US";
177
+ headers["Content-Type"] = "";
178
+ headers["Host"] = "";
179
+ headers["User-Agent"] = "";
180
+ headers["Via"] = "1.1 1234567890abcdefghijklmnopqrstuv.cloudfront.net (CloudFront)";
181
+ headers["X-Amz-Cf-Id"] = "0000000000000000000000000-000000000-000000000000000000==";
182
+ headers["X-Amzn-Trace-Id"] = "Root=1-00000000-ffffffffffffffffffffffff";
183
+ headers["X-Forwarded-For"] = req.connection.remoteAddress;
184
+ headers["X-Forwarded-Port"] = "443";
185
+ headers["X-Forwarded-Proto"] = "https";
186
+
187
+ for(var key in req.headers)
188
+ {
189
+ var uppercased = key.replace(/(^|-)[a-z]/g, function(text){ return text.toUpperCase(); });
190
+
191
+ headers[uppercased] = req.headers[key];
192
+ }
193
+
194
+ var request_event = {
195
+ resource: "/{proxy+}",
196
+ path: parsed_url.pathname,
197
+ httpMethod: req.method,
198
+ headers: headers,
199
+ queryStringParameters: url.parse(req.url, true).query,
200
+ pathParameters: request.params,
201
+ stageVariables: null,
202
+ requestContext: {
203
+ path: parsed_url.pathname,
204
+ accountId: "000000000000",
205
+ resourceId: "123abc",
206
+ stage: "test",
207
+ requestId: "00000000-0000-0000-0000-000000000000",
208
+ identity: {
209
+ cognitoIdentityId: null,
210
+ accountId: null,
211
+ cognitoIdentityId: null,
212
+ caller: null,
213
+ apiKey: "",
214
+ sourceIp: req.connection.remoteAddress,
215
+ accessKey: null,
216
+ cognitoAuthenticationType: null,
217
+ cognitoAuthenticationProvider: null,
218
+ userArn: null,
219
+ userAgent: headers["User-Agent"],
220
+ user: null
221
+
222
+ },
223
+ resourcePath: "/{proxy+}",
224
+ httpMethod: req.method,
225
+ apiId: "12345abcde"
226
+ },
227
+
228
+ body: completed_body,
229
+ isBase64Encoded: false
230
+
231
+ };
232
+
233
+ req._native_req = undefined;
234
+
235
+ try
236
+ {
237
+ handler(request_event, callback);
238
+ }
239
+ catch (e)
240
+ {
241
+ console.log(e);
242
+ callback(e, {
243
+ statusCode: 500,
244
+ body: JSON.stringify({message: "Internal Server Error"}, null, 2)
245
+ });
246
+ }
247
+ });
248
+ };
212
249
  }
213
250
 
214
251
  // {{ ROUTES }}