Skip to content

Commit

Permalink
Merge branch 'p720'
Browse files Browse the repository at this point in the history
  • Loading branch information
justincarter committed Feb 15, 2019
2 parents 75c2d4c + 3bc00e9 commit a2b6702
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
80 changes: 55 additions & 25 deletions packages/cdn/s3.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<cfargument name="headers" type="struct" required="false" default="#structNew()#" />
<cfargument name="payload" type="any" required="false" />
<cfargument name="unsignedPayload" type="boolean" required="false" />
<cfargument name="s3Path" type="boolean" required="false" default="false" />

<cfset var result = [
arguments.method,
Expand All @@ -362,6 +363,12 @@
<cfset var key = "" />
<cfset var intermed = [] />

<cfif arguments.config.domainType eq "s3" or arguments.s3Path>
<cfset arguments.headers["host"] = arguments.config.apiEndpoint />
<cfelse>
<cfset arguments.headers["host"] = arguments.config.domain & ".s3.amazonaws.com" />
</cfif>


<!--- Query parameters --->
<cfif isStruct(arguments.queryParams)>
Expand Down Expand Up @@ -407,15 +414,14 @@
<cfargument name="headers" type="struct" required="false" default="#structNew()#" />
<cfargument name="payload" type="any" required="false" />
<cfargument name="unsignedPayload" type="boolean" required="false" />
<cfargument name="s3Path" type="boolean" required="false" default="false" />

<cfset var scope = left(arguments.timestamp, 8) & "/" & arguments.config.region & "/s3/aws4_request" />
<cfset var canonicalRequest = "" />
<cfset var stringToSign = "" />
<cfset var signingKey = "" />
<cfset var signature = "" />

<cfset arguments.headers["host"] = "#arguments.config.apiEndpoint#" />

<cfset canonicalRequest = getCanonicalRequest(argumentCollection=arguments) />
<cfset stringToSign = getStringToSign(arguments.timestamp, scope, canonicalRequest) />
<cfset signingKey = getSigningKey(arguments.config.awsSecretKey, left(arguments.timestamp, 8), arguments.config.region, "s3") />
Expand All @@ -433,6 +439,7 @@
<cfargument name="headers" type="struct" required="false" default="#structNew()#" />
<cfargument name="payload" type="any" required="false" />
<cfargument name="unsignedPayload" type="boolean" required="false" />
<cfargument name="s3Path" type="boolean" required="false" default="false" />

<cfset var signature = getAWSSignature(argumentCollection=arguments) />
<cfset var signedHeaders = listSort(structKeyList(arguments.headers, ';'), 'textnocase', 'asc', ';') />
Expand Down Expand Up @@ -539,8 +546,9 @@
config=arguments.config,
timestamp=currentDate,
method=arguments.method,
path=arguments.config.apiEndpointPrefix & urlPath,
queryParams=queryParams
path=urlPath,
queryParams=queryParams,
s3Path=arguments.s3Path
) />

<cfset urlpath = urlpath & "?#structToQueryParams(queryParams)#&X-Amz-Signature=#signature#" />
Expand Down Expand Up @@ -594,22 +602,31 @@
<cfset var path = "" />
<cfset var stDetail = structNew() />
<cfset var substituteValues = arrayNew(1) />
<cfset var urlPath = arguments.config.pathPrefix & arguments.file />
<cfset var timestamp = application.fapi.dateToISO8601(Now()) />
<cfset var stHeaders = {
"x-amz-content-sha256" = "UNSIGNED-PAYLOAD"
} />
<cfset var i = "" />
<cfset var authArgs = {} />

<cfset var urlPath = arguments.config.pathPrefix & arguments.file />
<cfif left(arguments.file,1) neq "/">
<cfset urlPath = arguments.config.pathPrefix & "/" & arguments.file />
<cfelse>
<cfset urlPath = arguments.config.pathPrefix & arguments.file />
</cfif>

