Skip to content

Commit 767fc8a

Browse files
authored
Fixing default static files (awslabs#596)
1 parent a7ae1c5 commit 767fc8a

Some content is hidden

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

54 files changed

+6084
-70
lines changed

.gitignore

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# top-level and lambda function specific
22
/node_modules
33
/coverage
4-
/lambdas/static-asset-uploader/build
4+
!/lambdas/static-asset-uploader/build
55
/lambdas/coverage
66

77
# devportal specific
8-
/dev-portal/build
8+
!/dev-portal/build
99

1010
# we're committing the artifacts, don't need the modules
1111
# note, though, that we do need our patched version of swagger-ui and not the npm version
@@ -16,15 +16,12 @@ dev-portal/node_modules/swagger-ui/*
1616
!dev-portal/node_modules/swagger-ui/package.json
1717
!dev-portal/node_modules/swagger-ui/dist/
1818

19-
# built artifacts
20-
/dev-portal/build
21-
2219
# coverage reporting
2320
/dev-portal/coverage
2421

2522
# details about setup needed for local dev; these are sensitive, do not commit them!
2623
/dev-portal/deployer.config.js
27-
/dev-portal/public/config.js
24+
**/config.js
2825

2926
# misc
3027
npm-debug.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Prerequisites
2+
For the JavaScript SDK to work your APIs need to support CORS. The Amazon API Gateway developer guide explains how to [setup CORS for an endpoint]().
3+
The generated SDK depends on third-party libraries. Include all of the scripts in your webpage
4+
5+
<script type="text/javascript" src="lib/axios/dist/axios.standalone.js"></script>
6+
<script type="text/javascript" src="lib/CryptoJS/rollups/hmac-sha256.js"></script>
7+
<script type="text/javascript" src="lib/CryptoJS/rollups/sha256.js"></script>
8+
<script type="text/javascript" src="lib/CryptoJS/components/hmac.js"></script>
9+
<script type="text/javascript" src="lib/CryptoJS/components/enc-base64.js"></script>
10+
<script type="text/javascript" src="lib/url-template/url-template.js"></script>
11+
<script type="text/javascript" src="lib/apiGatewayCore/sigV4Client.js"></script>
12+
<script type="text/javascript" src="lib/apiGatewayCore/apiGatewayClient.js"></script>
13+
<script type="text/javascript" src="lib/apiGatewayCore/simpleHttpClient.js"></script>
14+
<script type="text/javascript" src="lib/apiGatewayCore/utils.js"></script>
15+
<script type="text/javascript" src="apigClient.js"></script>
16+
17+
# Use the SDK in your project
18+
19+
To initialize the most basic form of the SDK:
20+
21+
```
22+
var apigClient = apigClientFactory.newClient();
23+
```
24+
25+
Calls to an API take the form outlined below. Each API call returns a promise, that invokes either a success and failure callback
26+
27+
```
28+
var params = {
29+
//This is where any header, path, or querystring request params go. The key is the parameter named as defined in the API
30+
param0: '',
31+
param1: ''
32+
};
33+
var body = {
34+
//This is where you define the body of the request
35+
};
36+
var additionalParams = {
37+
//If there are any unmodeled query parameters or headers that need to be sent with the request you can add them here
38+
headers: {
39+
param0: '',
40+
param1: ''
41+
},
42+
queryParams: {
43+
param0: '',
44+
param1: ''
45+
}
46+
};
47+
48+
apigClient.methodName(params, body, additionalParams)
49+
.then(function(result){
50+
//This is where you would put a success callback
51+
}).catch( function(result){
52+
//This is where you would put an error callback
53+
});
54+
```
55+
56+
#Using AWS IAM for authorization
57+
To initialize the SDK with AWS Credentials use the code below. Note, if you use credentials all requests to the API will be signed. This means you will have to set the appropiate CORS accept-* headers for each request.
58+
59+
```
60+
var apigClient = apigClientFactory.newClient({
61+
accessKey: 'ACCESS_KEY',
62+
secretKey: 'SECRET_KEY',
63+
sessionToken: 'SESSION_TOKEN', //OPTIONAL: If you are using temporary credentials you must include the session token
64+
region: 'us-east-1' // OPTIONAL: The region where the API is deployed (e.g. eu-west-1, us-west-2). Defaults to us-east-1.
65+
});
66+
```
67+
68+
#Using API Keys
69+
To use an API Key with the client SDK you can pass the key as a parameter to the Factory object. Note, if you use an apiKey it will be attached as the header 'x-api-key' to all requests to the API will be signed. This means you will have to set the appropiate CORS accept-* headers for each request.
70+
71+
```
72+
var apigClient = apigClientFactory.newClient({
73+
apiKey: 'API_KEY'
74+
});
75+
```
76+
77+
78+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/* eslint-disable */
2+
/*
3+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
var apigClientFactory = {};
18+
apigClientFactory.newClient = function (config) {
19+
var apigClient = { };
20+
if(config === undefined) {
21+
config = {
22+
accessKey: '',
23+
secretKey: '',
24+
sessionToken: '',
25+
region: '',
26+
apiKey: undefined,
27+
defaultContentType: 'application/json',
28+
defaultAcceptType: 'application/json'
29+
};
30+
}
31+
if(config.accessKey === undefined) {
32+
config.accessKey = '';
33+
}
34+
if(config.secretKey === undefined) {
35+
config.secretKey = '';
36+
}
37+
if(config.apiKey === undefined) {
38+
config.apiKey = '';
39+
}
40+
if(config.sessionToken === undefined) {
41+
config.sessionToken = '';
42+
}
43+
if(config.region === undefined) {
44+
config.region = 'YOUR_PRIMARY_AWS_REGION';
45+
}
46+
//If defaultContentType is not defined then default to application/json
47+
if(config.defaultContentType === undefined) {
48+
config.defaultContentType = 'application/json';
49+
}
50+
//If defaultAcceptType is not defined then default to application/json
51+
if(config.defaultAcceptType === undefined) {
52+
config.defaultAcceptType = 'application/json';
53+
}
54+
55+
// extract endpoint and path from url
56+
let invokeUrl = `https://${window.config.restApiId}.execute-api.${window.config.region}.amazonaws.com/prod`,
57+
endpoint = /(^https?:\/\/[^\/]+)/g.exec(invokeUrl)[1],
58+
pathComponent = invokeUrl.substring(endpoint.length)
59+
60+
var sigV4ClientConfig = {
61+
accessKey: config.accessKey,
62+
secretKey: config.secretKey,
63+
sessionToken: config.sessionToken,
64+
serviceName: 'execute-api',
65+
region: config.region,
66+
endpoint: endpoint,
67+
defaultContentType: config.defaultContentType,
68+
defaultAcceptType: config.defaultAcceptType
69+
};
70+
71+
var authType = 'NONE';
72+
if (sigV4ClientConfig.accessKey !== undefined && sigV4ClientConfig.accessKey !== '' && sigV4ClientConfig.secretKey !== undefined && sigV4ClientConfig.secretKey !== '') {
73+
authType = 'AWS_IAM';
74+
}
75+
76+
var simpleHttpClientConfig = {
77+
endpoint: endpoint,
78+
defaultContentType: config.defaultContentType,
79+
defaultAcceptType: config.defaultAcceptType
80+
};
81+
82+
var apiGatewayClient = apiGateway.core.apiGatewayClientFactory.newClient(simpleHttpClientConfig, sigV4ClientConfig);
83+
84+
85+
86+
apigClient.rootOptions = function (params, body, additionalParams) {
87+
if(additionalParams === undefined) { additionalParams = {}; }
88+
89+
apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
90+
91+
var rootOptionsRequest = {
92+
verb: 'options'.toUpperCase(),
93+
path: pathComponent + uritemplate('/').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
94+
headers: apiGateway.core.utils.parseParametersToObject(params, []),
95+
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
96+
body: body
97+
};
98+
99+
100+
return apiGatewayClient.makeRequest(rootOptionsRequest, authType, additionalParams, config.apiKey);
101+
};
102+
103+
104+
apigClient.get = function (path, params, body, additionalParams) {
105+
if(additionalParams === undefined) { additionalParams = {}; }
106+
107+
apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
108+
109+
var proxyOptionsRequest = {
110+
verb: 'GET',
111+
path: pathComponent + path,
112+
headers: apiGateway.core.utils.parseParametersToObject(params, []),
113+
queryParams: apiGateway.core.utils.parseParametersToObject(params, ['start', 'end', 'sdkType']),
114+
body: body
115+
};
116+
117+
return apiGatewayClient.makeRequest(proxyOptionsRequest, authType, additionalParams, config.apiKey);
118+
};
119+
120+
apigClient.post = function (path, params, body, additionalParams) {
121+
if(additionalParams === undefined) { additionalParams = {}; }
122+
123+
apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
124+
125+
var proxyOptionsRequest = {
126+
verb: 'POST',
127+
path: pathComponent + path,
128+
headers: apiGateway.core.utils.parseParametersToObject(params, []),
129+
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
130+
body: body
131+
};
132+
133+
134+
return apiGatewayClient.makeRequest(proxyOptionsRequest, authType, additionalParams, config.apiKey);
135+
};
136+
137+
apigClient.put = function (path, params, body, additionalParams) {
138+
if(additionalParams === undefined) { additionalParams = {}; }
139+
140+
apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
141+
142+
var proxyOptionsRequest = {
143+
verb: 'PUT',
144+
path: pathComponent + path,
145+
headers: apiGateway.core.utils.parseParametersToObject(params, []),
146+
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
147+
body: body
148+
};
149+
150+
151+
return apiGatewayClient.makeRequest(proxyOptionsRequest, authType, additionalParams, config.apiKey);
152+
};
153+
154+
apigClient.delete = function (path, params, body, additionalParams) {
155+
if(additionalParams === undefined) { additionalParams = {}; }
156+
157+
apiGateway.core.utils.assertParametersDefined(params, [], ['body']);
158+
159+
var proxyOptionsRequest = {
160+
verb: 'DELETE',
161+
path: pathComponent + path,
162+
headers: apiGateway.core.utils.parseParametersToObject(params, []),
163+
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
164+
body: body
165+
};
166+
167+
168+
return apiGatewayClient.makeRequest(proxyOptionsRequest, authType, additionalParams, config.apiKey);
169+
};
170+
171+
172+
return apigClient;
173+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
CryptoJS v3.1.2
3+
code.google.com/p/crypto-js
4+
(c) 2009-2013 by Jeff Mott. All rights reserved.
5+
code.google.com/p/crypto-js/wiki/License
6+
*/
7+
(function () {
8+
// Shortcuts
9+
var C = CryptoJS;
10+
var C_lib = C.lib;
11+
var WordArray = C_lib.WordArray;
12+
var C_enc = C.enc;
13+
14+
/**
15+
* Base64 encoding strategy.
16+
*/
17+
var Base64 = C_enc.Base64 = {
18+
/**
19+
* Converts a word array to a Base64 string.
20+
*
21+
* @param {WordArray} wordArray The word array.
22+
*
23+
* @return {string} The Base64 string.
24+
*
25+
* @static
26+
*
27+
* @example
28+
*
29+
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
30+
*/
31+
stringify: function (wordArray) {
32+
// Shortcuts
33+
var words = wordArray.words;
34+
var sigBytes = wordArray.sigBytes;
35+
var map = this._map;
36+
37+
// Clamp excess bits
38+
wordArray.clamp();
39+
40+
// Convert
41+
var base64Chars = [];
42+
for (var i = 0; i < sigBytes; i += 3) {
43+
var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
44+
var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
45+
var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
46+
47+
var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
48+
49+
for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
50+
base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
51+
}
52+
}
53+
54+
// Add padding
55+
var paddingChar = map.charAt(64);
56+
if (paddingChar) {
57+
while (base64Chars.length % 4) {
58+
base64Chars.push(paddingChar);
59+
}
60+
}
61+
62+
return base64Chars.join('');
63+
},
64+
65+
/**
66+
* Converts a Base64 string to a word array.
67+
*
68+
* @param {string} base64Str The Base64 string.
69+
*
70+
* @return {WordArray} The word array.
71+
*
72+
* @static
73+
*
74+
* @example
75+
*
76+
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
77+
*/
78+
parse: function (base64Str) {
79+
// Shortcuts
80+
var base64StrLength = base64Str.length;
81+
var map = this._map;
82+
83+
// Ignore padding
84+
var paddingChar = map.charAt(64);
85+
if (paddingChar) {
86+
var paddingIndex = base64Str.indexOf(paddingChar);
87+
if (paddingIndex != -1) {
88+
base64StrLength = paddingIndex;
89+
}
90+
}
91+
92+
// Convert
93+
var words = [];
94+
var nBytes = 0;
95+
for (var i = 0; i < base64StrLength; i++) {
96+
if (i % 4) {
97+
var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
98+
var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
99+
words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
100+
nBytes++;
101+
}
102+
}
103+
104+
return WordArray.create(words, nBytes);
105+
},
106+
107+
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
108+
};
109+
}());

0 commit comments

Comments
 (0)