Skip to content

Commit dd4b7ed

Browse files
committed
wip
1 parent 3965a59 commit dd4b7ed

File tree

106 files changed

+42399
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+42399
-0
lines changed

apigw/DevPortalAPI/api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"swagger":"2.0","info":{"version":"1.0.0","title":"DevPortalAPI"},"basePath":"/devportal","schemes":["https"],"paths":{"/":{"x-amazon-apigateway-any-method":{"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":"200"}},"uri":"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/@lambda:devPortalBackend_v1@/invocations","passthroughBehavior":"when_no_match","httpMethod":"POST","type":"aws_proxy"}},"options":{"consumes":["application/json"],"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"},"headers":{"Access-Control-Allow-Origin":{"type":"string"},"Access-Control-Allow-Methods":{"type":"string"},"Access-Control-Allow-Headers":{"type":"string"}}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":200,"responseParameters":{"method.response.header.Access-Control-Allow-Methods":"'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'","method.response.header.Access-Control-Allow-Headers":"'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'","method.response.header.Access-Control-Allow-Origin":"'*'"}}},"passthroughBehavior":"when_no_match","requestTemplates":{"application/json":"{\"statusCode\": 200}"},"type":"mock"}}},"/register":{"post":{"produces":["application/json"],"responses":{"200":{"description":"200 response"}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":"200"}},"uri":"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/@lambda:devPortalBackend_v1@/invocations","passthroughBehavior":"when_no_match","httpMethod":"POST","type":"aws_proxy"}},"options":{"consumes":["application/json"],"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"},"headers":{"Access-Control-Allow-Origin":{"type":"string"},"Access-Control-Allow-Methods":{"type":"string"},"Access-Control-Allow-Headers":{"type":"string"}}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":200,"responseParameters":{"method.response.header.Access-Control-Allow-Methods":"'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'","method.response.header.Access-Control-Allow-Headers":"'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'","method.response.header.Access-Control-Allow-Origin":"'*'"}}},"passthroughBehavior":"when_no_match","requestTemplates":{"application/json":"{\"statusCode\": 200}"},"type":"mock"}}},"/marketplace-confirm/{usagePlanId}":{"post":{"produces":["application/json"],"parameters":[{"name":"usagePlanId","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"200 response"}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":"200"}},"uri":"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/@lambda:devPortalBackend_v1@/invocations","passthroughBehavior":"when_no_match","httpMethod":"POST","type":"aws_proxy"}},"options":{"consumes":["application/json"],"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"},"headers":{"Access-Control-Allow-Origin":{"type":"string"},"Access-Control-Allow-Methods":{"type":"string"},"Access-Control-Allow-Headers":{"type":"string"}}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":200,"responseParameters":{"method.response.header.Access-Control-Allow-Methods":"'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'","method.response.header.Access-Control-Allow-Headers":"'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'","method.response.header.Access-Control-Allow-Origin":"'*'"}}},"passthroughBehavior":"when_no_match","requestTemplates":{"application/json":"{\"statusCode\": 200}"},"type":"mock"}}},"/catalog":{"get":{"produces":["application/json"],"responses":{"200":{"description":"200 response"}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":"200"}},"uri":"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/@lambda:devPortalBackend_v1@/invocations","passthroughBehavior":"when_no_match","httpMethod":"POST","type":"aws_proxy"}},"options":{"consumes":["application/json"],"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"},"headers":{"Access-Control-Allow-Origin":{"type":"string"},"Access-Control-Allow-Methods":{"type":"string"},"Access-Control-Allow-Headers":{"type":"string"}}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":200,"responseParameters":{"method.response.header.Access-Control-Allow-Methods":"'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'","method.response.header.Access-Control-Allow-Headers":"'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'","method.response.header.Access-Control-Allow-Origin":"'*'"}}},"passthroughBehavior":"when_no_match","requestTemplates":{"application/json":"{\"statusCode\": 200}"},"type":"mock"}}},"/{proxy}":{"x-amazon-apigateway-any-method":{"x-amazon-apigateway-auth":{"type":"aws_iam"},"produces":["application/json"],"parameters":[{"name":"proxy","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"200 response"}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":"200"}},"uri":"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/@lambda:devPortalBackend_v1@/invocations","passthroughBehavior":"when_no_match","httpMethod":"POST","type":"aws_proxy"}},"options":{"consumes":["application/json"],"produces":["application/json"],"responses":{"200":{"description":"200 response","schema":{"$ref":"#/definitions/Empty"},"headers":{"Access-Control-Allow-Origin":{"type":"string"},"Access-Control-Allow-Methods":{"type":"string"},"Access-Control-Allow-Headers":{"type":"string"}}}},"x-amazon-apigateway-integration":{"responses":{"default":{"statusCode":200,"responseParameters":{"method.response.header.Access-Control-Allow-Methods":"'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'","method.response.header.Access-Control-Allow-Headers":"'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'","method.response.header.Access-Control-Allow-Origin":"'*'"}}},"passthroughBehavior":"when_no_match","requestTemplates":{"application/json":"{\"statusCode\": 200}"},"type":"mock"}}}},"definitions":{"Empty":{"type":"object","title":"Empty Schema"}}}