<!--- create signature --->
<cfset var signature = getAWSAuthorization(
<cfset var authArgs = {
config=arguments.config,
timestamp=timestamp,
method="HEAD",
path=arguments.config.apiEndpointPrefix & urlPath,
headers=stHeaders,
unsignedPayload=true
) />
unsignedPayload=true,
s3Path=true
} />
<cfset var signature = getAWSAuthorization(argumentCollection=authArgs) />

<!--- REST call --->
<cfhttp method="HEAD" url="https://#arguments.config.apiEndpoint##arguments.config.apiEndpointPrefix##urlPath#" charset="utf-8" result="stResponse" timeout="1800">
Expand Down Expand Up @@ -641,7 +658,9 @@
<cfset stDetail["result"] = results>
<cfset substituteValues = arrayNew(1)>
<cfset substituteValues[1] = results.error.message.XMLText>
<cfset application.fapi.throw(message="Error accessing S3 API: {1}",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
<cfset substituteValues[2] = getCanonicalRequest(argumentCollection=authArgs)>
<cfset substituteValues[3] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [canonical request={2}, signature={3}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
</cfif>
<cfelseif NOT listFindNoCase("200,204",listfirst(stResponse.statuscode," "))>
<cfset substituteValues = arrayNew(1)>
Expand Down Expand Up @@ -1060,6 +1079,7 @@
<cfset var path = "" />
<cfset var stDetail = structNew() />
<cfset var substituteValues = arrayNew(1) />
<cfset var authArgs = {} />


<cfif structkeyexists(arguments,"localfile")>
Expand Down Expand Up @@ -1104,14 +1124,16 @@
<cfset stHeaders["x-amz-content-sha256"] = "UNSIGNED-PAYLOAD" />

<!--- create signature --->
<cfset signature = getAWSAuthorization(
<cfset authArgs = {
config=arguments.config,
timestamp=timestamp,
method="PUT",
path=arguments.config.apiEndpointPrefix & path,
headers=stHeaders,
unsignedPayload=true
) />
unsignedPayload=true,
s3Path=true
} />
<cfset signature = getAWSAuthorization(argumentCollection=authArgs) />

<!--- REST call --->
<cfhttp method="PUT" url="https://#arguments.config.apiEndpoint##arguments.config.apiEndpointPrefix##path#" charset="utf-8" result="cfhttp" timeout="1800">
Expand Down Expand Up @@ -1140,8 +1162,9 @@
<cfset stDetail["result"] = results>
<cfset substituteValues = arrayNew(1)>
<cfset substituteValues[1] = results.error.message.XMLText>
<cfset substituteValues[2] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [signature={2}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
<cfset substituteValues[2] = getCanonicalRequest(argumentCollection=authArgs)>
<cfset substituteValues[3] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [canonical request={2}, signature={3}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
</cfif>
<cfelseif NOT listFindNoCase("200,204",listfirst(cfhttp.statuscode," "))>
<cfset substituteValues = arrayNew(1)>
Expand All @@ -1167,6 +1190,7 @@
<cfset var stDetail = structNew() />
<cfset var substituteValues = arrayNew(1) />
<cfset var header = "" />
<cfset var authArgs = {} />

<cfif left(arguments.file,1) neq "/">
<cfset path = arguments.config.pathPrefix & "/" & arguments.file />
Expand Down Expand Up @@ -1198,7 +1222,7 @@
<cfset stHeaders["x-amz-content-sha256"] = "UNSIGNED-PAYLOAD" />

<!--- create signature --->
<cfset signature = getAWSAuthorization(
<cfset authArgs = {
config=arguments.config,
timestamp=timestamp,
method="PUT",
Expand All @@ -1207,8 +1231,10 @@
"acl"=""
},
headers=stHeaders,
unsignedPayload=true
) />
unsignedPayload=true,
s3Path=true
} />
<cfset signature = getAWSAuthorization(argumentCollection=authArgs) />

<!--- REST call --->
<cfhttp method="PUT" url="https://#arguments.config.apiEndpoint##arguments.config.apiEndpointPrefix##path#?acl" charset="utf-8" result="cfhttp" timeout="1800">
Expand All @@ -1234,8 +1260,9 @@
<cfset stDetail["result"] = results>
<cfset substituteValues = arrayNew(1)>
<cfset substituteValues[1] = results.error.message.XMLText>
<cfset substituteValues[2] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [signature={2}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
<cfset substituteValues[2] = getCanonicalRequest(argumentCollection=authArgs)>
<cfset substituteValues[3] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [canonical request: {2}, signature={3}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
</cfif>
<cfelseif NOT listFindNoCase("200,204",listfirst(cfhttp.statuscode," "))>
<cfset substituteValues = arrayNew(1)>
Expand All @@ -1261,6 +1288,7 @@
<cfset var stHeaders = {
"x-amz-content-sha256" = "UNSIGNED-PAYLOAD"
} />
<cfset var authArgs = {} />

<cfif left(arguments.file,1) neq "/">
<cfset path = arguments.config.pathPrefix & "/" & arguments.file />
Expand All @@ -1269,14 +1297,16 @@
</cfif>

<!--- create signature --->
<cfset signature = getAWSAuthorization(
<cfset authArgs = {
config=arguments.config,
timestamp=timestamp,
method="DELETE",
path=arguments.config.apiEndpointPrefix & path,
headers=stHeaders,
unsignedPayload=true
) />
unsignedPayload=true,
s3Path=true
} />
<cfset signature = getAWSAuthorization(argumentCollection=authArgs) />

<!--- REST call --->
<cfhttp method="DELETE" url="https://#arguments.config.apiEndpoint##arguments.config.apiEndpointPrefix##path#" result="cfhttp" timeout="1800">
Expand All @@ -1301,9 +1331,9 @@
<cfset stDetail["signature"] = replace(signature, chr(10), "\n", "ALL")>
<cfset stDetail["result"] = results>
<cfset substituteValues = arrayNew(1)>
<cfset substituteValues[1] = results.error.message.XMLText>
<cfset substituteValues[2] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [signature={2}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
<cfset substituteValues[2] = getCanonicalRequest(argumentCollection=authArgs)>
<cfset substituteValues[3] = signature>
<cfset application.fapi.throw(message="Error accessing S3 API: {1} [canonical request: {2}, signature={3}]",type="s3error",detail=serializeJSON(stDetail),substituteValues=substituteValues) />
</cfif>
<cfelseif NOT listFindNoCase("200,204",listfirst(cfhttp.statuscode," "))>
<cfset substituteValues = arrayNew(1)>
Expand Down
4 changes: 2 additions & 2 deletions packages/formtools/image.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@
<!--- Check if either the new height or new width is smaller than the arugments width and height. If yes, then padding is needed --->
<cfif newImage.height lt arguments.Height or newImage.width lt arguments.Width>
<!--- Create a temp image with background color = PadColor --->
<cfset padImage = ImageNew("",arguments.Width,arguments.Height,"argb",arguments.PadColor) />
<cfset padImage = ImageNew("",arguments.Width,arguments.Height,"rgb",arguments.PadColor) />
<!--- Because ImageScaleToFit doesn't always work correctly (it may make the width or height it used to scale by smaller than it should have been... usually by 1 pixel) we need to account for that becfore we paste --->
<!--- Either use ceiling() or fix() depending on which side you want the extra pixeled padding on (This won't be a problem if Adobe fixes the bug in ImageScaleToFit in a future version of ColdFusion) --->
<cfset XCoordinate = ceiling((arguments.Width - newImage.Width)/2) />
Expand Down Expand Up @@ -1544,7 +1544,7 @@
<cfargument name="backgroundColor" type="string" required="false" default="white" hint="background color of image." />

<cfset var imgInfo = imageInfo(arguments.oImage)/>
<cfset var myImage = imageNew("", imgInfo.width, imgInfo.height, "argb", arguments.backgroundColor) />
<cfset var myImage = imageNew("", imgInfo.width, imgInfo.height, "rgb", arguments.backgroundColor) />
<cfset imagePaste(myImage, arguments.oImage, 0, 0) />

<cfreturn myImage />
Expand Down
2 changes: 1 addition & 1 deletion patch.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11
12

0 comments on commit a2b6702

Please sign in to comment.