项目作者: manifest

项目描述 :
Erlang client for Riak S2
高级语言: Erlang
项目地址: git://github.com/manifest/riak-s2-erlang-client.git
创建时间: 2016-10-27T13:37:31Z
项目社区:https://github.com/manifest/riak-s2-erlang-client

开源协议:MIT License

下载


Riak S2 Client

Build Status

Erlang client for Riak S2.
You can view API documentation here.
Since Riak S2 mimics Amazon S3 API, that documentation could also be helpful:
service,
bucket,
object,
error.

How To Use

Build and run the docker container.
The build script will create a user for you and store all information
required for connection to the .develop-environment file.

  1. $ ./run-docker.sh

Now we have Riak S2 initialized and started within container.
To build and start playing with the library, execute following commands in the shell:

  1. $ make app shell

Here basic operations that you can perform. Refer to documentation to get to know more.

  1. %% Initializing connection to Riak S2.
  2. {ok, S, _} = erl_scan:string(os:getenv("DEVELOP_ENVIRONMENT")),
  3. {ok, Conf} = erl_parse:parse_term(S),
  4. #{s2_user := Opts, s2_http := #{host := Host, port := Port}} = Conf,
  5. {ok, Pid} = gun:open(Host, Port, #{protocols => [http]}).
  6. %% Creating a bucket, uploading an object and get it back
  7. riaks2c_bucket:await_put(Pid, riaks2c_bucket:put(Pid, <<"test-bucket">>, Opts)),
  8. riaks2c_object:await_put(Pid, riaks2c_object:put(Pid, <<"test-bucket">>, <<"test_file">>, <<42>>, Opts)),
  9. riaks2c_object:expect_get(Pid, riaks2c_object:get(Pid, <<"test-bucket">>, <<"test_file">>, Opts)).
  10. %% [<<42>>]
  11. %% Listing buckets
  12. riaks2c_bucket:expect_list(Pid, riaks2c_bucket:list(Pid, Opts)).
  13. %% {'ListAllMyBucketsResult',[],
  14. %% {'CanonicalUser',[],
  15. %% <<"9897a3ea1c87262d4726b28b3e41c1e70bc9e20f54acdc12c5081e62f67b3323">>,
  16. %% <<"user">>},
  17. %% {'ListAllMyBucketsList',[],
  18. %% [{'ListAllMyBucketsEntry',[],<<"test-bucket">>,
  19. %% <<"2016-11-04T09:47:47.000Z">>}]}}
  20. %% Listing objects
  21. riaks2c_object:expect_list(Pid, riaks2c_object:list(Pid, <<"test-bucket">>, Opts)).
  22. %% {'ListBucketResult',[],
  23. %% undefined,<<"test-bucket">>,[],[],
  24. %% undefined,1000,[],false,
  25. %% [{'ListEntry',[],
  26. %% <<"test_file">>,<<"2016-11-04T09:47:47.000Z">>,
  27. %% <<"\"9a0364b9e99bb480dd25e1f0284c8555\"">>,<<"7">>,
  28. %% <<"STANDARD">>,
  29. %% {'CanonicalUser',[],
  30. %% <<"9897a3ea1c87262d4726b28b"...>>,
  31. %% <<"user">>}}],
  32. %% undefined}
  33. %% Cleaning up
  34. riaks2c_object:await_remove(Pid, riaks2c_object:remove(Pid, <<"test-bucket">>, <<"test_file">>, Opts)),
  35. riaks2c_bucket:await_remove(Pid, riaks2c_bucket:remove(Pid, <<"test-bucket">>, Opts)).

Troubleshooting

Using Docker container with Riak S2 on macOS, you can start getting “RequestTimeTooSkewed” error messages.
It happens because Docker synchronizes container’s time with its host OS
(which is Linux OS managed by docker-machine and isn’t macOS).
It can be fixed in this way:

  1. $ docker-machine ssh
  2. $ sudo ntpclient -s -h time.apple.com

License

The source code is provided under the terms of the MIT license.