apigw/DevPortalAPI/metadata.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Description": "API for getting Warranty status for device",
3+
"Stage": "@stage@",
4+
"UsagePlan": "@usageplan: Default@",
5+
"SwaggerFile": "file://api.json",
6+
"CustomDomain": "@env: CUSTOM_DOMAIN_NAME@",
7+
"CustomDomainName": "DevPortal",
8+
"UserData": {
9+
"SourceURL": "https://app.swaggerhub.com/apiproxy/schema/file/eBuilder/DevPortalAPI/1.0.0/swagger.json",
10+
"SwaggerAuthKey": "eyJUb2tlblR5cGUiOiJBUEkiLCJhbGciOiJIUzUxMiJ9.eyJqdGkiOiI2NTgwZDY4My0yNzVmLTRlOTUtODRhNC0xZjQxNjI2MDg3MWMiLCJpYXQiOjE1MDE2NzU1NTd9.XX_v8EmwYa7tw1ud4kLiGUKSmrTsYSRzaAdEwC5EvIcqRnnpy3ogAvG2_geNjr1ymtfWgEVfmfWF6aVMypQTuA"
11+
}
12+
}

apigw/setup.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/python
2+
import urllib2
3+
import json
4+
import os
5+
6+
def httpRequest(url,headers):
7+
req = urllib2.Request(url,headers=headers)
8+
response = urllib2.urlopen(req)
9+
responseData = response.read()
10+
return responseData;
11+
12+
def readFile(fileName):
13+
data = None;
14+
try:
15+
fh = open(fileName, 'r')
16+
data = fh.read()
17+
fh.close()
18+
except:
19+
print "Warning: " +fileName+ " doesn't exist. Ignoring it."
20+
return data;
21+
22+
def parseMetadataJson(jsonString):
23+
try:
24+
return json.loads(jsonString)
25+
except:
26+
print "Error: " +"'"+fileName + "' is not a valid json"
27+
28+
def extractMetadataJsonAttribute(jsonObject,fileName,attribute):
29+
if 'UserData' in jsonObject:
30+
if attribute in jsonObject['UserData']:
31+
return jsonObject['UserData'][attribute]
32+
print "Error: " +"UserData."+attribute+ " attribute missing in " +fileName
33+
34+
def saveSwaggerAPI(basePath,apiContent):
35+
swaggerFile= open(basePath+"/api.json",'wb')
36+
result = swaggerFile.write(apiContent)
37+
return result;
38+
39+
def readAPIFolders():
40+
dirs = next(os.walk("./"))[1]
41+
return dirs;
42+
43+
#Entry point to the program
44+
for api in readAPIFolders():
45+
print "Downloading swagger file for "+ api
46+
fileName = api+'/metadata.json';
47+
data = readFile(fileName)
48+
if data is not None:
49+
jsonObj = parseMetadataJson(data)
50+
url = extractMetadataJsonAttribute(jsonObj,fileName, "SourceURL")
51+
key = extractMetadataJsonAttribute(jsonObj,fileName,"SwaggerAuthKey")
52+
headers = {'Authorization': key}
53+
if url is not None and key is not None:
54+
apiContent = httpRequest(url , headers)
55+
saveSwaggerAPI(api, apiContent)
56+
print "DONE!!!"
57+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Read": 5,
3+
"Write": 5,
4+
"PartitionKey": {
5+
"Type": "String",
6+
"Name": "id"
7+
},
8+
"Indexes": [
9+
{
10+
"Name": "MarketplaceCustomerIdIndex",
11+
"Read": 5,
12+
"Write": 5,
13+
"PartitionKey": {
14+
"Type": "String",
15+
"Name": "MarketplaceCustomerId"
16+
},
17+
"Projection": {
18+
"Type": "ALL"
19+
}
20+
}
21+
]
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.handler = (event, context, callback) => { event.response = { autoConfirmUser: true }; callback(null, event); }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Description": "Listener",
3+
"Handler": "index.handler",
4+
"Timeout": 15,
5+
"Memory": 128,
6+
"Runtime": "nodejs6.10",
7+
"Role": "@role:lambda_basic_execution@",
8+
"Environment": {
9+
"loglevel" : "@env: LOGLEVEL@"
10+
},
11+
"CWLogFilter": {
12+
"Destination": "@kinesis:outCWlogs@",
13+
"Role": "@role:CWLtoKinesisRole@"
14+
}
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const yaml = require('js-yaml')
2+
const fs = require('fs')
3+
4+
// Load Swagger as JSON
5+
// const petStoreSwaggerDefinition = require('./pet-store-prod.json')
6+
7+
// Load Swagger as YAML
8+
const petStoreSwaggerDefinition = loadYaml('./pet-store-prod.yaml')
9+
10+
const usagePlans = [{
11+
id: 'YOUR_USAGE_PLAN_ID',
12+
name: 'Free',
13+
apis: [{
14+
id: 'YOUR_API_ID',
15+
image: '/sam-logo.png',
16+
swagger: petStoreSwaggerDefinition
17+
}]
18+
}]
19+
20+
module.exports = usagePlans
21+
22+
function loadYaml (path) {
23+
try {
24+
return yaml.safeLoad(fs.readFileSync(`${__dirname}/${path}`, 'utf8'))
25+
} catch (e) {
26+
console.log(e)
27+
}
28+
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"description": "Your first API with Amazon API Gateway. This is a sample API that integrates via HTTP with our demo Pet Store endpoints",
5+
"version": "2016-11-28T18:02:46Z",
6+
"title": "PetStoreDocs"
7+
},
8+
"host": "YOUR_API_ID.execute-api.us-east-1.amazonaws.com",
9+
"basePath": "/prod",
10+
"schemes": [
11+
"https"
12+
],
13+
"paths": {
14+
"/": {
15+
"get": {
16+
"tags": [
17+
"pets"
18+
],
19+
"description": "PetStore HTML web page containing API usage information",
20+
"consumes": [
21+
"application/json"
22+
],
23+
"produces": [
24+
"text/html"
25+
],
26+
"responses": {
27+
"200": {
28+
"description": "Successful operation",
29+
"headers": {
30+
"Content-Type": {
31+
"type": "string",
32+
"description": "Media type of request"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"/pets": {
40+
"get": {
41+
"tags": [
42+
"pets"
43+
],
44+
"summary": "List all pets",
45+
"produces": [
46+
"application/json"
47+
],
48+
"parameters": [{
49+
"name": "type",
50+
"in": "query",
51+
"description": "The type of pet to retrieve",
52+
"required": false,
53+
"type": "string"
54+
}, {
55+
"name": "page",
56+
"in": "query",
57+
"description": "Page number of results to return.",
58+
"required": false,
59+
"type": "string"
60+
}],
61+
"responses": {
62+
"200": {
63+
"description": "Successful operation",
64+
"schema": {
65+
"$ref": "#/definitions/Empty"
66+
},
67+
"headers": {
68+
"Access-Control-Allow-Origin": {
69+
"type": "string",
70+
"description": "URI that may access the resource"
71+
}
72+
}
73+
}
74+
},
75+
"security": [{
76+
"api_key": []
77+
}]
78+
},
79+
"post": {
80+
"tags": [
81+
"pets"
82+
],
83+
"summary": "Create a pet",
84+
"produces": [
85+
"application/json"
86+
],
87+
"responses": {
88+
"200": {
89+
"description": "Successful operation",
90+
"schema": {
91+
"$ref": "#/definitions/Empty"
92+
},
93+
"headers": {
94+
"Access-Control-Allow-Origin": {
95+
"type": "string",
96+
"description": "URI that may access the resource"
97+
}
98+
}
99+
}
100+
},
101+
"security": [{
102+
"api_key": []
103+
}]
104+
},
105+
"options": {
106+
"consumes": [
107+
"application/json"
108+
],
109+
"produces": [
110+
"application/json"
111+
],
112+
"responses": {
113+
"200": {
114+
"description": "Successful operation",
115+
"schema": {
116+
"$ref": "#/definitions/Empty"
117+
},
118+
"headers": {
119+
"Access-Control-Allow-Origin": {
120+
"type": "string",
121+
"description": "URI that may access the resource"
122+
},
123+
"Access-Control-Allow-Methods": {
124+
"type": "string",
125+
"description": "Method or methods allowed when accessing the resource"
126+
},
127+
"Access-Control-Allow-Headers": {
128+
"type": "string",
129+
"description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request."
130+
}
131+
}
132+
}
133+
}
134+
}
135+
},
136+
"/pets/{petId}": {
137+
"get": {
138+
"tags": [
139+
"pets"
140+
],
141+
"summary": "Info for a specific pet",
142+
"produces": [
143+
"application/json"
144+
],
145+
"parameters": [{
146+
"name": "petId",
147+
"in": "path",
148+
"description": "The id of the pet to retrieve",
149+
"required": true,
150+
"type": "string"
151+
}],
152+
"responses": {
153+
"200": {
154+
"description": "Successful operation",
155+
"schema": {
156+
"$ref": "#/definitions/Empty"
157+
},
158+
"headers": {
159+
"Access-Control-Allow-Origin": {
160+
"type": "string",
161+
"description": "URI that may access the resource"
162+
}
163+
}
164+
}
165+
},
166+
"security": [{
167+
"api_key": []
168+
}]
169+
},
170+
"options": {
171+
"consumes": [
172+
"application/json"
173+
],
174+
"produces": [
175+
"application/json"
176+
],
177+
"parameters": [{
178+
"name": "petId",
179+
"in": "path",
180+
"description": "The id of the pet to retrieve",
181+
"required": true,
182+
"type": "string"
183+
}],
184+
"responses": {
185+
"200": {
186+
"description": "Successful operation",
187+
"schema": {
188+
"$ref": "#/definitions/Empty"
189+
},
190+
"headers": {
191+
"Access-Control-Allow-Origin": {
192+
"type": "string",
193+
"description": "URI that may access the resource"
194+
},
195+
"Access-Control-Allow-Methods": {
196+
"type": "string",
197+
"description": "Method or methods allowed when accessing the resource"
198+
},
199+
"Access-Control-Allow-Headers": {
200+
"type": "string",
201+
"description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request."
202+
}
203+
}
204+
}
205+
}
206+
}
207+
}
208+
},
209+
"securityDefinitions": {
210+
"api_key": {
211+
"type": "apiKey",
212+
"name": "x-api-key",
213+
"in": "header"
214+
}
215+
},
216+
"definitions": {
217+
"Empty": {
218+
"type": "object"
219+
}
220+
}
221+
}

0 commit comments

Comments
 (0)