aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/uploaders/swift/keystone.ex
diff options
context:
space:
mode:
authorThurloat <thurloat@gmail.com>2018-08-28 22:32:24 -0300
committerThurloat <thurloat@gmail.com>2018-08-28 22:32:24 -0300
commit2ff25ac0ceb98f2ee1c803aeb8aecc112e335877 (patch)
treee27c814f0ff81872c5426d4fc3959924df1b0760 /lib/pleroma/uploaders/swift/keystone.ex
parent9fc20ed5720bccb77289ce3d6eb9bc3a69ceeb8a (diff)
downloadpleroma-2ff25ac0ceb98f2ee1c803aeb8aecc112e335877.tar.gz
A hobbldey-working swift client.
apparently, all elixir openstack libraries are trash luckily, the APIs are stupid easy.
Diffstat (limited to 'lib/pleroma/uploaders/swift/keystone.ex')
-rw-r--r--lib/pleroma/uploaders/swift/keystone.ex48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/pleroma/uploaders/swift/keystone.ex b/lib/pleroma/uploaders/swift/keystone.ex
new file mode 100644
index 000000000..a79214319
--- /dev/null
+++ b/lib/pleroma/uploaders/swift/keystone.ex
@@ -0,0 +1,48 @@
+defmodule Pleroma.Uploaders.Swift.Keystone do
+ use HTTPoison.Base
+
+ @settings Application.get_env(:pleroma, Pleroma.Uploaders.Swift)
+
+ def process_url(url) do
+ Enum.join(
+ [Keyword.fetch!(@settings, :auth_url), url],
+ "/"
+ )
+ end
+
+ def process_response_body(body) do
+ body
+ |> Poison.decode!()
+ end
+
+ def get_token() do
+ username = Keyword.fetch!(@settings, :username)
+ password = Keyword.fetch!(@settings, :password)
+ tenant_id = Keyword.fetch!(@settings, :tenant_id)
+
+ case post(
+ "/tokens",
+ make_auth_body(username, password, tenant_id),
+ ["Content-Type": "application/json"],
+ hackney: [:insecure]
+ ) do
+ {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
+ body["access"]["token"]["id"]
+
+ {:ok, %HTTPoison.Response{status_code: _}} ->
+ ""
+ end
+ end
+
+ def make_auth_body(username, password, tenant) do
+ Poison.encode!(%{
+ :auth => %{
+ :passwordCredentials => %{
+ :username => username,
+ :password => password
+ },
+ :tenantId => tenant
+ }
+ })
+ end
+end