Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of DMS service for ex-aws #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## v0.1.0 (2018-05-01)

Initial release

- describe replication tasks
- stop replication task
- start replication task
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Contributing
============

Contributions to ExAws are always welcome! For contributions to this particular service, feel free to just open a PR or an issue. For larger scale contributions see: https://github.com/ex-aws/ex_aws/blob/master/CONTRIBUTING.md
14 changes: 14 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* Do not use the issues tracker for help or support (try Elixir Forum, Slack, IRC, etc.)
* Questions about how to contribute are fine.

### Environment

* Elixir & Erlang versions (elixir --version):
* ExAws version `mix deps | grep ex_aws`
* HTTP client version. IE for hackney do `mix deps | grep hackney`

### Current behavior

Include code samples, errors and stacktraces if appropriate.

### Expected behavior
13 changes: 13 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Apache 2 License

Copyright (c) 2018 100Starlings

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# ex_aws_dms
# ExAws.DMS

Partial client implementation of the AWS [Database Migration Service API](https://docs.aws.amazon.com/dms/latest/APIReference/Welcome.html).

Service module for https://github.com/ex-aws/ex_aws

## Installation

The package can be installed by adding `ex_aws_dms` to your list of dependencies in `mix.exs`
along with `:ex_aws` and your preferred JSON codec / http client

```elixir
def deps do
[
{:ex_aws, "~> 2.0"},
{:ex_aws_dms, "~> 0.1"},
{:poison, "~> 3.1"},
{:hackney, "~> 1.9"},
]
end
```

Documentation can be found at [https://hexdocs.pm/ex_aws_dms](https://hexdocs.pm/ex_aws_dms).

## License

The MIT License (MIT)

Copyright (c) 2018 100Starlings Ltd.

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.
30 changes: 30 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -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 your application as:
#
# config :ex_aws_kinesis, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:ex_aws_kinesis, :key)
#
# You can also 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"
54 changes: 54 additions & 0 deletions lib/ex_aws/dms.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule ExAws.DMS do
@moduledoc """
Operations on [AWS DMS](https://docs.aws.amazon.com/dms/latest/APIReference/API_Operations.html)
"""

@type replication_task_arn :: binary

@namespace "AmazonDMSv20160101"

@doc "Starts a replication task"
@type start_replication_task_type :: :start_replication | :resume_processing | :reload_target
@spec start_replication_task(
replication_task_arn :: replication_task_arn,
start_replication_task_type :: start_replication_task_type
) :: ExAws.Operation.JSON.t()
def start_replication_task(replication_task_arn, start_replication_task_type) do
data = %{
"ReplicationTaskArn" => replication_task_arn,
"StartReplicationTaskType" =>
start_replication_task_type |> Atom.to_string() |> String.replace("_", "-")
}

request(:start_replication_task, data)
end

@doc "Stops a replication task"
@spec stop_replication_task(replication_task_arn :: replication_task_arn) ::
ExAws.Operation.JSON.t()
def stop_replication_task(replication_task_arn) do
data = %{"ReplicationTaskArn" => replication_task_arn}
request(:stop_replication_task, data)
end

@doc "Returns information about replication tasks in the current region"
@spec describe_replication_tasks() :: ExAws.Operation.JSON.t()
def describe_replication_tasks() do
request(:describe_replication_tasks)
end

defp request(action, data \\ %{}) do
operation =
action
|> Atom.to_string()
|> Macro.camelize()

ExAws.Operation.JSON.new(:dms, %{
data: data,
headers: [
{"x-amz-target", "#{@namespace}.#{operation}"},
{"content-type", "application/x-amz-json-1.1"}
]
})
end
end
59 changes: 59 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
defmodule ExAws.DMS.Mixfile do
use Mix.Project

@version "0.1.1"
@service "dms"
@url "https://github.com/ex-aws/ex_aws_#{@service}"
@name __MODULE__ |> Module.split() |> Enum.take(2) |> Enum.join(".")

def project do
[
app: :ex_aws_dms,
version: @version,
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
deps: deps(),
name: @name,
package: package(),
docs: [
main: @name,
source_ref: "v#{@version}",
source_url: @url
]
]
end

defp package do
[
description: "#{@name} service package",
files: ["lib", "config", "mix.exs", "README*"],
maintainers: ["Zoltan Iklodi", "Laszlo Bacsi"],
licenses: ["MIT"],
links: %{github: @url}
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

def application do
[extra_applications: [:logger]]
end

defp deps do
[
{:ex_doc, ">= 0.0.0", only: :dev},
{:hackney, ">= 0.0.0", only: [:dev, :test]},
{:poison, ">= 0.0.0", only: [:dev, :test]},
ex_aws()
]
end

defp ex_aws do
case System.get_env("AWS") do
"LOCAL" -> {:ex_aws, path: "../ex_aws"}
_ -> {:ex_aws, "~> 2.0"}
end
end
end
15 changes: 15 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%{
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
"ex_aws": {:hex, :ex_aws, "2.0.2", "8df2f96f58624a399abe5a0ce26db648ee848aca6393b9c65c939ece9ac07bfa", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.12.1", "8bf2d0e11e722e533903fe126e14d6e7e94d9b7983ced595b75f532e04b7fdc7", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.1", "cbc3b2fa1645113267cc59c760bafa64b2ea0334635ef06dbac8801e42f7279c", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"sweet_xml": {:hex, :sweet_xml, "0.6.5", "dd9cde443212b505d1b5f9758feb2000e66a14d3c449f04c572f3048c66e6697", [:mix], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
}
43 changes: 43 additions & 0 deletions test/lib/dms_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule ExAws.DMSTest do
use ExUnit.Case, async: true
alias ExAws.DMS

test "#describe_replication_tasks" do
assert %ExAws.Operation.JSON{service: :dms} = request = DMS.describe_replication_tasks()

assert request.data == %{}

assert request.headers == [
{"x-amz-target", "AmazonDMSv20160101.DescribeReplicationTasks"},
{"content-type", "application/x-amz-json-1.1"}
]
end

test "#start_replication_task" do
assert %ExAws.Operation.JSON{service: :dms} =
request = DMS.start_replication_task("arn", :resume_processing)

assert request.data == %{
"ReplicationTaskArn" => "arn",
"StartReplicationTaskType" => "resume-processing"
}

assert request.headers == [
{"x-amz-target", "AmazonDMSv20160101.StartReplicationTask"},
{"content-type", "application/x-amz-json-1.1"}
]
end

test "#stop_replication_task" do
assert %ExAws.Operation.JSON{service: :dms} = request = DMS.stop_replication_task("arn")

assert request.data == %{
"ReplicationTaskArn" => "arn"
}

assert request.headers == [
{"x-amz-target", "AmazonDMSv20160101.StopReplicationTask"},
{"content-type", "application/x-amz-json-1.1"}
]
end
end
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()