A pure Erlang utility library for interfacing with Google Cloud Storage, based on Enenra, jsone and ibrowse. Redesigned as a utility, it aims to support flexible handling of multiple credentials and operation parallelism.
- This is a pure Erlang variant of the original Enera Library.
Named after Saci which is a character in Brazilian folklore, a one-legged black or youngster, who smokes a pipe and wears a magical red cap that enables him to disappear and reappear wherever he wishes (usually in the middle of a dust devil). Saci The new name is a homage to its predecessor.
`.
:soydho+oos+-
+mdddddddh-
`:dmmmdddh`
+mddhhhd-
` `:ss/-` -ydddmm-.-.
`/+++oo+//yddsoodd+o:./hh.
`/os:. .mdydd: so+/.
ymmhddh- :d`
:dddh:-yhsys
oddh: .+o`
sdhh+-
`/ohdhy/
./hd+
+dh-
ys`
.yd`
:hdo
```..yds: `
```.-:-.
- Erlang/OTP R18 or R19
- R20 has backward incompatible API changes
- rebar3 3.0.0 or higher
$ rebar3 compile
$ rebar3 xref
Note that the test suite expects to find an environment variable named GOOGLE_APPLICATION_CREDENTIALS which specifies the path to your Google Cloud Platform service credentials. This JSON formatted file is created via the Cloud Console, as described in the setup section below. This file contains your private key, so be sure to store this file with permissions that prevent exposure to third parties.
To include saci as a dependency in your release, add it to the list of dependencies in your rebar.config file, like so:
{deps, [
{saci, {git, "https://github.com/xmppjingle/saci", {tag, "0.0.1"}}}
]}.
To have the saci application started automatically, be sure to include saci in the applications list of your application configuration before building a release. You may also want to add jiffy to the list of included_applications, and hackney to the list of applications.
Below is a simple example in which a bucket is created and a file is uploaded to that bucket. This also demonstrates loading the credentials from a file and computing an MD5 checksum of a file to be uploaded to a bucket.
1> rr("include/saci.hrl").
[access_token,bucket,credentials,object]
2> Credentials = os:getenv("GOOGLE_APPLICATION_CREDENTIALS").
"/Users/nfiedler/.gcloud/testing.json"
3> {ok, Creds} = saci:load_credentials(Credentials).
{ok,#credentials{type = <<"service_account">>,
project_id = <<"a-project">>,
private_key_id = <<"a-private-key-id">>,
private_key = <<"a-private-key">>,
client_email = <<"an-email-address">>,
client_id = <<"a-client-id">>}}
5> saci:insert_bucket(#bucket{
name = <<"0136d00f-a942-11e6-8f9a-3c07547e18a6-saci-1234">>,
location = <<"US-WEST1">>,
storageClass = <<"STANDARD">>}, Creds).
{ok,#bucket{id = <<"a-bucket-id">>,
projectNumber = <<"a-project-number">>,
name = <<"0136d00f-a942-11e6-8f9a-3c07547e18a6-saci-1234">>,
timeCreated = <<"2016-11-18T22:25:54.239Z">>,
updated = <<"2016-11-18T22:25:54.239Z">>,
location = <<"US-WEST1">>,
storageClass = <<"STANDARD">>}}
6> {ok, Md5} = saci:compute_md5("test/saci_SUITE_data/Saci_Perere_por_Marconi.jpg").
{ok,<<"kq56YDAH2p4mzAqrQw84kQ==">>}
7> saci:upload_file("test/saci_SUITE_data/Saci_Perere_por_Marconi.jpg", #object{
name = <<"my_image">>,
bucket = <<"0136d00f-a942-11e6-8f9a-3c07547e18a6-saci-1234">>,
contentType = <<"image/jpeg">>,
md5Hash = Md5,
size = 107302}, Creds).
{ok,#object{id = <<"a-bucket-id/name/an-object-id">>,
name = <<"my_image">>,
bucket = <<"0136d00f-a942-11e6-8f9a-3c07547e18a6-saci-1234">>,
contentType = <<"image/jpeg">>,
timeCreated = <<"2016-11-18T22:28:01.232Z">>,
updated = <<"2016-11-18T22:28:01.232Z">>,
storageClass = <<"STANDARD">>,
size = <<"107302">>,
md5Hash = <<"kq56YDAH2p4mzAqrQw84kQ==">>}}- Visit https://console.cloud.google.com/ and log in with your account.
- Select an existing project or create a new one.
- Note the Project ID as that will be necessary when connecting via saci.
- Using the menu, select API Manager, then Credentials.
- On the Credentials page, select the Create credentials drop-down, then select Service account key.
- From the Service account drop-down, select an existing service account or create a new one.
- For Key type, select the JSON key option, then select Create. The file automatically downloads to your computer.
- Put the
*.jsonfile you just downloaded in a directory of your choosing. This directory must be private, but accessible to your application.
The credentials file must be readable by the application, but should not be readable by casual users. Likewise, it is possible, if the server process crashes, that the private keys will end up in the log file (they are an argument to the API, after all). As such, the log files should be protected from unintended exposure to third parties.
BSD 3-Clause, see the LICENSE file.
Test Image by Jean Marconi from Brasil (https://www.flickr.com/people/88491322@N00)