paketo-buildpacks / libpak

An opinionated extension to the libcnb Cloud Native Buildpack Library
Apache License 2.0
15 stars 17 forks source link

Avoid including http query parameters in downloaded (http) artifact's filename #274

Closed semmet95 closed 12 months ago

semmet95 commented 1 year ago

Describe the Enhancement

This request is in the context of Paketo's apache-tomcat buildpack. We are trying to use a presigned S3 url to download tomcat external configurations, setting the url as the value for the environment variable BP_TOMCAT_EXT_CONF_URI. Internally the buildpack calls libpak. DependencyCache's Artifact function. This function sets the name of the downloaded artifact based on the value returned by the filepath.Base(uri) function call. However, if we use an http uri with query parameters this call will try to set the filename with the query parameters included.

In our case, the S3 presigned url we are using has very long query parameter values, and when libpak tries to save the downloaded file with these parameters included in the filename, it runs into file name too long error.

Possible Solution

We can parse the uri using net/url's Parse function and then get the clean uri without the query parameters using the Path property. We can also put checks to ensure this is done only for http/https URIs.

Motivation

This would add support for presigned S3 urls to the Tomcat buildpack to provide external configurations.

We already have a PR drafted, let us know if we can mark it ready for review.

dmikusa commented 1 year ago

This sounds reasonable. I see your PR, when that's ready let us know.

semmet95 commented 1 year ago

Thanks @dmikusa for checking the PR. I've marked it as Ready for Review now.