Skip to content

Commit 8f696ae

Browse files
committed
Add a .cfformat.json file to normalize formatting
1 parent 4782318 commit 8f696ae

23 files changed

+723
-238
lines changed

.cfformat.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"array.empty_padding": true,
3+
"array.multiline.element_count": 4,
4+
"array.multiline.leading_comma": false,
5+
"array.multiline.leading_comma.padding": true,
6+
"array.multiline.min_length": 40,
7+
"array.padding": true,
8+
"binary_operators.padding": true,
9+
"brackets.padding": true,
10+
"comment.asterisks": "indent",
11+
"for_loop_semicolons.padding": true,
12+
"function_anonymous.empty_padding": false,
13+
"function_anonymous.group_to_block_spacing": "spaced",
14+
"function_anonymous.multiline.element_count": 4,
15+
"function_anonymous.multiline.leading_comma": false,
16+
"function_anonymous.multiline.leading_comma.padding": true,
17+
"function_anonymous.multiline.min_length": 40,
18+
"function_anonymous.padding": true,
19+
"function_call.empty_padding": false,
20+
"function_call.multiline.element_count": 4,
21+
"function_call.multiline.leading_comma": false,
22+
"function_call.multiline.leading_comma.padding": true,
23+
"function_call.multiline.min_length": 40,
24+
"function_call.padding": true,
25+
"function_declaration.empty_padding": false,
26+
"function_declaration.group_to_block_spacing": "spaced",
27+
"function_declaration.multiline.element_count": 0,
28+
"function_declaration.multiline.leading_comma": false,
29+
"function_declaration.multiline.leading_comma.padding": true,
30+
"function_declaration.multiline.min_length": 0,
31+
"function_declaration.padding": true,
32+
"indent_size": 4,
33+
"keywords.block_to_keyword_spacing": "spaced",
34+
"keywords.empty_group_spacing": false,
35+
"keywords.group_to_block_spacing": "spaced",
36+
"keywords.padding_inside_group": true,
37+
"keywords.spacing_to_block": "spaced",
38+
"keywords.spacing_to_group": true,
39+
"max_columns": 120,
40+
"parentheses.padding": true,
41+
"strings.attributes.quote": "double",
42+
"strings.quote": "single",
43+
"struct.empty_padding": true,
44+
"struct.multiline.element_count": 4,
45+
"struct.multiline.leading_comma": false,
46+
"struct.multiline.leading_comma.padding": true,
47+
"struct.multiline.min_length": 40,
48+
"struct.padding": true,
49+
"struct.separator": ": ",
50+
"tab_indent": false
51+
}

