@@ -86,9 +86,39 @@ smtp_tls = get_var_from_path_or_env(config_dir, "SMTP_TLS", "always")
8686smtp_auth = get_var_from_path_or_env ( config_dir , "SMTP_AUTH" , "always" )
8787smtp_port = get_int_from_path_or_env ( config_dir , "SMTP_PORT" , 25 )
8888
89- aws_access_key_id = get_var_from_path_or_env ( config_dir , "AWS_ACCESS_KEY_ID" , nil )
90- aws_secret_access_key = get_var_from_path_or_env ( config_dir , "AWS_SECRET_ACCESS_KEY" , nil )
91- aws_region = get_var_from_path_or_env ( config_dir , "AWS_REGION" , nil )
89+ storage = get_var_from_path_or_env ( config_dir , "PRESENTATION_STORAGE" , "local" )
90+ if storage not in [ "local" , "s3" ] , do: raise ( "Invalid PRESENTATION_STORAGE value #{ storage } " )
91+
92+ s3_access_key_id = get_var_from_path_or_env ( config_dir , "S3_ACCESS_KEY_ID" )
93+ s3_secret_access_key = get_var_from_path_or_env ( config_dir , "S3_SECRET_ACCESS_KEY" )
94+ s3_region = get_var_from_path_or_env ( config_dir , "S3_REGION" )
95+ s3_bucket = get_var_from_path_or_env ( config_dir , "S3_BUCKET" )
96+
97+ if storage == "s3" and
98+ not Enum . all? ( [ s3_access_key_id , s3_secret_access_key , s3_region , s3_bucket ] ) do
99+ raise (
100+ "S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_REGION and S3_BUCKET required when PRESENTATION_STORAGE=s3"
101+ )
102+ end
103+
104+ s3_scheme = get_var_from_path_or_env ( config_dir , "S3_SCHEME" )
105+ s3_host = get_var_from_path_or_env ( config_dir , "S3_HOST" )
106+ s3_port = get_var_from_path_or_env ( config_dir , "S3_PORT" )
107+
108+ if storage == "s3" do
109+ if ! ! s3_scheme and ! s3_host , do: "S3_HOST required if S3_SCHEME is set"
110+ if ! s3_scheme and ! ! s3_host , do: "S3_SCHEME required if S3_HOST is set"
111+ end
112+
113+ s3_public_url =
114+ get_var_from_path_or_env (
115+ config_dir ,
116+ "S3_PUBLIC_URL" ,
117+ if ( s3_scheme && s3_host ,
118+ do: s3_scheme <> s3_host <> if ( s3_port , do: ":#{ s3_port } " , else: "" ) ,
119+ else: "https://#{ s3_bucket } .s3.#{ s3_region } .amazonaws.com"
120+ )
121+ )
92122
93123same_site_cookie = get_var_from_path_or_env ( config_dir , "SAME_SITE_COOKIE" , "Lax" )
94124
@@ -176,9 +206,10 @@ config :claper,
176206
177207config :claper , :presentations ,
178208 max_file_size: max_file_size ,
179- storage: get_var_from_path_or_env ( config_dir , "PRESENTATION_STORAGE" , "local" ) ,
180- aws_bucket: get_var_from_path_or_env ( config_dir , "AWS_PRES_BUCKET" , nil ) ,
181- resolution: get_var_from_path_or_env ( config_dir , "GS_JPG_RESOLUTION" , "300x300" )
209+ storage: storage ,
210+ s3_bucket: s3_bucket ,
211+ resolution: get_var_from_path_or_env ( config_dir , "GS_JPG_RESOLUTION" , "300x300" ) ,
212+ s3_public_url: s3_public_url
182213
183214config :claper , :mail ,
184215 from: get_var_from_path_or_env ( config_dir , "MAIL_FROM" , "noreply@claper.co" ) ,
@@ -227,9 +258,10 @@ case mail_transport do
227258end
228259
229260config :ex_aws ,
230- access_key_id: aws_access_key_id ,
231- secret_access_key: aws_secret_access_key ,
232- region: aws_region ,
233- normalize_path: false
261+ access_key_id: s3_access_key_id ,
262+ secret_access_key: s3_secret_access_key ,
263+ region: s3_region ,
264+ normalize_path: false ,
265+ s3: [ scheme: s3_scheme , host: s3_host , port: s3_port ]
234266
235267config :swoosh , :api_client , Swoosh.ApiClient.Finch
0 commit comments