diff --git a/.arcconfig b/.arcconfig new file mode 100644 index 0000000..b9fd1a3 --- /dev/null +++ b/.arcconfig @@ -0,0 +1,3 @@ +{ + "phabricator.uri": "https://git.kolab.org" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..755b605 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/_build +/cover +/deps +erl_crash.dump +*.ez diff --git a/README.md b/README.md new file mode 100644 index 0000000..06f57d9 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# KolabWopi + + *WARNING: PRE-ALPHA SOFTWARE, WILL EAT ALL THE BABIES* + +KolabWopi provides an API implementing Web Application Open Interface standard. +To learn about Kolab visit https://kolab.org diff --git a/config/config.exs b/config/config.exs new file mode 100644 index 0000000..14da6ae --- /dev/null +++ b/config/config.exs @@ -0,0 +1,30 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Mix.Config module. +use Mix.Config + +# This configuration is loaded before any dependency and is restricted +# to this project. If another project depends on this project, this +# file won't be loaded nor affect the parent project. For this reason, +# if you want to provide default values for your application for +# 3rd-party users, it should be done in your "mix.exs" file. + +# You can configure for your application as: +# +# config :kolab_wopi, key: :value +# +# And access this configuration in your application as: +# +# Application.get_env(:kolab_wopi, :key) +# +# Or configure a 3rd-party app: +# +# config :logger, level: :info +# + +# It is also possible to import configuration files, relative to this +# directory. For example, you can emulate configuration per environment +# by uncommenting the line below and defining dev.exs, test.exs and such. +# Configuration from the imported file will override the ones defined +# here (which is why it is important to import them last). +# +# import_config "#{Mix.env}.exs" diff --git a/lib/kolab_wopi.ex b/lib/kolab_wopi.ex new file mode 100644 index 0000000..5aa110a --- /dev/null +++ b/lib/kolab_wopi.ex @@ -0,0 +1,20 @@ +defmodule KolabWopi do + use Application + + # See http://elixir-lang.org/docs/stable/elixir/Application.html + # for more information on OTP Applications + def start(_type, _args) do + import Supervisor.Spec, warn: false + + children = [ + # Define workers and child supervisors to be supervised + worker(__MODULE__.API, []), + worker(__MODULE__.Chwala, []) + ] + + # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: __MODULE__.Supervisor] + Supervisor.start_link(children, opts) + end +end diff --git a/lib/kolab_wopi/api.ex b/lib/kolab_wopi/api.ex new file mode 100644 index 0000000..902adc0 --- /dev/null +++ b/lib/kolab_wopi/api.ex @@ -0,0 +1,31 @@ +defmodule KolabWopi.API do + use Plug.Router + use Plug.ErrorHandler + + require Logger + + plug Plug.Logger + plug :match + plug :dispatch + + def init(options) do + options + end + + def start_link do + {:ok, _} = Plug.Adapters.Cowboy.http __MODULE__, [] + end + + forward "/wopi/files", to: __MODULE__.Files + forward "/wopi/containers", to: __MODULE__.Containers + forward "/wopi/ecosystem", to: __MODULE__.Ecosystem + forward "/wopibootstrapper", to: __MODULE__.Bootstrap + + match _ do + conn |> send_resp(404, "Not found") + end + + defp handle_errors(conn, %{kind: _kind, reason: _reason, stack: _stack}) do + conn |> send_resp(500, "Internal Server Error") + end +end diff --git a/lib/kolab_wopi/api/bootstrap.ex b/lib/kolab_wopi/api/bootstrap.ex new file mode 100644 index 0000000..72a7ded --- /dev/null +++ b/lib/kolab_wopi/api/bootstrap.ex @@ -0,0 +1,10 @@ +defmodule KolabWopi.API.Bootstrap do + use Plug.Router + + plug :match + plug :dispatch + + match _ do + conn |> send_resp(501, "Not implemented") + end +end diff --git a/lib/kolab_wopi/api/containers.ex b/lib/kolab_wopi/api/containers.ex new file mode 100644 index 0000000..a2d3687 --- /dev/null +++ b/lib/kolab_wopi/api/containers.ex @@ -0,0 +1,10 @@ +defmodule KolabWopi.API.Containers do + use Plug.Router + + plug :match + plug :dispatch + + match _ do + conn |> send_resp(501, "Not implemented") + end +end diff --git a/lib/kolab_wopi/api/ecosystem.ex b/lib/kolab_wopi/api/ecosystem.ex new file mode 100644 index 0000000..9e88edc --- /dev/null +++ b/lib/kolab_wopi/api/ecosystem.ex @@ -0,0 +1,10 @@ +defmodule KolabWopi.API.Ecosystem do + use Plug.Router + + plug :match + plug :dispatch + + match _ do + conn |> send_resp(501, "Not implemented") + end +end diff --git a/lib/kolab_wopi/api/files.ex b/lib/kolab_wopi/api/files.ex new file mode 100644 index 0000000..ec657c5 --- /dev/null +++ b/lib/kolab_wopi/api/files.ex @@ -0,0 +1,14 @@ +defmodule KolabWopi.API.Files do + use Plug.Router + + plug :match + plug :dispatch + + get "/" do + conn |> send_resp(200, "/wopi/files") + end + + match _ do + conn |> send_resp(404, "Not found") + end +end diff --git a/lib/kolab_wopi/chwala.ex b/lib/kolab_wopi/chwala.ex new file mode 100644 index 0000000..b5f2c87 --- /dev/null +++ b/lib/kolab_wopi/chwala.ex @@ -0,0 +1,10 @@ +defmodule KolabWopi.Chwala do + use GenServer + + require Logger + + def start_link do + GenServer.start_link(__MODULE__, []) + end + +end diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..da704f5 --- /dev/null +++ b/mix.exs @@ -0,0 +1,36 @@ +defmodule KolabWopi.Mixfile do + use Mix.Project + + def project do + [ + app: :kolab_wopi, + version: "0.0.1", + elixir: "~> 1.2", + build_embedded: Mix.env == :prod, + start_permanent: Mix.env == :prod, + deps: deps + ] + end + + # Configuration for the OTP application + # + # Type "mix help compile.app" for more information + def application do + [ + applications: [:logger, :cowboy, :plug, :httpoison], + mod: {KolabWopi, []} + ] + end + + # Dependencies can be Hex packages: + # + # Type "mix help deps" for more examples and options + defp deps do + [ + {:cowboy, "~> 1.0"}, + {:plug, "~> 1.2"}, + {:httpoison, "~> 0.9"}, + {:poison, "~> 2.2"} + ] + end +end diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..b5ee57a --- /dev/null +++ b/mix.lock @@ -0,0 +1,13 @@ +%{"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []}, + "cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:rebar, :make], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]}, + "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []}, + "hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]}, + "httpoison": {:hex, :httpoison, "0.9.1", "6c2b4eaf2588a6f3ef29663d28c992531ca3f0bc832a97e0359bc822978e1c5d", [:mix], [{:hackney, "~> 1.6.0", [hex: :hackney, optional: false]}]}, + "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, + "mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []}, + "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, + "plug": {:hex, :plug, "1.2.0", "496bef96634a49d7803ab2671482f0c5ce9ce0b7b9bc25bc0ae8e09859dd2004", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]}, + "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []}, + "ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []}} diff --git a/test/kolab_wopi_test.exs b/test/kolab_wopi_test.exs new file mode 100644 index 0000000..5bda50d --- /dev/null +++ b/test/kolab_wopi_test.exs @@ -0,0 +1,8 @@ +defmodule KolabWopiTest do + use ExUnit.Case + doctest KolabWopi + + test "the truth" do + assert 1 + 1 == 2 + end +end diff --git a/test/test_helper.exs b/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start()