Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

server: add s3 bucket and initial module for presigning

+33 -2
+5 -2
apps/sower/lib/sower/config.ex
··· 60 60 endpoint: %Schema{type: :string, format: :uri}, 61 61 region: %Schema{type: :string}, 62 62 access_key_id: %Schema{type: :string}, 63 - secret_access_key_file: %Schema{type: :string} 63 + secret_access_key_file: %Schema{type: :string}, 64 + bucket: %Schema{type: :string} 64 65 }, 65 - required: [:endpoint] 66 + required: [:endpoint, :region, :bucket, :access_key_id] 66 67 }, 67 68 listen_address: %Schema{ 68 69 anyOf: [ ··· 257 258 scheme: scheme <> "://", 258 259 host: host, 259 260 port: port 261 + 262 + config :sower, Sower.Storage, s3: [bucket: get_in(json_config, [:s3, :bucket])] 260 263 261 264 Logger.info("Finished loading configuration.") 262 265 end
+28
apps/sower/lib/sower/storage.ex
··· 1 + defmodule Sower.Storage do 2 + def presign_upload(file, opts \\ []) do 3 + bucket = get_in(config(), [:s3, :bucket]) 4 + expires_in = Keyword.get(opts, :expires_in, 60 * 60) 5 + headers = checksum_headers(opts) ++ Keyword.get(opts, :headers, []) 6 + 7 + :s3 8 + |> ExAws.Config.new() 9 + |> ExAws.S3.presigned_url(:put, bucket, file, 10 + expires_in: expires_in, 11 + headers: headers 12 + ) 13 + end 14 + 15 + defp checksum_headers(opts) do 16 + case Keyword.fetch(opts, :checksum_sha256) do 17 + {:ok, checksum} -> 18 + [{"x-amz-checksum-sha256", checksum}] 19 + 20 + :error -> 21 + [] 22 + end 23 + end 24 + 25 + defp config() do 26 + Application.get_env(:sower, __MODULE__) 27 + end 28 + end