ModuleConfig.cfc

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ component {
66
this.description = 'This module will provide you with connectivity to the AWS API for any ColdFusion (CFML) application.';
77

88
/**
9-
* See README.md for the config struct options
10-
*/
9+
* See README.md for the config struct options
10+
*/
1111
function configure() {
1212
settings = {
1313
awsKey: '',
@@ -18,7 +18,8 @@ component {
1818
}
1919

2020
function onLoad() {
21-
binder.map( 'aws@awscfml' )
21+
binder
22+
.map( 'aws@awscfml' )
2223
.to( '#moduleMapping#.aws' )
2324
.asSingleton()
2425
.initWith( argumentCollection = settings );

aws.cfc

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ component {
1717
];
1818

1919
variables.constructorArgs = {
20-
cognitoIdentity: {apiVersion: '2014-06-30'},
20+
cognitoIdentity: { apiVersion: '2014-06-30' },
2121
dynamodb: { apiVersion: '20120810' },
2222
elastictranscoder: { apiVersion: '2012-09-25' },
2323
elasticsearch: { endpoint: '' },
@@ -29,11 +29,7 @@ component {
2929
s3: { },
3030
sns: { apiVersion: '2010-03-31' },
3131
sqs: { apiVersion: '2012-11-05' },
32-
translate: {
33-
apiVersion: '20170701',
34-
defaultSourceLanguageCode: 'es',
35-
defaultTargetLanguageCode: 'en'
36-
}
32+
translate: { apiVersion: '20170701', defaultSourceLanguageCode: 'es', defaultTargetLanguageCode: 'en' }
3733
};
3834

3935
public struct function init(

com/api.cfc

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ component accessors="true" {
66
property signer;
77
property defaultRegion;
88

9-
public any function init( required string awsKey, required string awsSecretKey, required string defaultRegion ) {
9+
public any function init(
10+
required string awsKey,
11+
required string awsSecretKey,
12+
required string defaultRegion
13+
) {
1014
variables.utils = new utils();
1115
variables.httpService = server.keyExists( 'lucee' ) ? new http.lucee( utils ) : new http.coldfusion( utils );
1216
variables.credentials = new credentials( awsKey, awsSecretKey, this );
1317
variables.signer = new signature_v4( this );
14-
variables.defaultRegion = arguments.defaultRegion.len() ? arguments.defaultRegion : utils.getSystemSetting( 'AWS_DEFAULT_REGION', '' );
18+
variables.defaultRegion = arguments.defaultRegion.len() ? arguments.defaultRegion : utils.getSystemSetting(
19+
'AWS_DEFAULT_REGION',
20+
''
21+
);
1522

1623
if ( !variables.defaultRegion.len() ) {
1724
var profile = utils.getSystemSetting( 'AWS_PROFILE', 'default' );
@@ -24,7 +31,10 @@ component accessors="true" {
2431
return this;
2532
}
2633

27-
public struct function resolveRequestSettings( struct awsCredentials = { }, string region = defaultRegion ) {
34+
public struct function resolveRequestSettings(
35+
struct awsCredentials = { },
36+
string region = defaultRegion
37+
) {
2838
if ( !awsCredentials.isEmpty() ) {
2939
awsCredentials = credentials.defaultCredentials( argumentCollection = awsCredentials );
3040
}

com/credentials.cfc

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
component {
22

3-
public any function init( string awsKey = '', string awsSecretKey = '', any api ) {
3+
public any function init(
4+
string awsKey = '',
5+
string awsSecretKey = '',
6+
any api
7+
) {
48
variables.api = api;
59
variables.iamRolePath = '169.254.169.254/latest/meta-data/iam/security-credentials/';
610
variables.iamRole = '';
@@ -15,7 +19,11 @@ component {
1519
return credentials;
1620
}
1721

18-
public struct function defaultCredentials( string awsKey = '', string awsSecretKey = '', string token = '' ) {
22+
public struct function defaultCredentials(
23+
string awsKey = '',
24+
string awsSecretKey = '',
25+
string token = ''
26+
) {
1927
return {
2028
awsKey: awsKey,
2129
awsSecretKey: awsSecretKey,
@@ -24,7 +32,10 @@ component {
2432
};
2533
}
2634

27-
private function resolveCredentials( awsKey, awsSecretKey ) {
35+
private function resolveCredentials(
36+
awsKey,
37+
awsSecretKey
38+
) {
2839
var credentials = defaultCredentials( awsKey, awsSecretKey );
2940

3041
if ( len( credentials.awsKey ) && len( credentials.awsSecretKey ) ) {
@@ -82,7 +93,9 @@ component {
8293
return req.filecontent;
8394
}
8495

85-
private void function refreshCredentials( src ) {
96+
private void function refreshCredentials(
97+
src
98+
) {
8699
var httpArgs = { };
87100
httpArgs[ 'httpMethod' ] = 'get';
88101
httpArgs[ 'path' ] = iamRolePath & iamRole;

com/http/coldfusion.cfc

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ component {
1919
var result = '';
2020
var fullPath = path & ( !queryParams.isEmpty() ? ( '?' & utils.parseQueryParams( queryParams ) ) : '' );
2121
var request_headers = utils.parseHeaders( headers );
22-
var urlPath = 'http' & (useSSL ? 's' : '') & '://' & fullPath;
23-
24-
cfhttp( url = urlPath, method = httpMethod, result = 'result', timeout = timeout ) {
22+
var urlPath = 'http' & ( useSSL ? 's' : '' ) & '://' & fullPath;
2523

24+
cfhttp(url=urlPath method=httpMethod result="result" timeout=timeout) {
2625
for ( var header in request_headers ) {
2726
if ( header.name == 'host' ) continue;
28-
cfhttpparam( type = "header", name = lcase( header.name ), value = header.value );
27+
cfhttpparam(type="header" name=lCase( header.name ) value=header.value);
2928
}
3029

31-
if ( arrayFindNoCase( [ 'POST','PUT' ], httpMethod ) && !isNull( arguments.body ) ) {
32-
cfhttpparam( type = "body", value = body );
30+
if ( arrayFindNoCase( [ 'POST', 'PUT' ], httpMethod ) && !isNull( arguments.body ) ) {
31+
cfhttpparam(type="body" value=body);
3332
}
34-
3533
}
3634
return result;
3735
}

com/http/lucee.cfc

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ component {
1919
var result = '';
2020
var fullPath = path & ( !queryParams.isEmpty() ? ( '?' & utils.parseQueryParams( queryParams ) ) : '' );
2121
var request_headers = utils.parseHeaders( headers );
22-
var urlPath = 'http' & (useSSL ? 's' : '') & '://' & fullPath;
23-
24-
http url = urlPath method = httpMethod result = "result" encodeurl = false timeout = timeout {
22+
var urlPath = 'http' & ( useSSL ? 's' : '' ) & '://' & fullPath;
2523

24+
http url=urlPath method=httpMethod result="result" encodeurl=false timeout=timeout {
2625
for ( var header in request_headers ) {
2726
if ( header.name == 'host' ) continue;
28-
httpparam type = "header" name = lcase( header.name ) value = header.value;
27+
httpparam type="header" name=lCase( header.name ) value=header.value;
2928
}
3029

31-
if ( arrayFindNoCase( [ 'POST','PUT' ], httpMethod ) && !isNull( arguments.body ) ) {
32-
httpparam type = "body" value = body;
30+
if ( arrayFindNoCase( [ 'POST', 'PUT' ], httpMethod ) && !isNull( arguments.body ) ) {
31+
httpparam type="body" value=body;
3332
}
34-
3533
}
3634
return result;
3735
}

com/signature_v4.cfc

+105-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
component {
22

3-
public any function init( required any api ) {
3+
public any function init(
4+
required any api
5+
) {
46
variables.utils = api.getUtils();
57
variables.lf = chr( 10 );
68
return this;
@@ -23,13 +25,30 @@ component {
2325
if ( len( awsCredentials.token ) ) {
2426
requestHeaders[ 'X-Amz-Security-Token' ] = awsCredentials.token;
2527
}
26-
requestHeaders.append(headers);
27-
28-
var canonicalRequest = createCanonicalRequest( httpMethod, path, queryParams, requestHeaders, payload );
29-
var stringToSign = createStringToSign( region, service, isoTime, canonicalRequest );
28+
requestHeaders.append( headers );
29+
30+
var canonicalRequest = createCanonicalRequest(
31+
httpMethod,
32+
path,
33+
queryParams,
34+
requestHeaders,
35+
payload
36+
);
37+
var stringToSign = createStringToSign(
38+
region,
39+
service,
40+
isoTime,
41+
canonicalRequest
42+
);
3043
var credentialScope = stringToSign.listGetAt( stringToSign.listLen( lf ) - 1, lf );
3144
var signedHeaders = canonicalRequest.listGetAt( canonicalRequest.listLen( lf ) - 1, lf );
32-
var signature = sign( awsCredentials, isoTime.left( 8 ), region, service, stringToSign );
45+
var signature = sign(
46+
awsCredentials,
47+
isoTime.left( 8 ),
48+
region,
49+
service,
50+
stringToSign
51+
);
3352

3453
var authorization = 'AWS4-HMAC-SHA256 ';
3554
authorization &= 'Credential=' & awsCredentials.awsKey & '/' & credentialScope & ', ';
@@ -51,17 +70,42 @@ component {
5170
required struct awsCredentials
5271
) {
5372
var isoTime = utils.iso8601();
54-
var params = {};
73+
var params = { };
5574
params.append( queryParams );
56-
params.append( getAuthorizationParams( service, region, isoTime, awsCredentials ) );
75+
params.append(
76+
getAuthorizationParams(
77+
service,
78+
region,
79+
isoTime,
80+
awsCredentials
81+
)
82+
);
5783
params[ 'X-Amz-SignedHeaders' ] = 'host';
5884
params[ 'X-Amz-Expires' ] = expires;
5985

60-
var canonicalRequest = createCanonicalRequest( httpMethod, path, params, { 'Host': host }, '', true );
61-
var stringToSign = createStringToSign( region, service, isoTime, canonicalRequest );
86+
var canonicalRequest = createCanonicalRequest(
87+
httpMethod,
88+
path,
89+
params,
90+
{ 'Host': host },
91+
'',
92+
true
93+
);
94+
var stringToSign = createStringToSign(
95+
region,
96+
service,
97+
isoTime,
98+
canonicalRequest
99+
);
62100
// writeDump( canonicalRequest );
63101
// writeDump( stringToSign );
64-
params[ 'X-Amz-Signature' ] = sign( awsCredentials, isoTime.left( 8 ), region, service, stringToSign );
102+
params[ 'X-Amz-Signature' ] = sign(
103+
awsCredentials,
104+
isoTime.left( 8 ),
105+
region,
106+
service,
107+
stringToSign
108+
);
65109
return params;
66110
}
67111

@@ -103,7 +147,13 @@ component {
103147
}
104148

105149
result.append( '' );
106-
result.append( headersParsed.map( function( header ) { return header.name; } ).toList( ';' ) );
150+
result.append(
151+
headersParsed
152+
.map( function( header ) {
153+
return header.name;
154+
} )
155+
.toList( ';' )
156+
);
107157
if ( unsignedPayload ) {
108158
result.append( 'UNSIGNED-PAYLOAD' );
109159
} else {
@@ -121,7 +171,7 @@ component {
121171
var result = [ ];
122172
result.append( 'AWS4-HMAC-SHA256' );
123173
result.append( isoTime );
124-
result.append( isoTime.left( 8 ) & '/' & region & '/' & service & '/aws4_request' );
174+
result.append( isoTime.left( 8 ) & '/' & region & '/' & service & '/aws4_request' );
125175
result.append( hash( canonicalRequest, 'SHA-256' ).lcase() );
126176
return result.toList( lf );
127177
}
@@ -133,11 +183,48 @@ component {
133183
required string service,
134184
required string stringToSign
135185
) {
136-
var signingKey = binaryDecode( hmac( isoDateShort, 'AWS4' & awsCredentials.awsSecretKey, 'hmacSHA256', 'utf-8' ), 'hex' );
137-
signingKey = binaryDecode( hmac( region, signingKey, 'hmacSHA256', 'utf-8' ), 'hex' );
138-
signingKey = binaryDecode( hmac( service, signingKey, 'hmacSHA256', 'utf-8' ), 'hex' );
139-
signingKey = binaryDecode( hmac( 'aws4_request', signingKey, 'hmacSHA256', 'utf-8' ), 'hex' );
140-
return hmac( stringToSign, signingKey, 'hmacSHA256', 'utf-8' ).lcase();
186+
var signingKey = binaryDecode(
187+
hmac(
188+
isoDateShort,
189+
'AWS4' & awsCredentials.awsSecretKey,
190+
'hmacSHA256',
191+
'utf-8'
192+
),
193+
'hex'
194+
);
195+
signingKey = binaryDecode(
196+
hmac(
197+
region,
198+
signingKey,
199+
'hmacSHA256',
200+
'utf-8'
201+
),
202+
'hex'
203+
);
204+
signingKey = binaryDecode(
205+
hmac(
206+
service,
207+
signingKey,
208+
'hmacSHA256',
209+
'utf-8'
210+
),
211+
'hex'
212+
);
213+
signingKey = binaryDecode(
214+
hmac(
215+
'aws4_request',
216+
signingKey,
217+
'hmacSHA256',
218+
'utf-8'
219+
),
220+
'hex'
221+
);
222+
return hmac(
223+
stringToSign,
224+
signingKey,
225+
'hmacSHA256',
226+
'utf-8'
227+
).lcase();
141228
}
142229

143230
}

0 commit comments

Comments
 (0)