swaggerless 0.1.4 → 0.1.5
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/lib/swaggerless/deployer.rb +19 -14
- data/lib/swaggerless/swaggerextractor.rb +18 -22
- data/lib/swaggerless/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8548560a65b15f31c57f4529df4e0b98f6aceec
|
4
|
+
data.tar.gz: feb6bdc1b1bf5d0708c94451acc3c40ff0203e7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff5e011f8f121b9080bb17b1d3f2c8a5053ba94876da350e38d6cec3d40eeb0f2ce204f7b21ea51a93553728999cc0da963650a44b71f9381a76721469a42ba
|
7
|
+
data.tar.gz: 77017ee7f6560138928f12e6e972f0e524c4a81cd7d72d07dac851b2001c366eae303c0475093994ec8d8664edfb8feeeb13d0db4950e12882f5d9273d6931ca
|
data/lib/swaggerless/deployer.rb
CHANGED
@@ -13,6 +13,7 @@ module Swaggerless
|
|
13
13
|
@verbose = false;
|
14
14
|
@function_alias = get_current_package_alias
|
15
15
|
@swaggerExtractor = Swaggerless::SwaggerExtractor.new();
|
16
|
+
@lambda_client = Aws::Lambda::Client.new(region: @region)
|
16
17
|
end
|
17
18
|
|
18
19
|
def create_lambda_package(directory, outputName)
|
@@ -34,17 +35,16 @@ module Swaggerless
|
|
34
35
|
else
|
35
36
|
securityDefinition[AMZ_APIGATEWAY_AUTHORIZER]["authorizerUri"] = "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{authorizer}/invocations"
|
36
37
|
end
|
37
|
-
lambda_client = Aws::Lambda::Client.new(region: @region)
|
38
38
|
policy_exists = false
|
39
39
|
begin
|
40
|
-
existing_policies = lambda_client.get_policy(function_name: authorizer).data
|
40
|
+
existing_policies = @lambda_client.get_policy(function_name: authorizer).data
|
41
41
|
existing_policy = JSON.parse(existing_policies.policy)
|
42
42
|
policy_exists = existing_policy['Statement'].select { |s| s['Sid'] == "API_2_#{authorizer}" }.any?
|
43
43
|
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
44
44
|
policy_exists = false
|
45
45
|
end
|
46
46
|
unless policy_exists
|
47
|
-
lambda_client.add_permission({function_name: "arn:aws:lambda:#{@region}:#{@account}:function:#{authorizer}",
|
47
|
+
@lambda_client.add_permission({function_name: "arn:aws:lambda:#{@region}:#{@account}:function:#{authorizer}",
|
48
48
|
statement_id: "API_2_#{authorizer}", action: "lambda:*", principal: 'apigateway.amazonaws.com'})
|
49
49
|
end
|
50
50
|
end
|
@@ -56,7 +56,7 @@ module Swaggerless
|
|
56
56
|
deployed_operations = Hash.new
|
57
57
|
swagger["paths"].each do |path, path_config|
|
58
58
|
path_config.each do |method, method_config|
|
59
|
-
if method_config[
|
59
|
+
if method_config[EXT_LAMBDA_HANDLER] then
|
60
60
|
if deployed_operations[method_config[EXT_LAMBDA_NAME]] == nil
|
61
61
|
config = lambdas_configs[method_config[EXT_LAMBDA_NAME]]
|
62
62
|
deployed_operations[method_config[EXT_LAMBDA_NAME]] = deploy_lambda(lambda_role_arn, method_config[EXT_LAMBDA_NAME], config[:description],
|
@@ -65,7 +65,13 @@ module Swaggerless
|
|
65
65
|
puts "Updating swagger with integration uri for #{method} #{path}: #{deployed_operations[method_config[EXT_LAMBDA_NAME]]}" unless not @verbose
|
66
66
|
method_config['x-amazon-apigateway-integration']['uri'] = deployed_operations[method_config[EXT_LAMBDA_NAME]]
|
67
67
|
elsif method_config[EXT_LAMBDA_NAME] then
|
68
|
-
method_config[
|
68
|
+
if lambdas_configs[method_config[EXT_LAMBDA_NAME] == nil]
|
69
|
+
external_lambda_arn = "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{method_config[EXT_LAMBDA_NAME]}/invocations"
|
70
|
+
method_config['x-amazon-apigateway-integration']['uri'] = external_lambda_arn
|
71
|
+
puts "Adding integration to lambda that is external (#{external_lambda_arn}) to the project. Make sure to grant permissions so that API Gateway can call it."
|
72
|
+
else
|
73
|
+
method_config['x-amazon-apigateway-integration']['uri'] = "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{method_config[EXT_LAMBDA_NAME]}:#{@function_alias}/invocations"
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
@@ -75,23 +81,22 @@ module Swaggerless
|
|
75
81
|
puts "Deploying #{function_name}"
|
76
82
|
runtime ||= 'nodejs4.3'
|
77
83
|
timeout ||= 5
|
78
|
-
lambda_client = Aws::Lambda::Client.new(region: @region)
|
79
84
|
begin
|
80
|
-
lambda_client.get_alias({function_name: function_name, name: @function_alias})
|
85
|
+
@lambda_client.get_alias({function_name: function_name, name: @function_alias})
|
81
86
|
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
82
87
|
lambda_response = nil
|
83
88
|
zip_file_content = File.read(File.join(@output_path, "#{@function_alias}.zip"))
|
84
89
|
begin
|
85
|
-
lambda_client.get_function({function_name: function_name})
|
86
|
-
lambda_response = lambda_client.update_function_code({function_name: function_name, zip_file: zip_file_content, publish: true})
|
87
|
-
lambda_client.update_function_configuration({function_name: function_name, runtime: runtime, role: lambda_role_arn, handler: handler, description: summary, timeout: timeout})
|
90
|
+
@lambda_client.get_function({function_name: function_name})
|
91
|
+
lambda_response = @lambda_client.update_function_code({function_name: function_name, zip_file: zip_file_content, publish: true})
|
92
|
+
@lambda_client.update_function_configuration({function_name: function_name, runtime: runtime, role: lambda_role_arn, handler: handler, description: summary, timeout: timeout})
|
88
93
|
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
89
94
|
puts "Creating new function #{function_name}"
|
90
|
-
lambda_response = lambda_client.create_function({function_name: function_name, runtime: runtime, role: lambda_role_arn, handler: handler, code: {zip_file: zip_file_content }, description: summary, publish: true, timeout: timeout})
|
95
|
+
lambda_response = @lambda_client.create_function({function_name: function_name, runtime: runtime, role: lambda_role_arn, handler: handler, code: {zip_file: zip_file_content }, description: summary, publish: true, timeout: timeout})
|
91
96
|
end
|
92
97
|
puts "Creating alias #{@function_alias}"
|
93
|
-
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})
|
94
|
-
lambda_client.add_permission({function_name: alias_resp.alias_arn, statement_id: "API_2_#{function_name}_#{@function_alias}", action: "lambda:*", principal: 'apigateway.amazonaws.com'})
|
98
|
+
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})
|
99
|
+
@lambda_client.add_permission({function_name: alias_resp.alias_arn, statement_id: "API_2_#{function_name}_#{@function_alias}", action: "lambda:*", principal: 'apigateway.amazonaws.com'})
|
95
100
|
end
|
96
101
|
return "arn:aws:apigateway:#{@region}:lambda:path/2015-03-31/functions/arn:aws:lambda:#{@region}:#{@account}:function:#{function_name}:#{@function_alias}/invocations"
|
97
102
|
end
|
@@ -111,7 +116,7 @@ module Swaggerless
|
|
111
116
|
apis = @api_gateway_client.get_rest_apis(limit: 500).data
|
112
117
|
api = apis.items.select { |a| a.name == swagger['info']['title'] }.first
|
113
118
|
|
114
|
-
if api
|
119
|
+
if api
|
115
120
|
resp = @api_gateway_client.put_rest_api({rest_api_id: api.id, mode: "overwrite", fail_on_warnings: true, body: swagger.to_yaml})
|
116
121
|
else
|
117
122
|
resp = @api_gateway_client.import_rest_api({fail_on_warnings: true, body: swagger.to_yaml})
|
@@ -9,7 +9,6 @@ module Swaggerless
|
|
9
9
|
|
10
10
|
AMZ_APIGATEWAY_AUTHORIZER = 'x-amazon-apigateway-authorizer'
|
11
11
|
|
12
|
-
SWGR_OPERATION_ID = 'operationId'
|
13
12
|
SWGR_SUMMARY = 'summary'
|
14
13
|
SWGR_DESCRIPTION = 'description'
|
15
14
|
|
@@ -19,37 +18,32 @@ module Swaggerless
|
|
19
18
|
lambdas_map = Hash.new
|
20
19
|
swagger["paths"].each do |path, path_config|
|
21
20
|
path_config.each do |method, method_config|
|
22
|
-
|
23
|
-
stored_version = lambdas_map[method_config[EXT_LAMBDA_NAME]];
|
24
|
-
encountered_version = build_lambda_config_hash(method_config)
|
25
|
-
fill_in_config_gaps(stored_version, encountered_version)
|
26
|
-
unless is_lambda_config_correct(stored_version, encountered_version)
|
27
|
-
raise "Lambda #{method_config[EXT_LAMBDA_NAME]} mentioned multiple times in configuration with different settings"
|
28
|
-
end
|
29
|
-
lambdas_map[method_config[EXT_LAMBDA_NAME]][:description] = 'Part of ' + Deployer.get_service_prefix(swagger)
|
30
|
-
elsif method_config[EXT_LAMBDA_NAME]
|
31
|
-
lambdas_map[method_config[EXT_LAMBDA_NAME]] = build_lambda_config_hash(method_config)
|
32
|
-
end
|
21
|
+
process_lambda_config(lambdas_map, method_config, swagger)
|
33
22
|
end
|
34
23
|
end
|
35
24
|
|
36
25
|
swagger["securityDefinitions"].each do |securityDefinitionName, securityDefinition|
|
37
26
|
if securityDefinition[AMZ_APIGATEWAY_AUTHORIZER] != nil
|
38
|
-
|
39
|
-
stored_version = lambdas_map[securityDefinition[AMZ_APIGATEWAY_AUTHORIZER][EXT_LAMBDA_NAME]];
|
40
|
-
encountered_version = build_lambda_config_hash(securityDefinition[AMZ_APIGATEWAY_AUTHORIZER])
|
41
|
-
unless is_lambda_config_correct(stored_version, encountered_version)
|
42
|
-
raise "Lambda #{method_config[EXT_LAMBDA_NAME]} mentioned multiple times in configuration with different settings"
|
43
|
-
end
|
44
|
-
lambdas_map[securityDefinition[EXT_LAMBDA_NAME]][:description] = 'Part of ' + Deployer.get_service_prefix(swagger)
|
45
|
-
else
|
46
|
-
lambdas_map[securityDefinition[EXT_LAMBDA_NAME]] = build_lambda_config_hash(securityDefinition)
|
47
|
-
end
|
27
|
+
process_lambda_config(lambdas_map, securityDefinition, swagger)
|
48
28
|
end
|
49
29
|
end
|
50
30
|
return lambdas_map
|
51
31
|
end
|
52
32
|
|
33
|
+
def process_lambda_config(lambdas_map, objContainingLambdaConfig, swagger)
|
34
|
+
if lambdas_map[objContainingLambdaConfig[EXT_LAMBDA_NAME]]
|
35
|
+
stored_version = lambdas_map[objContainingLambdaConfig[EXT_LAMBDA_NAME]];
|
36
|
+
encountered_version = build_lambda_config_hash(objContainingLambdaConfig)
|
37
|
+
fill_in_config_gaps(stored_version, encountered_version)
|
38
|
+
unless is_lambda_config_correct(stored_version, encountered_version)
|
39
|
+
raise "Lambda #{objContainingLambdaConfig[EXT_LAMBDA_NAME]} mentioned multiple times in configuration with different settings"
|
40
|
+
end
|
41
|
+
lambdas_map[objContainingLambdaConfig[EXT_LAMBDA_NAME]][:description] = 'Part of ' + Deployer.get_service_prefix(swagger)
|
42
|
+
elsif objContainingLambdaConfig[EXT_LAMBDA_NAME]
|
43
|
+
lambdas_map[objContainingLambdaConfig[EXT_LAMBDA_NAME]] = build_lambda_config_hash(objContainingLambdaConfig)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
53
47
|
private
|
54
48
|
|
55
49
|
def fill_in_config_gaps(to, from)
|
@@ -59,6 +53,8 @@ module Swaggerless
|
|
59
53
|
end
|
60
54
|
|
61
55
|
def is_lambda_config_correct(l1, l2)
|
56
|
+
fill_in_config_gaps(l2,l1)
|
57
|
+
fill_in_config_gaps(l1,l2)
|
62
58
|
return (l1[:handler] == l2[:handler] and
|
63
59
|
l1[:timeout] == l2[:timeout] and
|
64
60
|
l1[:runtime] == l2[:runtime])
|
data/lib/swaggerless/version.rb
CHANGED