-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.ex
55 lines (44 loc) · 1.67 KB
/
s3.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
defmodule Mix.Tasks.Publishex.S3 do
use Mix.Task
@shortdoc "Publish a directory to S3"
@moduledoc """
Publish directory to Netlify
## Usage
mix publishex.s3 --bucket bucket_name --region us-west-1 --access_key_id access_key_id --secret_access_key secret_access_key --acl public_read
# Set a custom directory
mix publishex.s3 --bucket bucket_name --region us-west-1 --access_key_id access_key_id --secret_access_key secret_access_key --acl public_read --directory "some_dir"
You have to explicitly pass the acl so files are not accidentally made public
The values can be any of the following `private`, `public_read`, `public_read_write`, `authenticated_read`, `bucket_owner_read` or `bucket_owner_full_control`.
"""
@impl Mix.Task
def run(argv) do
Application.ensure_all_started(:httpoison)
parse_options = [
strict: [
bucket: :string,
region: :string,
directory: :string,
secret_access_key: :string,
access_key_id: :string,
acl: :string
]
]
{opts, _args, _} = OptionParser.parse(argv, parse_options)
directory = Keyword.get(opts, :directory, "doc")
bucket = Keyword.fetch!(opts, :bucket)
region = Keyword.fetch!(opts, :region)
access_key_id = Keyword.fetch!(opts, :access_key_id)
secret_access_key = Keyword.fetch!(opts, :secret_access_key)
acl = Keyword.fetch!(opts, :acl)
Publishex.publish(directory,
adapter: Publishex.Adapter.S3,
adapter_opts: [
bucket: bucket,
region: region,
access_key_id: access_key_id,
secret_access_key: secret_access_key,
acl: String.to_atom(acl)
]
)
end
end