Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eirenauts-infra committed Jun 29, 2016
0 parents commit 373211e
Show file tree
Hide file tree
Showing 46 changed files with 4,786 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/_build
/cover
/deps
/.deprecated
/doc
/.idea
/config/dev.exs

erl_crash.dump
*.ez
mix
mix.lock
.env

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## v0.2.0

- Add functions `delete_object/3`, `delete_object!/3`
- Remove some duplicated docs from the `Openstex.Services.Swift.V1.Helpers` and have them on `@callback` only. (unfinished)
22 changes: 22 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# MIT License

Copyright (c) 2016 Stephen Moloney

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Openstex [![Build Status](https://travis-ci.org/stephenmoloney/openstex_test.svg)](https://travis-ci.org/stephenmoloney/openstex_test) [![Hex Version](http://img.shields.io/hexpm/v/openstex.svg?style=flat)](https://hex.pm/packages/openstex) [![Hex docs](http://img.shields.io/badge/hex.pm-docs-green.svg?style=flat)](https://hexdocs.pm/openstex)

An elixir client for making requests to [Openstack compliant apis](http://developer.openstack.org/api-ref.html).

#### Supported services

| Openstack Service | Supported |
|---|---|
| Identity 2.0 (Keystone) | :heavy_check_mark: |
| Object Storage 1.0 (Swift) | :heavy_check_mark: |


## Features

1. Query modules for generating query structs which can subsequently be sent to the API using a `request` function.
Example: *Creating a container:* [create_container/3](https://github.com/stephenmoloney/openstex/blob/master/lib/services/swift/v1/query.ex#L88).

2. Helper modules for

a. One liners for sending queries to the client API. Example: *Getting the swift public url:* [get_public_url/0](https://github.com/stephenmoloney/openstex/blob/master/lib/services/swift/v1/helpers.ex#L21)

b. Sending more complex queries such as multi-step queries to the client API. Example: *Getting all objects in a pseudofolder:* [list_objects/3](https://github.com/stephenmoloney/openstex/blob/master/lib/services/swift/v1/helpers.ex#L247)

3. The `Request.request/3` and `Transformation.request/3` protocols and associated implementations that send the queries and process the response.
Theoretically, the protocol can be extended so that queries are processed in a different manner is so required later during development
for particular request types.

4. Adapter modules for [OVH Webstorage CDN](https://www.ovh.com/fr/cdn/webstorage/), [OVH Cloudstorage](https://www.ovh.ie/cloud/storage/),
[Hubic](https://hubic.com/en/), [Rackspace Cloudfiles](https://www.rackspace.com/cloud/files)
and [Rackspace Cloudfiles CDN](https://www.rackspace.com/cloud/cdn-content-delivery-network).
All of the above Adapters provide access to Swift Object Storage services which are (mostly) openstack compliant.


## Installation and Getting Started

| Adapter | Getting started |
|---|---|
| [Ovh Cloudstorage Adapter](https://github.com/stephenmoloney/openstex/blob/master/lib/adapters/ovh/cloudstorage/adapter.ex) | [docs/ovh/cloudstorage/getting_started.md](https://github.com/stephenmoloney/openstex/blob/master/docs/ovh/cloudstorage/getting_started.md) |


# Usage

- Examples to be added. (for now see [openstex tests](https://github.com/stephenmoloney/openstex_test/tree/master/test))

## Tests

- To avoid circular dependency issues, tests are run from a separate repository [openstex_tests](https://github.com/stephenmoloney/openstex_test).

## Available Services

| Tables | Version | Status |
| ------------- |:-------------:| -----:|
| Identity (Keystone) , [overview](https://wiki.openstack.org/wiki/keystone), [api](http://developer.openstack.org/api-ref-identity-v2.html) | v2 | :heavy_check_mark: |
| Identity (Keystone) , [overview](https://wiki.openstack.org/wiki/keystone), [api](http://developer.openstack.org/api-ref-identity-v3.html) | v3 | :x: |
| Object Storage (Swift) , [overview](https://wiki.openstack.org/wiki/swift), [api](http://developer.openstack.org/api-ref-objectstorage-v1.html) | v1 | :heavy_check_mark: |

[Openstack api reference](http://developer.openstack.org/api-ref.html)


## Licence

[MIT Licence](LICENCE.md)
16 changes: 16 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use Mix.Config

config :logger,
backends: [:console],
level: :debug,
format: "\n$date $time [$level] $metadata$message"

if Mix.env == :prod do
config :logger,
backends: [:console],
compile_time_purge_level: :warn
end

unless Mix.env == :test do
import_config "#{Mix.env}.exs"
end
157 changes: 157 additions & 0 deletions docs/ovh/cloudstorage/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
## Getting started - OVH Cloudstorage

- Add `:ex_ovh` and `openstex` to your project list of dependencies.

```elixir
defp deps() do
[
{:ex_ovh, "~> 0.1.0"},
{:openstex, github: "stephenmoloney/openstex", tag: "0.1"}
]
end
```

- Configure an ExOvh Client

- Create an OVH account at [OVH](https://www.ovh.com/)

- Create an API application at the [OVH API page](https://eu.api.ovh.com/createApp/). Follow the
steps outlined by OVH there. Alternatively, there is a [mix task](https://github.com/stephenmoloney/ex_ovh/blob/master/docs/mix_task_advanced.md) which can help
generate the OVH application.

- The mix task (if used) will generate a config file as follows:

```elixir
config :my_app, MyApp.Cloudstorage,
ovh: [
application_key: System.get_env("MY_APP_CLOUDSTORAGE_APPLICATION_KEY"),
application_secret: System.get_env("MY_APP_CLOUDSTORAGE_APPLICATION_SECRET"),
consumer_key: System.get_env("MY_APP_CLOUDSTORAGE_CONSUMER_KEY")
]
```

- Add additional configuration as needed or as known.

```elixir
config :my_app, MyApp.Cloudstorage,
adapter: Openstex.Adapters.Ovh.Cloudstorage.Adapter,
ovh: [
application_key: System.get_env("MY_APP_CLOUDSTORAGE_APPLICATION_KEY"),
application_secret: System.get_env("MY_APP_CLOUDSTORAGE_APPLICATION_SECRET"),
consumer_key: System.get_env("MY_APP_CLOUDSTORAGE_CONSUMER_KEY"),
endpoint: "ovh-eu",
api_version: "1.0"
],
keystone: [
tenant_id: System.get_env("MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to an ovh project id or ovh servicename
user_id: System.get_env("MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_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("MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TEMP_URL_KEY1"), # defaults to :nil if absent
account_temp_url_key2: System.get_env("MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TEMP_URL_KEY2"), # defaults to :nil if absent
region: :nil # defaults to "SBG1" if not set.
],
httpoison: [
connect_timeout: 20000,
receive_timeout: 180000
]
```

- Ensure that the following variables are available as environment variables. The `mix ovh` task generates a `.env` file
which can optionally be used for this purpose. *NOTE:* Make sure `.env` is never added to version control.

```shell
export MY_APP_CLOUDSTORAGE_APPLICATION_KEY=<KEY>
export MY_APP_CLOUDSTORAGE_APPLICATION_SECRET=<SECRET>
export MY_APP_CLOUDSTORAGE_CONSUMER_KEY=<KEY>
export MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TENANT_ID=<TENANT_ID>
export MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TEMP_URL_KEY1=<KEY1>
export MY_APP_CLOUDSTORAGE_CLOUDSTORAGE_TEMP_URL_KEY2=<KEY2>
```

- Add the environment variables to the enviroment. Eg run ```source .env```

- Add a client to your project.


```elixir
defmodule MyApp.Cloudstorage do
@moduledoc :false
use Openstex.Client, otp_app: :my_app, client: __MODULE__

defmodule SwiftHelpers do
@moduledoc :false
use Openstex.Services.Swift.V1.Helpers, otp_app: :my_app, client: MyApp.Cloudstorage
end

defmodule Ovh do
@moduledoc :false
use ExOvh.Client, otp_app: :my_app, client: __MODULE__
end
end
```

- Add the client (`Openstex.Cloudstorage`) to your project supervision tree.


```elixir
def start(_type, _args) do
import Supervisor.Spec, warn: false
spec1 = [supervisor(MyApp.Endpoint, [])]
spec2 = [supervisor(MyApp.Cloudstorage, [])]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(spec1 ++ spec2, opts)
end
```


### Examples

client = MyApp.Cloudstorage

- An example of an API call to a swift API using the Helper functions (higher level):

```elixir
file_on_client = "/priv/test_file.json"
server_file = "test/nested/test_file.json"
container = "default"
client.swift().upload_file(file_on_client, server_file, container, [recv_timeout: (60000 * 60)])
```

- An example of an API call to a swift API using the Query functions (lower level):


```elixir
new_container = "my_new_container"
account = client.swift().get_account()
container_metadata = [headers: [{"X-Container-Meta-Access-Control-Allow-Origin", "http://stephenmoloney.com"}]]
create_container(new_container, account, container_metadata) |> client.request()
```

- An example of manually constructed query call to a swift API using the Query functions (low level):

```elixir
%Openstex.Swift.Query{
method: :get,
uri: account,
params: %{query_string: %{"format" => "json"}}
}
|> client.request()
```

- An example of manually constructed query call to a swift API using the Query functions (lowest level):


```elixir
%Openstex.HttpQuery{
method: :get,
uri: account,
body: "",
headers: [{"Content-Type", "application/json; charset=utf-8"}],
options: [timeout: 10000, recv_timeout: 30000],
service: :openstack
}
|> client.prepare_request()
|> client.request()
```
5 changes: 5 additions & 0 deletions lib/adapter/adapter.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Openstex.Adapter do
@moduledoc :false
@callback keystone() :: atom
@callback config() :: atom
end
Loading

0 comments on commit 373211e

Please sign in to comment.