Skip to content

Commit

Permalink
Remove Expires header from S3 put_object requests, it doesn't do wh…
Browse files Browse the repository at this point in the history
…at I thought it did
  • Loading branch information
jzimbel-mbta committed Oct 15, 2024
1 parent 7b0660a commit b793df0
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/arrow/gtfs/archive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,24 @@ defmodule Arrow.Gtfs.Archive do
end

@spec upload_to_s3(iodata) :: {:ok, s3_uri :: String.t()} | {:ok, :disabled} | {:error, term}
def upload_to_s3(zip_iodata, now \\ DateTime.utc_now()) do
def upload_to_s3(zip_iodata) do
config = Config.get()

if config.enabled? do
do_upload(zip_iodata, config, now)
do_upload(zip_iodata, config)
else
{:ok, :disabled}
end
end

defp do_upload(zip_iodata, config, now) do
defp do_upload(zip_iodata, config) do
path = get_upload_path(config)
expires_timestamp = get_expires_timestamp(now)

upload_op =
zip_iodata
|> List.wrap()
|> Stream.map(&IO.iodata_to_binary/1)
|> ExAws.S3.upload(config.bucket, path,
expires: expires_timestamp,
content_type: "application/zip"
)
|> ExAws.S3.upload(config.bucket, path, content_type: "application/zip")

{mod, fun} = config.request_fn

Expand Down Expand Up @@ -134,12 +130,6 @@ defmodule Arrow.Gtfs.Archive do
|> Path.join()
end

defp get_expires_timestamp(utc_now) do
utc_now
|> DateTime.add(div(365, 2), :day)
|> Calendar.strftime("%a, %d %b %Y %X GMT")
end

defimpl Unzip.FileAccess do
def pread(archive, offset, length) do
case :file.pread(archive.fd, offset, length) do
Expand Down

0 comments on commit b793df0

Please sign in to comment.