lambdagate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2fa1b21b117b12abbd4742700022b4e3897bd83b
4
+ data.tar.gz: 5940307a702bad093dc5a30961c2ae46135ed3f6
5
+ SHA512:
6
+ metadata.gz: d56c862f80712ad9af8777bffe18689b2678fe0b2b2a72635b9d5818d2d0530d242c0d331fcc79eb48051b5268c987d3cf768dc03751cc080a2603d82a8e3bd9
7
+ data.tar.gz: e00b6da97c2c610f90b75e28d5651df5837f005ef02136b875ddd496b5d63c14839ec14033db5f77ab921445ab13ab82cc28ec2728eb175978cee0f3cdef6924
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lambdagate.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ryo Nakamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Lambdagate
2
+ Management tool for Amazon API Gateway and Amazon Lambda.
3
+
4
+ ## Requirements
5
+ - Ruby 2.2.0 or higher
6
+ - Bundler gem
7
+
8
+ ## Authentication
9
+ We assume that your credentials are stored in `~/.aws/credentials`.
10
+
11
+ ```
12
+ [default]
13
+ aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID
14
+ aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY
15
+ ```
16
+
17
+ ## Usage
18
+ The `lambdagate` executable is provided to create and update your API from your API schema
19
+ written in [Swagger](http://swagger.io/) format.
20
+
21
+ ```
22
+ $ lambdagate
23
+ Usage: lambdagate [create|deploy|update] [command-specific-options]
24
+ ```
25
+
26
+ ### lambdagate create
27
+ Creates Restapi, Resources, Methods, and so on from your swagger schema.
28
+
29
+ ```
30
+ $ lambdagate create
31
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lambdagate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,249 @@
1
+ ---
2
+ swagger: '2.0'
3
+ info:
4
+ title: API Gateway Test API
5
+ description: Move your app forward with the Uber API
6
+ version: 1.0.0
7
+ host: api.uber.com
8
+ schemes:
9
+ - https
10
+ basePath: "/v1"
11
+ produces:
12
+ - application/json
13
+ security:
14
+ - api_key: []
15
+ securityDefinitions:
16
+ api_key:
17
+ type: apiKey
18
+ name: x-api-key
19
+ in: header
20
+ paths:
21
+ "/products":
22
+ get:
23
+ summary: Product Types
24
+ description: |
25
+ The Products endpoint returns information about the *Uber* products
26
+ offered at a given location. The response includes the display name
27
+ and other details about each product, and lists the products in the
28
+ proper display order.
29
+ parameters:
30
+ - name: latitude
31
+ in: query
32
+ description: Latitude component of location.
33
+ required: true
34
+ type: number
35
+ format: double
36
+ - name: longitude
37
+ in: query
38
+ description: Longitude component of location.
39
+ required: true
40
+ type: number
41
+ format: double
42
+ tags:
43
+ - Products
44
+ responses:
45
+ '200':
46
+ description: An array of products
47
+ schema:
48
+ type: array
49
+ items:
50
+ "$ref": "#/definitions/Product"
51
+ headers:
52
+ test-method-response-header:
53
+ type: string
54
+ '400':
55
+ description: Bad request
56
+ schema:
57
+ "$ref": "#/definitions/Error"
58
+ default:
59
+ description: Unexpected error
60
+ schema:
61
+ "$ref": "#/definitions/Error"
62
+ security:
63
+ - api_key: []
64
+ x-amazon-apigateway-auth:
65
+ type: aws_iam
66
+ x-amazon-apigateway-integration:
67
+ type: aws
68
+ uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:ACCOUNT_ID:function:myFunction/invocations
69
+ httpMethod: POST
70
+ credentials: arn:aws:iam::ACCOUNT_ID:role/lambda_exec_role
71
+ requestTemplates:
72
+ application/json: json request template 2
73
+ application/xml: xml request template 2
74
+ requestParameters:
75
+ integration.request.path.integrationPathParam: method.request.querystring.latitude
76
+ integration.request.querystring.integrationQueryParam: method.request.querystring.longitude
77
+ cacheNamespace: cache namespace
78
+ cacheKeyParameters: []
79
+ responses:
80
+ 2//d{2}:
81
+ statusCode: '200'
82
+ responseParameters:
83
+ method.response.header.test-method-response-header: integration.response.header.integrationResponseHeaderParam1
84
+ responseTemplates:
85
+ application/json: json 200 response template
86
+ application/xml: xml 200 response template
87
+ default:
88
+ statusCode: '400'
89
+ responseParameters:
90
+ method.response.header.test-method-response-header: "'static value'"
91
+ responseTemplates:
92
+ application/json: json 400 response template
93
+ application/xml: xml 400 response template
94
+ "/products/child":
95
+ post:
96
+ summary: Product Types
97
+ description: |
98
+ The Products endpoint returns information about the *Uber* products
99
+ offered at a given location. The response includes the display name
100
+ and other details about each product, and lists the products in the
101
+ proper display order.
102
+ parameters:
103
+ - name: latitude
104
+ in: query
105
+ description: Latitude component of location.
106
+ required: true
107
+ type: number
108
+ format: double
109
+ - name: longitude
110
+ in: query
111
+ description: Longitude component of location.
112
+ required: true
113
+ type: number
114
+ format: double
115
+ tags:
116
+ - Products
117
+ responses:
118
+ '200':
119
+ description: An array of products
120
+ schema:
121
+ type: array
122
+ items:
123
+ "$ref": "#/definitions/Product"
124
+ headers:
125
+ test-method-response-header:
126
+ type: string
127
+ '400':
128
+ description: Bad request
129
+ schema:
130
+ "$ref": "#/definitions/Error"
131
+ default:
132
+ description: Unexpected error
133
+ schema:
134
+ "$ref": "#/definitions/Error"
135
+ security:
136
+ - api_key: []
137
+ x-amazon-apigateway-auth:
138
+ type: none
139
+ x-amazon-apigateway-integration:
140
+ type: http
141
+ uri: https://api.github.com
142
+ httpMethod: GET
143
+ responses:
144
+ 2//d{2}:
145
+ statusCode: '200'
146
+ default:
147
+ statusCode: '400'
148
+ responseParameters:
149
+ method.response.header.test-method-response-header: "'static value'"
150
+ responseTemplates:
151
+ application/json: json 400 response template
152
+ application/xml: xml 400 response template
153
+ definitions:
154
+ Product:
155
+ properties:
156
+ product_id:
157
+ type: string
158
+ description: Unique identifier representing a specific product for a given
159
+ latitude & longitude. For example, uberX in San Francisco will have a different
160
+ product_id than uberX in Los Angeles.
161
+ description:
162
+ type: string
163
+ description: Description of product.
164
+ display_name:
165
+ type: string
166
+ description: Display name of product.
167
+ capacity:
168
+ type: string
169
+ description: Capacity of product. For example, 4 people.
170
+ image:
171
+ type: string
172
+ description: Image URL representing the product.
173
+ PriceEstimate:
174
+ properties:
175
+ product_id:
176
+ type: string
177
+ description: Unique identifier representing a specific product for a given
178
+ latitude & longitude. For example, uberX in San Francisco will have a different
179
+ product_id than uberX in Los Angeles
180
+ currency_code:
181
+ type: string
182
+ description: "[ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) currency code."
183
+ display_name:
184
+ type: string
185
+ description: Display name of product.
186
+ estimate:
187
+ type: string
188
+ description: Formatted string of estimate in local currency of the start location.
189
+ Estimate could be a range, a single number (flat rate) or "Metered" for
190
+ TAXI.
191
+ low_estimate:
192
+ type: number
193
+ description: Lower bound of the estimated price.
194
+ high_estimate:
195
+ type: number
196
+ description: Upper bound of the estimated price.
197
+ surge_multiplier:
198
+ type: number
199
+ description: Expected surge multiplier. Surge is active if surge_multiplier
200
+ is greater than 1. Price estimate already factors in the surge multiplier.
201
+ Profile:
202
+ properties:
203
+ first_name:
204
+ type: string
205
+ description: First name of the Uber user.
206
+ last_name:
207
+ type: string
208
+ description: Last name of the Uber user.
209
+ email:
210
+ type: string
211
+ description: Email address of the Uber user
212
+ picture:
213
+ type: string
214
+ description: Image URL of the Uber user.
215
+ promo_code:
216
+ type: string
217
+ description: Promo code of the Uber user.
218
+ Activity:
219
+ properties:
220
+ uuid:
221
+ type: string
222
+ description: Unique identifier for the activity
223
+ Activities:
224
+ properties:
225
+ offset:
226
+ type: integer
227
+ format: int32
228
+ description: Position in pagination.
229
+ limit:
230
+ type: integer
231
+ format: int32
232
+ description: Number of items to retrieve (100 max).
233
+ count:
234
+ type: integer
235
+ format: int32
236
+ description: Total number of items available.
237
+ history:
238
+ type: array
239
+ items:
240
+ "$ref": "#/definitions/Activity"
241
+ Error:
242
+ properties:
243
+ code:
244
+ type: integer
245
+ format: int32
246
+ message:
247
+ type: string
248
+ fields:
249
+ type: string
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "lambdagate"
4
+
5
+ Lambdagate::CommandLineParser.parse(ARGV).run
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "lambdagate/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lambdagate"
7
+ spec.version = Lambdagate::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Management tool for Amazon API Gateway and Amazon Lambda."
11
+ spec.homepage = "https://github.com/r7kamura/lambdagate"
12
+ spec.license = "MIT"
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = "exe"
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+ spec.add_development_dependency "bundler", "~> 1.9"
18
+ spec.add_development_dependency "pry"
19
+ spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_runtime_dependency "aws-sdk", ">= 2.0.0"
21
+ spec.add_runtime_dependency "faraday", ">= 0.9.1"
22
+ spec.add_runtime_dependency "faraday_middleware"
23
+ spec.add_runtime_dependency "faraday_middleware-aws-signers-v4"
24
+ spec.add_runtime_dependency "swagger_parser", ">= 0.0.2"
25
+ end
@@ -0,0 +1,3 @@
1
+ require "lambdagate/api_gateway_client"
2
+ require "lambdagate/command_line_parser"
3
+ require "lambdagate/version"
@@ -0,0 +1,212 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "faraday_middleware/aws_signers_v4"
4
+
5
+ module Lambdagate
6
+ class ApiGatewayClient
7
+ DEFAULT_AUTHORIZATION_TYPE = "NONE"
8
+ DEFAULT_REGION = "us-east-1"
9
+ SERVICE_NAME = "apigateway"
10
+
11
+ # @param [String] access_key_id
12
+ # @param [String, nil] host
13
+ # @param [String, nil] region
14
+ # @param [String] secret_access_key
15
+ def initialize(access_key_id:, host: nil, region: nil, secret_access_key:)
16
+ @access_key_id = access_key_id
17
+ @host = host
18
+ @region = region
19
+ @secret_access_key = secret_access_key
20
+ end
21
+
22
+ # @param [String] parent_id
23
+ # @param [String] path_part
24
+ # @param [String] restapi_id
25
+ # @return [Faraday::Response]
26
+ def create_resource(parent_id:, part:, restapi_id:)
27
+ post("/restapis/#{restapi_id}/resources/#{parent_id}", pathPart: part).tap do |response|
28
+ puts "[DEBUG] Created " + response.body["path"]
29
+ end
30
+ end
31
+
32
+ # @param [Array<String>] paths
33
+ # @param [String] restapi_id
34
+ def create_resources(paths:, restapi_id:)
35
+ root_resource_id = get_root_resource_id(restapi_id: restapi_id)
36
+ paths.each do |path|
37
+ parent_id = root_resource_id
38
+ parts = path.split("/")
39
+ parts[1..-1].each_with_index do |part, index|
40
+ if resource = find_resource(path: parts[0 .. index + 1].join("/"), restapi_id: restapi_id)
41
+ parent_id = resource["id"]
42
+ else
43
+ response = create_resource(
44
+ parent_id: parent_id,
45
+ part: part,
46
+ restapi_id: restapi_id,
47
+ )
48
+ parent_id = response.body["id"]
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ # @param [String] name
55
+ # @return [Faraday::Response]
56
+ def create_restapi(name:)
57
+ post("/restapis", name: name)
58
+ end
59
+
60
+ # @param [String] model_name
61
+ # @param [String] restapi_id
62
+ # @return [Faraday::Response]
63
+ def delete_model(model_name:, restapi_id:)
64
+ delete("/restapis/#{restapi_id}/models/#{model_name}")
65
+ end
66
+
67
+ # @param [String] path
68
+ # @param [String] restapi_id
69
+ # @return [Hash{String => Hash}, nil]
70
+ def find_resource(path:, restapi_id:)
71
+ list_resources(restapi_id: restapi_id).body["item"].find do |item|
72
+ item["path"] == path
73
+ end
74
+ end
75
+
76
+ # @param [String] restapi_id
77
+ # @return [Faraday::Response]
78
+ def list_resources(restapi_id:)
79
+ get("/restapis/#{restapi_id}/resources")
80
+ end
81
+
82
+ # @param [false, true, nil] api_key_required
83
+ # @param [String, nil] authorization_type
84
+ # @param [String] http_method
85
+ # @param [Hash{String => String}, nil] request_models
86
+ # @param [Hash{String => String}, nil] request_parameters
87
+ # @param [String] resource_id
88
+ # @param [String] restapi_id
89
+ # @return [Faraday::Response]
90
+ def put_method(api_key_required: nil, authorization_type: nil, http_method:, request_models: nil, request_parameters: nil, resource_id:, restapi_id:)
91
+ put(
92
+ "/restapis/#{restapi_id}/resources/#{resource_id}/methods/#{http_method}",
93
+ {
94
+ apiKeyRequired: api_key_required,
95
+ authorizationType: authorization_type || DEFAULT_AUTHORIZATION_TYPE,
96
+ requestModels: request_models,
97
+ requestParameters: request_parameters,
98
+ }.reject { |key, value| value.nil? },
99
+ )
100
+ end
101
+
102
+ private
103
+
104
+ # @return [String]
105
+ def base_url
106
+ "https://#{host}"
107
+ end
108
+
109
+ # @return [Faraday::Connection]
110
+ def connection
111
+ @connection ||= Faraday::Connection.new(url: base_url) do |connection|
112
+ connection.request :json
113
+ connection.request(
114
+ :aws_signers_v4,
115
+ credentials: Aws::Credentials.new(@access_key_id, @secret_access_key),
116
+ region: region,
117
+ service_name: SERVICE_NAME,
118
+ )
119
+ connection.response :json, :content_type => /\bjson\b/
120
+ connection.response :raise_error
121
+ connection.adapter Faraday.default_adapter
122
+ end
123
+ end
124
+
125
+ # @return [String]
126
+ def default_host
127
+ "#{SERVICE_NAME}.#{region}.amazonaws.com"
128
+ end
129
+
130
+ # @return [Hash{String => String}]
131
+ def default_request_headers
132
+ {
133
+ "Host" => host,
134
+ "X-Amz-Date" => Time.now.iso8601,
135
+ }
136
+ end
137
+
138
+ # @param [String] path
139
+ # @param [Hash, nil] params
140
+ # @param [Hash, nil] headers
141
+ # @return [Faraday::Response]
142
+ def delete(path, params = nil, headers = nil)
143
+ process(:delete, path, params, headers)
144
+ end
145
+
146
+ # @param [String] path
147
+ # @param [Hash, nil] params
148
+ # @param [Hash, nil] headers
149
+ # @return [Faraday::Response]
150
+ def get(path, params = nil, headers = nil)
151
+ process(:get, path, params, headers)
152
+ end
153
+
154
+ # @param [String] restapi_id
155
+ # @return [String, nil]
156
+ def get_root_resource_id(restapi_id:)
157
+ list_resources(restapi_id: restapi_id).body["item"].find do |item|
158
+ if item["path"] == "/"
159
+ return item["id"]
160
+ end
161
+ end
162
+ end
163
+
164
+ # @return [String]
165
+ def host
166
+ @host || default_host
167
+ end
168
+
169
+ # @param [String] path
170
+ # @param [Hash, nil] params
171
+ # @param [Hash, nil] headers
172
+ # @return [Faraday::Response]
173
+ def patch(path, params = nil, headers = nil)
174
+ process(:patch, path, params, headers)
175
+ end
176
+
177
+ # @param [String] path
178
+ # @param [Hash, nil] params
179
+ # @param [Hash, nil] headers
180
+ # @return [Faraday::Response]
181
+ def post(path, params = nil, headers = nil)
182
+ process(:post, path, params, headers)
183
+ end
184
+
185
+ # @param [Symbol] request_method
186
+ # @param [String] path
187
+ # @param [Hash, nil] params
188
+ # @param [Hash, nil] headers
189
+ # @return [Faraday::Response]
190
+ def process(request_method, path, params, headers)
191
+ connection.send(
192
+ request_method,
193
+ path,
194
+ params,
195
+ headers,
196
+ )
197
+ end
198
+
199
+ # @param [String] path
200
+ # @param [Hash, nil] params
201
+ # @param [Hash, nil] headers
202
+ # @return [Faraday::Response]
203
+ def put(path, params = nil, headers = nil)
204
+ process(:put, path, params, headers)
205
+ end
206
+
207
+ # @return [String]
208
+ def region
209
+ @region || DEFAULT_REGION
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,13 @@
1
+ module Lambdagate
2
+ class Command
3
+ # @param [Array<String>] argv
4
+ def initialize(argv)
5
+ @argv = argv
6
+ end
7
+
8
+ # @note Override me
9
+ def run
10
+ raise NotImplementedError
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ require "lambdagate/command"
2
+ require "lambdagate/create_command"
3
+ require "lambdagate/deploy_command"
4
+ require "lambdagate/update_command"
5
+ require "lambdagate/usage_command"
6
+
7
+ module Lambdagate
8
+ class CommandLineParser
9
+ class << self
10
+ # @param [Array<String>] argv
11
+ # @return [Lambdagate::Command]
12
+ def parse(argv)
13
+ new(argv).parse
14
+ end
15
+ end
16
+
17
+ # @param [Array<String>] argv
18
+ def initialize(argv)
19
+ @argv = argv
20
+ end
21
+
22
+ # @return [Lambdagate::Command]
23
+ def parse
24
+ command_class.new(@argv)
25
+ end
26
+
27
+ private
28
+
29
+ # @return [Class]
30
+ def command_class
31
+ case @argv.first
32
+ when "create"
33
+ Lambdagate::CreateCommand
34
+ when "deploy"
35
+ Lambdagate::DeployCommand
36
+ when "update"
37
+ Lambdagate::UpdateCommand
38
+ else
39
+ Lambdagate::UsageCommand
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,115 @@
1
+ require "aws-sdk"
2
+ require "lambdagate/command"
3
+ require "swagger_parser"
4
+
5
+ module Lambdagate
6
+ class CreateCommand < Command
7
+ DEFAULT_MODEL_NAMES = %w(Empty Error)
8
+
9
+ # @todo
10
+ # @note Implementation for Lambdagate::Command
11
+ def run
12
+ puts "[DEBUG] Creating API"
13
+ response = create_restapi
14
+ restapi_id = response.body["id"]
15
+
16
+ puts "[DEBUG] Deleting default models"
17
+ delete_default_models(restapi_id: restapi_id)
18
+
19
+ puts "[DEBUG] Creating resources"
20
+ api_gateway_client.create_resources(
21
+ paths: paths,
22
+ restapi_id: restapi_id,
23
+ )
24
+
25
+ puts "[DEBUG] Creating methods"
26
+ methods.each do |method|
27
+ resource = api_gateway_client.find_resource(path: method[:path], restapi_id: restapi_id)
28
+ api_gateway_client.put_method(
29
+ api_key_required: method[:api_key_required],
30
+ authorization_type: method[:authorization_type],
31
+ http_method: method[:http_method],
32
+ request_models: method[:request_models],
33
+ request_parameters: method[:request_parameters],
34
+ resource_id: resource["id"],
35
+ restapi_id: restapi_id,
36
+ )
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ # @return [String, nil]
43
+ def access_key_id
44
+ credentials.access_key_id
45
+ end
46
+
47
+ # @return [Lambdagate::ApiGatewayClient]
48
+ def api_gateway_client
49
+ @__api_gateway_client ||= Lambdagate::ApiGatewayClient.new(
50
+ access_key_id: access_key_id,
51
+ secret_access_key: secret_access_key,
52
+ )
53
+ end
54
+
55
+ # @return [String]
56
+ def api_name
57
+ swagger.info.title
58
+ end
59
+
60
+ # @return [Faraday::Response]
61
+ def create_restapi
62
+ api_gateway_client.create_restapi(name: api_name)
63
+ end
64
+
65
+ # @return [Aws::Credentials]
66
+ def credentials
67
+ @__credentials ||= Aws::SharedCredentials.new.credentials
68
+ end
69
+
70
+ # @param [String] restapi_id
71
+ # @return [Array<Faraday::Response>]
72
+ def delete_default_models(restapi_id:)
73
+ DEFAULT_MODEL_NAMES.map do |model_name|
74
+ api_gateway_client.delete_model(restapi_id: restapi_id, model_name: model_name)
75
+ end
76
+ end
77
+
78
+ # @return [Array<Hash>]
79
+ def methods
80
+ swagger.paths.flat_map do |path, path_object|
81
+ path_object.operations.map do |operation|
82
+ {
83
+ api_key_required: !!operation.source["x-api-key-required"],
84
+ authorization_type: operation.source["x-authorization-type"],
85
+ http_method: operation.http_method,
86
+ path: "#{swagger.base_path}#{path}",
87
+ request_models: operation.source["x-request-models"],
88
+ request_parameters: operation.source["x-request-parameters"],
89
+ }
90
+ end
91
+ end
92
+ end
93
+
94
+ # @return [Array<String>]
95
+ def paths
96
+ swagger.paths.map { |key, value| "#{swagger.base_path}#{key}" }
97
+ end
98
+
99
+ # @return [String, nil]
100
+ def secret_access_key
101
+ credentials.secret_access_key
102
+ end
103
+
104
+ # @return [SwaggerParser::Swagger]
105
+ def swagger
106
+ @swagger ||= SwaggerParser::FileParser.parse(swagger_path)
107
+ end
108
+
109
+ # @todo
110
+ # @return [String]
111
+ def swagger_path
112
+ "examples/swagger.yml"
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,10 @@
1
+ require "lambdagate/command"
2
+
3
+ module Lambdagate
4
+ class DeployCommand < Command
5
+ # @todo
6
+ # @note Implementation for Lambdagate::Command
7
+ def run
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require "lambdagate/command"
2
+
3
+ module Lambdagate
4
+ class UpdateCommand < Command
5
+ # @todo
6
+ # @note Implementation for Lambdagate::Command
7
+ def run
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require "lambdagate/command"
2
+
3
+ module Lambdagate
4
+ class UsageCommand < Command
5
+ # @todo
6
+ # @note Implementation for Lambdagate::Command
7
+ def run
8
+ abort "Usage: #{$0} [create|deploy|update] [command-specific-options]"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Lambdagate
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lambdagate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware-aws-signers-v4
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: swagger_parser
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.2
125
+ description:
126
+ email:
127
+ - r7kamura@gmail.com
128
+ executables:
129
+ - lambdagate
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - examples/swagger.yml
142
+ - exe/lambdagate
143
+ - lambdagate.gemspec
144
+ - lib/lambdagate.rb
145
+ - lib/lambdagate/api_gateway_client.rb
146
+ - lib/lambdagate/command.rb
147
+ - lib/lambdagate/command_line_parser.rb
148
+ - lib/lambdagate/create_command.rb
149
+ - lib/lambdagate/deploy_command.rb
150
+ - lib/lambdagate/update_command.rb
151
+ - lib/lambdagate/usage_command.rb
152
+ - lib/lambdagate/version.rb
153
+ homepage: https://github.com/r7kamura/lambdagate
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.4.5
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Management tool for Amazon API Gateway and Amazon Lambda.
177
+ test_files: []
178
+ has_rdoc: