swaggerless 0.1.3 → 0.1.4
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/cleaner.rb +21 -16
- data/lib/swaggerless/swaggerextractor.rb +17 -9
- 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: 877151d9ab0dbe93d6ff7b28cec271aa7b49e114
|
4
|
+
data.tar.gz: dde2af502d75aa20bbbc8e24cc699c390bc73b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6dc71afc0b92c7cf60668b91c5c5babfc6e583cb37557483c7f6b6163cfe822dd0ef6ade4dd99c41658000c535bf92ab04f9071b0e0b9d8ca69c75f861fe6d2
|
7
|
+
data.tar.gz: 224e708bf3ac7bbf71b21cfb0c4b1a02dd5c1db59d2fbb08acff52fe0a5993b4fa32aac714007b13afbee0f027b67bffd236e71d74bdeeccd7d34860afe47ce0
|
data/lib/swaggerless/cleaner.rb
CHANGED
@@ -26,8 +26,8 @@ module Swaggerless
|
|
26
26
|
response = @api_gateway_client.get_deployments({rest_api_id: api.id, limit: 500})
|
27
27
|
time_threshold = Time.now
|
28
28
|
response.items.each do |deployment|
|
29
|
-
puts "Deployment #{deployment.id} is not used and old enough to be pruned"
|
30
29
|
if used_deployments[deployment.id] == nil and Time.at(deployment.created_date) < time_threshold
|
30
|
+
puts "Deployment #{deployment.id} is not used and old enough to be pruned"
|
31
31
|
@api_gateway_client.delete_deployment({rest_api_id: api.id, deployment_id: deployment.id})
|
32
32
|
end
|
33
33
|
end
|
@@ -46,25 +46,30 @@ module Swaggerless
|
|
46
46
|
configured_lambdas = @swaggerExtractor.get_lambda_map(swagger)
|
47
47
|
configured_lambdas.each do |functionName, value|
|
48
48
|
lambda_versions_used = Hash.new
|
49
|
-
resp = @lambda_client.list_aliases({function_name: functionName, max_items: 500 })
|
50
|
-
resp.aliases.each do |funcAlias|
|
51
|
-
if lambda_liases_used[funcAlias.name] == nil then
|
52
|
-
puts "Deleting alias #{funcAlias.name} for lambda function #{functionName}"
|
53
|
-
@lambda_client.delete_alias({function_name: functionName, name: funcAlias.name})
|
54
|
-
else
|
55
|
-
puts "Lambda version #{funcAlias.function_version} still used by function deployment #{functionName}"
|
56
|
-
lambda_versions_used[funcAlias.function_version] = funcAlias.name
|
57
|
-
end
|
58
49
|
|
59
|
-
|
50
|
+
begin
|
51
|
+
resp = @lambda_client.list_aliases({function_name: functionName, max_items: 500 })
|
52
|
+
resp.aliases.each do |funcAlias|
|
53
|
+
if lambda_liases_used[funcAlias.name] == nil then
|
54
|
+
puts "Deleting alias #{funcAlias.name} for lambda function #{functionName}"
|
55
|
+
@lambda_client.delete_alias({function_name: functionName, name: funcAlias.name})
|
56
|
+
else
|
57
|
+
puts "Lambda version #{funcAlias.function_version} still used by function deployment #{functionName}"
|
58
|
+
lambda_versions_used[funcAlias.function_version] = funcAlias.name
|
59
|
+
end
|
60
60
|
|
61
|
-
resp = @lambda_client.list_versions_by_function({function_name: functionName, max_items: 500})
|
62
|
-
resp.versions.each do |lambda|
|
63
|
-
if lambda.version != "$LATEST" and lambda_versions_used[lambda.version] == nil
|
64
|
-
puts "Deleting lambda version #{lambda.version} of function #{functionName}"
|
65
|
-
@lambda_client.delete_function({function_name: functionName, qualifier: lambda.version})
|
66
61
|
end
|
67
62
|
|
63
|
+
resp = @lambda_client.list_versions_by_function({function_name: functionName, max_items: 500})
|
64
|
+
resp.versions.each do |lambda|
|
65
|
+
if lambda.version != "$LATEST" and lambda_versions_used[lambda.version] == nil
|
66
|
+
puts "Deleting lambda version #{lambda.version} of function #{functionName}"
|
67
|
+
@lambda_client.delete_function({function_name: functionName, qualifier: lambda.version})
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
rescue Aws::Lambda::Errors::ResourceNotFoundException
|
72
|
+
puts "Function #{functionName} does not exist and will be skipped"
|
68
73
|
end
|
69
74
|
|
70
75
|
end
|
@@ -11,6 +11,7 @@ module Swaggerless
|
|
11
11
|
|
12
12
|
SWGR_OPERATION_ID = 'operationId'
|
13
13
|
SWGR_SUMMARY = 'summary'
|
14
|
+
SWGR_DESCRIPTION = 'description'
|
14
15
|
|
15
16
|
class SwaggerExtractor
|
16
17
|
|
@@ -21,10 +22,11 @@ module Swaggerless
|
|
21
22
|
if lambdas_map[method_config[EXT_LAMBDA_NAME]] then
|
22
23
|
stored_version = lambdas_map[method_config[EXT_LAMBDA_NAME]];
|
23
24
|
encountered_version = build_lambda_config_hash(method_config)
|
24
|
-
|
25
|
+
fill_in_config_gaps(stored_version, encountered_version)
|
26
|
+
unless is_lambda_config_correct(stored_version, encountered_version)
|
25
27
|
raise "Lambda #{method_config[EXT_LAMBDA_NAME]} mentioned multiple times in configuration with different settings"
|
26
28
|
end
|
27
|
-
lambdas_map[method_config[EXT_LAMBDA_NAME]][
|
29
|
+
lambdas_map[method_config[EXT_LAMBDA_NAME]][:description] = 'Part of ' + Deployer.get_service_prefix(swagger)
|
28
30
|
elsif method_config[EXT_LAMBDA_NAME]
|
29
31
|
lambdas_map[method_config[EXT_LAMBDA_NAME]] = build_lambda_config_hash(method_config)
|
30
32
|
end
|
@@ -32,14 +34,14 @@ module Swaggerless
|
|
32
34
|
end
|
33
35
|
|
34
36
|
swagger["securityDefinitions"].each do |securityDefinitionName, securityDefinition|
|
35
|
-
if securityDefinition[AMZ_APIGATEWAY_AUTHORIZER] != nil
|
36
|
-
if lambdas_map[securityDefinition[EXT_LAMBDA_NAME]]
|
37
|
+
if securityDefinition[AMZ_APIGATEWAY_AUTHORIZER] != nil
|
38
|
+
if lambdas_map[securityDefinition[EXT_LAMBDA_NAME]]
|
37
39
|
stored_version = lambdas_map[securityDefinition[AMZ_APIGATEWAY_AUTHORIZER][EXT_LAMBDA_NAME]];
|
38
40
|
encountered_version = build_lambda_config_hash(securityDefinition[AMZ_APIGATEWAY_AUTHORIZER])
|
39
41
|
unless is_lambda_config_correct(stored_version, encountered_version)
|
40
42
|
raise "Lambda #{method_config[EXT_LAMBDA_NAME]} mentioned multiple times in configuration with different settings"
|
41
43
|
end
|
42
|
-
lambdas_map[securityDefinition[EXT_LAMBDA_NAME]]
|
44
|
+
lambdas_map[securityDefinition[EXT_LAMBDA_NAME]][:description] = 'Part of ' + Deployer.get_service_prefix(swagger)
|
43
45
|
else
|
44
46
|
lambdas_map[securityDefinition[EXT_LAMBDA_NAME]] = build_lambda_config_hash(securityDefinition)
|
45
47
|
end
|
@@ -50,17 +52,23 @@ module Swaggerless
|
|
50
52
|
|
51
53
|
private
|
52
54
|
|
55
|
+
def fill_in_config_gaps(to, from)
|
56
|
+
if to[:handler] == nil then to[:handler] = from[:handler] end
|
57
|
+
if to[:timeout] == nil then to[:timeout] = from[:timeout] end
|
58
|
+
if to[:runtime] == nil then to[:runtime] = from[:runtime] end
|
59
|
+
end
|
60
|
+
|
53
61
|
def is_lambda_config_correct(l1, l2)
|
54
|
-
return (l1[
|
55
|
-
l1[
|
56
|
-
l1[
|
62
|
+
return (l1[:handler] == l2[:handler] and
|
63
|
+
l1[:timeout] == l2[:timeout] and
|
64
|
+
l1[:runtime] == l2[:runtime])
|
57
65
|
end
|
58
66
|
|
59
67
|
def build_lambda_config_hash(method_config)
|
60
68
|
{ handler: method_config[EXT_LAMBDA_HANDLER],
|
61
69
|
timeout: method_config[EXT_LAMBDA_TIMEOUT],
|
62
70
|
runtime: method_config[EXT_LAMBDA_RUNTIME],
|
63
|
-
description: method_config[SWGR_SUMMARY]}
|
71
|
+
description: method_config[SWGR_SUMMARY] || method_config[SWGR_DESCRIPTION]}
|
64
72
|
end
|
65
73
|
|
66
74
|
end
|
data/lib/swaggerless/version.rb
CHANGED