summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHentioe <me@bluerain.io>2020-10-29 00:52:30 +0800
committerHentioe <me@bluerain.io>2020-10-29 00:52:30 +0800
commit502bee91e8e2553b94229614cff8d0bea96ebd28 (patch)
tree737145919e0d43faa2f3b3fc5583d87efe05e89b
parentDelete all models (diff)
Add some APIs
-rw-r--r--lib/azure_ex.ex10
-rw-r--r--lib/azure_ex/request.ex17
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/azure_ex.ex b/lib/azure_ex.ex
index a752828..64b3122 100644
--- a/lib/azure_ex.ex
+++ b/lib/azure_ex.ex
@@ -7,6 +7,16 @@ defmodule AzureEx do
import AzureEx.DSL
defendpoint(
+ "CreateOrUpdateVirtualMachines",
+ "PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2020-06-01"
+ )
+
+ defendpoint(
+ "GetVirtualMachines",
+ "GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2020-06-01"
+ )
+
+ defendpoint(
"ListAllVirtualMachines",
"GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines?api-version=2020-06-01"
)
diff --git a/lib/azure_ex/request.ex b/lib/azure_ex/request.ex
index bf8277d..c33cd51 100644
--- a/lib/azure_ex/request.ex
+++ b/lib/azure_ex/request.ex
@@ -5,7 +5,7 @@ defmodule AzureEx.Request do
alias AzureEx.{Config, TokenHosting}
- @type method :: :get | :post
+ @type method :: :get | :post | :put
@type data :: map
@type result :: any
@type error :: any
@@ -25,6 +25,8 @@ defmodule AzureEx.Request do
end
end
+ @data_content_type "application/json"
+
@spec send(method, String.t(), data) :: httpoison_result
defp send(:get, endpoint, _data) do
headers = [Authorization: "Bearer #{TokenHosting.get_token()}"]
@@ -35,11 +37,22 @@ defmodule AzureEx.Request do
defp send(:post, endpoint, data) do
headers = [
Authorization: "Bearer #{TokenHosting.get_token()}",
- "Content-Type": "application/json"
+ "Content-Type": @data_content_type
]
body = Jason.encode!(data || %{})
HTTPoison.post(endpoint, body, headers, Config.timeouts())
end
+
+ defp send(:put, endpoint, data) do
+ headers = [
+ Authorization: "Bearer #{TokenHosting.get_token()}",
+ "Content-Type": @data_content_type
+ ]
+
+ body = Jason.encode!(data || %{})
+
+ HTTPoison.put(endpoint, body, headers, Config.timeouts())
+ end
end