swaggerless 0.1.10 → 0.1.11
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 +57 -0
- data/lib/swaggerless/deployer.rb +27 -24
- data/lib/swaggerless/swaggerextractor.rb +5 -4
- data/lib/swaggerless/version.rb +1 -1
- data/lib/tasks/swaggerless.rake +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a18e0970662d5508436a06af8726f2e089267b79
|
4
|
+
data.tar.gz: 5b0c2c01580632917534d72395a498b5e2177554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c76fde123ac403e8209bacd1df3745b8f275a0b91f3c787d231ee7fa989f0bc12d2ad6df4e8a111ebf669fa84f8637d73c2a9b2c0ec267d111d2970771f9f8e
|
7
|
+
data.tar.gz: c9827f1950e48f15fde341e552688fa300cf3a343d53b32b8b23d0804e5fe8e2b8e0cdaa97f781279776b6fb3f1e2b668ebd4cb3293334a5e0edb29117c9735f
|
data/README.md
CHANGED
@@ -23,6 +23,63 @@ And then execute:
|
|
23
23
|
Or install it yourself as:
|
24
24
|
|
25
25
|
$ gem install swaggerless
|
26
|
+
|
27
|
+
## Usage for desing first microservice development
|
28
|
+
|
29
|
+
The gem was designed to be used together with Rake. It exports default taks to get you started. It can also be used with any framework.
|
30
|
+
|
31
|
+
All you need to start is the design of your service in Open API spec (Swagger). For example for an `some_endpoint`
|
32
|
+
|
33
|
+
```
|
34
|
+
/some_endpoint:
|
35
|
+
post:
|
36
|
+
produces:
|
37
|
+
- "application/json"
|
38
|
+
responses:
|
39
|
+
200:
|
40
|
+
description: "200 response"
|
41
|
+
schema:
|
42
|
+
$ref: "#/definitions/WebhookPayload"
|
43
|
+
x-amazon-lambda-name: HipchatAgileIntegrations
|
44
|
+
x-amazon-lambda-handler: lambda.handler
|
45
|
+
x-amazon-lambda-runtime: nodejs4.3
|
46
|
+
x-amazon-lambda-timeout: 10
|
47
|
+
x-amazon-apigateway-integration:
|
48
|
+
type: aws_proxy
|
49
|
+
httpMethod: POST
|
50
|
+
passthroughBehavior: when_no_match
|
51
|
+
```
|
52
|
+
|
53
|
+
As you can see apart from standard [API Gateway Extensions to Swagger](http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html) this gem will be additionally looking for:
|
54
|
+
- x-amazon-lambda-name (required)
|
55
|
+
- x-amazon-lambda-handler
|
56
|
+
- x-amazon-lambda-runtime
|
57
|
+
- x-amazon-lambda-timeout
|
58
|
+
- x-amazon-lambda-log-forwarder
|
59
|
+
|
60
|
+
Once you have that, it is time to create your Rakefile
|
61
|
+
|
62
|
+
```
|
63
|
+
require 'swaggerless'
|
64
|
+
|
65
|
+
cmd = 'cp package.json src/ && npm install --production --prefix src && rm src/package.json'
|
66
|
+
%x[ #{cmd} ]
|
67
|
+
|
68
|
+
@awsAccount = <AWS account ID>
|
69
|
+
@lambdaRoleArn = <AWS role you want to use for lambda execution>
|
70
|
+
@awsRegion = <AWS region>
|
71
|
+
```
|
72
|
+
|
73
|
+
and then calling `rake -T` should get you the following output:
|
74
|
+
|
75
|
+
```
|
76
|
+
rake swaggerless:clean # Clean
|
77
|
+
rake swaggerless:clean_aws_resources # Clean AWS resources
|
78
|
+
rake swaggerless:delete[environment] # Remove stage and cleanup
|
79
|
+
rake swaggerless:deploy[environment] # Deploys to an environment specified as parameter
|
80
|
+
rake swaggerless:package # Package the project for AWS Lambda
|
81
|
+
```
|
82
|
+
|
26
83
|
|
27
84
|
## Contributing
|
28
85
|
|
data/lib/swaggerless/deployer.rb
CHANGED
@@ -28,28 +28,30 @@ module Swaggerless
|
|
28
28
|
|
29
29
|
def deploy_authoirizers_and_update_authorizers_uri(lambda_role_arn, swagger)
|
30
30
|
lambdas_configs = @swaggerExtractor.get_lambda_map(swagger)
|
31
|
-
swagger
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
securityDefinition[
|
40
|
-
|
41
|
-
|
42
|
-
policy_name = "API_2_#{authorizer}".gsub(":","_")
|
43
|
-
begin
|
44
|
-
existing_policies = @lambda_client.get_policy(function_name: authorizer).data
|
45
|
-
existing_policy = JSON.parse(existing_policies.policy)
|
46
|
-
policy_exists = existing_policy['Statement'].select { |s| s['Sid'] == policy_name }.any?
|
47
|
-
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
31
|
+
if swagger.key?("securityDefinitions") then
|
32
|
+
swagger["securityDefinitions"].each do |securityDefinitionName, securityDefinition|
|
33
|
+
if securityDefinition[AMZ_APIGATEWAY_AUTHORIZER] != nil then
|
34
|
+
authorizer = securityDefinition[EXT_LAMBDA_NAME]
|
35
|
+
if securityDefinition[EXT_LAMBDA_NAME] and securityDefinition[EXT_LAMBDA_HANDLER] then
|
36
|
+
config = lambdas_configs[securityDefinition[EXT_LAMBDA_NAME]]
|
37
|
+
securityDefinition[AMZ_APIGATEWAY_AUTHORIZER]["authorizerUri"] =
|
38
|
+
deploy_lambda_and_attach_log_forwarder(lambda_role_arn, securityDefinition, config)
|
39
|
+
elsif securityDefinition[EXT_LAMBDA_NAME]
|
40
|
+
securityDefinition[AMZ_APIGATEWAY_AUTHORIZER]["authorizerUri"] = "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{authorizer}/invocations"
|
41
|
+
end
|
48
42
|
policy_exists = false
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
policy_name = "API_2_#{authorizer}".gsub(":","_")
|
44
|
+
begin
|
45
|
+
existing_policies = @lambda_client.get_policy(function_name: authorizer).data
|
46
|
+
existing_policy = JSON.parse(existing_policies.policy)
|
47
|
+
policy_exists = existing_policy['Statement'].select { |s| s['Sid'] == policy_name }.any?
|
48
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
49
|
+
policy_exists = false
|
50
|
+
end
|
51
|
+
unless policy_exists
|
52
|
+
@lambda_client.add_permission({function_name: "arn:aws:lambda:#{@region}:#{@account}:function:#{authorizer}",
|
53
|
+
statement_id: policy_name, action: "lambda:*", principal: 'apigateway.amazonaws.com'})
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -124,6 +126,7 @@ module Swaggerless
|
|
124
126
|
puts "Deploying #{function_name}"
|
125
127
|
runtime ||= 'nodejs4.3'
|
126
128
|
timeout ||= 5
|
129
|
+
permissionStatementId = Digest::SHA1.hexdigest "API_2_#{function_name}_#{@function_alias}"
|
127
130
|
begin
|
128
131
|
@lambda_client.get_alias({function_name: function_name, name: @function_alias})
|
129
132
|
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
@@ -139,7 +142,7 @@ module Swaggerless
|
|
139
142
|
end
|
140
143
|
puts "Creating alias #{@function_alias}"
|
141
144
|
alias_resp = @lambda_client.create_alias({function_name: function_name, name: @function_alias, function_version: lambda_response.version, description: "Deployment of new version on " + Time.now.inspect})
|
142
|
-
@lambda_client.add_permission({function_name: alias_resp.alias_arn, statement_id:
|
145
|
+
@lambda_client.add_permission({function_name: alias_resp.alias_arn, statement_id: permissionStatementId, action: "lambda:*", principal: 'apigateway.amazonaws.com'})
|
143
146
|
end
|
144
147
|
return "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{function_name}:#{@function_alias}/invocations"
|
145
148
|
end
|
@@ -196,8 +199,8 @@ module Swaggerless
|
|
196
199
|
puts "API available at #{url}"
|
197
200
|
return url;
|
198
201
|
rescue Aws::APIGateway::Errors::TooManyRequestsException => e
|
199
|
-
STDERR.puts 'WARNING: Got TooManyRequests response from API Gateway. Waiting
|
200
|
-
sleep(
|
202
|
+
STDERR.puts 'WARNING: Got TooManyRequests response from API Gateway. Waiting...'
|
203
|
+
sleep(5)
|
201
204
|
end
|
202
205
|
end
|
203
206
|
|
@@ -22,10 +22,11 @@ module Swaggerless
|
|
22
22
|
process_lambda_config(lambdas_map, method_config, swagger)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if swagger.key?("securityDefinitions") then
|
26
|
+
swagger["securityDefinitions"].each do |securityDefinitionName, securityDefinition|
|
27
|
+
if securityDefinition[AMZ_APIGATEWAY_AUTHORIZER] != nil
|
28
|
+
process_lambda_config(lambdas_map, securityDefinition, swagger)
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
return lambdas_map
|
data/lib/swaggerless/version.rb
CHANGED
data/lib/tasks/swaggerless.rake
CHANGED
@@ -38,6 +38,11 @@ namespace :swaggerless do
|
|
38
38
|
|
39
39
|
FileUtils.mkdir_p 'output'
|
40
40
|
|
41
|
+
if not @swaggerSpecFile then
|
42
|
+
@swaggerSpecFile = 'swagger.yaml'
|
43
|
+
STDERR.puts("Swagger file not configured. Trying default ('#{@swaggerSpecFile}'). Set @swaggerSpecFile to point to swagger yaml file if you use different file name")
|
44
|
+
end
|
45
|
+
|
41
46
|
if not @packageDir then
|
42
47
|
@packageDir = 'src'
|
43
48
|
STDERR.puts("Package directory not configured. Trying default ('#{@packageDir}'). Set @packageDir to point to the directory that should be packaged for AWS Lambda")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swaggerless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafal Nowosielski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|