diff options
author | Hentioe <me@bluerain.io> | 2020-11-03 18:22:49 +0800 |
---|---|---|
committer | Hentioe <me@bluerain.io> | 2020-11-03 18:22:49 +0800 |
commit | 31fe50e61222f5c25cc450113f4a42c4465cd540 (patch) | |
tree | dee2fcfccc515e50f043c2d2e85bf644cfdee6a5 | |
parent | Added some resources to delete APIs (diff) |
Wrap remote error
-rw-r--r-- | lib/azure_ex.ex | 15 | ||||
-rw-r--r-- | lib/azure_ex/model/network_interfaces/create_or_update.ex | 11 | ||||
-rw-r--r-- | lib/azure_ex/model/public_ip_address/create_or_update.ex | 21 | ||||
-rw-r--r-- | lib/azure_ex/request.ex | 12 |
4 files changed, 55 insertions, 4 deletions
diff --git a/lib/azure_ex.ex b/lib/azure_ex.ex index e580f0d..c284809 100644 --- a/lib/azure_ex.ex +++ b/lib/azure_ex.ex @@ -60,4 +60,19 @@ defmodule AzureEx do "DeleteNetworkInterfaces", "DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}?api-version=2020-05-01" ) + + defendpoint( + "CreateOrUpdatePublicIPAddress", + "PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2020-05-01" + ) + + defendpoint( + "DeletePublicIPAddress", + "DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2020-05-01" + ) + + defendpoint( + "DeleteDisks", + "DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}?api-version=2020-06-30" + ) end diff --git a/lib/azure_ex/model/network_interfaces/create_or_update.ex b/lib/azure_ex/model/network_interfaces/create_or_update.ex index bff597c..2d944ef 100644 --- a/lib/azure_ex/model/network_interfaces/create_or_update.ex +++ b/lib/azure_ex/model/network_interfaces/create_or_update.ex @@ -3,7 +3,14 @@ defmodule AzureEx.Model.NetworkInterfaces.CreateOrUpdate do use TypedStruct - alias __MODULE__.{Properties} + alias __MODULE__.{Properties, PublicIPAddress} + + typedstruct module: PublicIPAddress do + @derive Jason.Encoder + + field :id, String.t() + field :name, String.t() + end typedstruct module: Subnet do @derive Jason.Encoder @@ -15,11 +22,13 @@ defmodule AzureEx.Model.NetworkInterfaces.CreateOrUpdate do @derive Jason.Encoder field :subnet, Subnet.t() + field :publicIPAddress, PublicIPAddress.t() end typedstruct module: NetworkInterfaceIPConfiguration do @derive Jason.Encoder + field :id, String.t() field :name, String.t() field :properties, NetworkInterfaceIPConfiguration.Properties.t() end diff --git a/lib/azure_ex/model/public_ip_address/create_or_update.ex b/lib/azure_ex/model/public_ip_address/create_or_update.ex new file mode 100644 index 0000000..959db34 --- /dev/null +++ b/lib/azure_ex/model/public_ip_address/create_or_update.ex @@ -0,0 +1,21 @@ +defmodule AzureEx.Model.PublicIPAddress.CreateOrUpdate do + @moduledoc false + + use TypedStruct + + alias __MODULE__.{Properties} + + typedstruct module: Properties do + @derive Jason.Encoder + + field :publicIPAddressVersion, String.t() + end + + typedstruct do + @derive Jason.Encoder + + field :id, String.t() + field :location, String.t() + field :properties, Properties.t(), default: %Properties{} + end +end diff --git a/lib/azure_ex/request.ex b/lib/azure_ex/request.ex index c7b1432..7dcd957 100644 --- a/lib/azure_ex/request.ex +++ b/lib/azure_ex/request.ex @@ -7,8 +7,8 @@ defmodule AzureEx.Request do @type method :: :get | :post | :put | :delete @type data :: map - @type result :: any - @type error :: any + @type result :: integer | map + @type error :: map @type httpoison_result :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} @spec call(binary, method, data) :: {:ok, result} | {:error, error} @@ -21,7 +21,13 @@ defmodule AzureEx.Request do if body == "" do {:ok, status_code} else - {:ok, Jason.decode!(body, keys: :atoms)} + result = Jason.decode!(body, keys: :atoms) + + if result[:error] && result[:error][:code] do + {:error, %{code: result[:error][:code], message: result[:error][:message]}} + else + {:ok, result} + end end end |