https://github.com/stephenmoloney/arc_ovh
An ovh storage adapter for arc.
https://github.com/stephenmoloney/arc_ovh
arc cloud-storage elixir file-storage ovh
Last synced: 4 months ago
JSON representation
An ovh storage adapter for arc.
- Host: GitHub
- URL: https://github.com/stephenmoloney/arc_ovh
- Owner: stephenmoloney
- License: mit
- Created: 2017-04-20T20:25:43.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-02T15:35:41.000Z (over 7 years ago)
- Last Synced: 2025-02-01T07:31:37.857Z (4 months ago)
- Topics: arc, cloud-storage, elixir, file-storage, ovh
- Language: Elixir
- Homepage: https://hex.pm/packages/arc_ovh
- Size: 364 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ArcOvh
Use Arc with the [OVH Cloudstorage](https://www.ovh.co.uk/public-cloud/storage/)
## Installation
The package can be installed by adding `arc_ovh` to your
list of dependencies in `mix.exs`:```elixir
def deps do
[{:arc_ovh, "~> 0.2"}]
end
```## Configuration
- Configure the Arc Storage adapter
```elixir
config :arc,
storage: Arc.Storage.Ovh.Cloudstorage,
client: ArcOvh.Client.Cloudstorage,
container: "default",
default_tempurl_ttl: (30 * 24 * 60 * 60), # 30 days default time to live for signed urls.
version_timeout: (60 * 3 * 1000) # 3 minutes
```- Configure the OVH client
```elixir
config :arc_ovh, ArcOvh.Client.Cloudstorage,
adapter: Openstex.Adapters.Ovh,
ovh: [
application_key: System.get_env("APPLICATION_KEY"),
application_secret: System.get_env("APPLICATION_SECRET"),
consumer_key: System.get_env("CONSUMER_KEY")
],
keystone: [
tenant_id: System.get_env("TENANT_ID"), # mandatory, corresponds to an ovh project id or ovh servicename
user_id: System.get_env("USER_ID"), # optional, if absent a user will be created using the ovh api.
endpoint: "https://auth.cloud.ovh.net/v2.0"
],
swift: [
account_temp_url_key1: System.get_env("TEMP_URL_KEY1"), # defaults to :nil if absent
account_temp_url_key2: System.get_env("TEMP_URL_KEY2"), # defaults to :nil if absent
region: :nil # specify a region if you like. Check your OVH cloud.
],
hackney: [
timeout: 20000,
recv_timeout: 40000
]config :httpipe,
adapter: HTTPipe.Adapters.Hackney
```## Example usage
- Create Definition (see [arc](https://github.com/stavro/arc) for more information)
```elixir
defmodule DummyDefinitionThumbnail do
use Arc.Definition
@versions [:original, :thumbnail]def transform(:thumbnail, _) do
{"convert", "-strip -thumbnail 100x100^ -gravity center -extent 100x100 -format jpg", :jpg}
end
# Whitelist file extensions:
def validate({file, _}) do
file_extension = file.file_name |> Path.extname() |> String.downcase()
file_extension in ~w(.jpg .jpeg .gif .png)
end
def __storage(), do: Application.get_env(:arc, :storage, Arc.Storage.Ovh.Cloudstorage)def storage_dir(_version, {_file, scope}) do
(scope != :nil && Map.has_key?(scope, :id)) &&
"#{scope.id}" ||
""
end
def storage_dir(_version, _) do
""
enddef filename(version, {file, _scope}) do
"#{Path.basename(file.file_name) |> Path.rootname()}_#{version}"
end
end
```- Store an image and generate a url for the
`:original` version and `:thumbnail` version```elixir
defp image(), do: Path.join(__DIR__, "./assets/image.jpg") |> Path.expand(){:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
original_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :original)
thumbnail_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :thumbnail)
```- Store an image and generate a signed url for the
`:original` version and `:thumbnail` version```elixir
defp image(), do: Path.join(__DIR__, "./assets/image.jpg") |> Path.expand(){:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
original_signed_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :original, signed: :true)
thumbnail_signed_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :thumbnail, signed: :true)
```- Delete an image for all versions.
```elixir
{:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
:ok = DummyDefinitionThumbnail.delete({object_name, %{id: 1}})
```## Tests
- Tests are run against a container named `arc_ovh_test_container` on an ovh
openstack server.- Create a `test.exs` file in `config.exs` and setup a [Configuration](## Configuration)
- `mix test`
- The image used in the tests was taken in bundoran Ireland by me a few years back.
![]()
## License
[MIT Licence](LICENSE)