I tried to fetch titles of objects using req with req_s3 plugin.
def new_req(options \\ []) when is_list(options) do
access_key = System.fetch_env!("MINIO_ACCESS_KEY")
secret_access_key = System.fetch_env!("MINIO_SECRET_KEY")
endpoint_url = System.fetch_env!("MINIO_URL")
Req.new(
base_url: "#{endpoint_url}/justrunit",
aws_sigv4: [service: :s3, access_key_id: access_key, secret_access_key: secret_access_key],
retry: :transient
)
|> ReqS3.attach()
|> Req.merge(options)
end
def list_objects(prefix) do
req = new_req() |> ReqS3.attach()
case Req.get!(req, params: [prefix: prefix]) do
%Req.Response{status: 200, body: body} -> {:ok, body}
response -> {:error, response}
end
end
And it returned XML instead of elixir data structures.
I printed out request steps after attaching ReqS3 and it seems fine.
web-1 | Step: {:put_user_agent, &Req.Steps.put_user_agent/1}
web-1 | Step: {:compressed, &Req.Steps.compressed/1}
web-1 | Step: {:encode_body, &Req.Steps.encode_body/1}
web-1 | Step: {:put_base_url, &Req.Steps.put_base_url/1}
web-1 | Step: {:auth, &Req.Steps.auth/1}
web-1 | Step: {:put_params, &Req.Steps.put_params/1}
web-1 | Step: {:put_path_params, &Req.Steps.put_path_params/1}
web-1 | Step: {:put_range, &Req.Steps.put_range/1}
web-1 | Step: {:cache, &Req.Steps.cache/1}
web-1 | Step: {:put_plug, &Req.Steps.put_plug/1}
web-1 | Step: {:compress_body, &Req.Steps.compress_body/1}
web-1 | Step: {:checksum, &Req.Steps.checksum/1}
web-1 | Step: {:s3_handle_url, #Function<2.113709267/1 in ReqS3.handle_s3_url>}
web-1 | Step: {:put_aws_sigv4, &Req.Steps.put_aws_sigv4/1}
Putting XML into ReqS3.XML.parse_s3
works as it should i’d rather use ReqS3.attach()
.
My project is using MinIO as a local S3 db so you can get it from github and run:
git clone https://github.com/justrundotit/justrunit
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
Thanks for your time, all questions are welcome