Hash :
fe17ed84
Author :
Date :
2016-05-01T14:43:49
design change. add additional client per swift service.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
defmodule ExOvh.Ovh.V1.Cloud.Query do
@moduledoc ~s"""
Helper functions for building queries directed at the `/cloud` part of the ovh api.
## Notes
| Function | Description | OVH API call |
|---|---|---|
| `list_services/0` | <small>List available services</small> | <sub><sup>GET /cloud/project</sup></sub> |
| `get_users/1` | <small>Get all users</small> | <sub><sup>GET /cloud/project/{serviceName}/user</sup></sub> |
| `create_user/2` | <small>Create user</small> | <sub><sup>POST /cloud/project/{serviceName}/user</sup></sub> |
| `get_user_details/2` | <small>Get user details</small> | <sub><sup>GET /cloud/project/{serviceName}/user/{userId}</sup></sub> |
| `delete_user/2` | <small>Delete user</small> | <sub><sup>DELETE /cloud/project/{serviceName}/user/{userId}</sup></sub> |
| `download_openrc_script/3` | <small>Get RC file of OpenStack</small> | <sub><sup>GET /cloud/project/{serviceName}/user/{userId}/openrc</sup></sub> |
| `regenerate_credentials/2` | <small>Regenerate user credentials including password</small> | <sub><sup>POST /cloud/project/{serviceName}/user/{userId}/regeneratePassword</sup></sub> |
| `swift_identity/3` | <small>Gets a json object similar to that returned by Keystone Identity. Includes the 'X-Auth-Token'</small> | <sub><sup>POST /cloud/project/{serviceName}/user/{userId}/token</sup></sub> |
## TODO
POST /cloud/createProject Start a new cloud project
GET /cloud/price Get services prices
GET /cloud/project/{serviceName} Get this object properties
PUT /cloud/project/{serviceName} Alter this object properties
GET /cloud/project/{serviceName}/acl Get ACL on your cloud project
POST /cloud/project/{serviceName}/acl
GET /cloud/project/{serviceName}/serviceInfos
GET /cloud/project/{serviceName}/quota Get project quotas
GET /cloud/project/{serviceName}/region Get regions
GET /cloud/project/{serviceName}/region/{regionName}
GET /cloud/project/{serviceName}/consumption
GET /cloud/project/{serviceName}/bill
## Example
ExOvh.Ovh.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
"""
alias ExOvh.Ovh.Query
@doc ~s"""
GET /cloud/project List available services
## Example
ExOvh.Ovh.V1.Cloud.Query.list_services() |> ExOvh.request!()
"""
@spec list_services() :: Query.t
def list_services() do
%Query{
method: :get,
uri: "/cloud/services",
params: :nil
}
end
@doc ~s"""
GET /cloud/project/{serviceName}/user Get all users
## Example
ExOvh.Ovh.V1.Cloud.Query.get_users(service_name) |> ExOvh.request!()
"""
@spec get_users(String.t) :: Query.t
def get_users(service_name) do
%Query{
method: :get,
uri: "/cloud/project/#{service_name}/user",
params: :nil
}
end
@doc ~s"""
POST /cloud/project/{serviceName}/user Create user
## Example
ExOvh.Ovh.V1.Cloud.Query.create_user(service_name, "ex_ovh") |> ExOvh.request!()
"""
@spec create_user(String.t, String.t) :: Query.t
def create_user(service_name, description) do
%Query{
method: :get,
uri: "/cloud/project/#{service_name}/user",
params: %{
"description" => description
}
|> Poison.encode!()
}
end
@doc ~s"""
GET /cloud/project/{serviceName}/user/{userId} Get user details
## Example
ExOvh.Ovh.V1.Cloud.Query.get_user_details(service_name, user_id) |> ExOvh.request!()
"""
@spec get_user_details(String.t, String.t) :: Query.t
def get_user_details(service_name, user_id) do
%Query{
method: :get,
uri: "/cloud/project/#{service_name}/user/#{user_id}",
params: :nil
}
end
@doc ~s"""
DELETE /cloud/project/{serviceName}/user/{userId} Delete user
## Example
ExOvh.Ovh.V1.Cloud.Query.delete_user(service_name, user_id) |> ExOvh.request!()
"""
@spec delete_user(String.t, String.t) :: Query.t
def delete_user(service_name, user_id) do
%Query{
method: :delete,
uri: "/cloud/project/#{service_name}/user/#{user_id}",
params: :nil
}
end
@doc ~s"""
GET /cloud/project/{serviceName}/user/{userId}/openrc Get RC file of OpenStack
## Example
ExOvh.Ovh.V1.Cloud.Query.download_openrc_script(service_name, user_id, "SBG1") |> ExOvh.request!()
"""
@spec download_openrc_script(String.t, String.t, String.t) :: Query.t
def download_openrc_script(service_name, user_id, region \\ "SBG1") do
%Query{
method: :get,
uri: "/cloud/project/#{service_name}/user/#{user_id}/openrc",
params: %{
region: region
}
}
end
@doc ~s"""
POST /cloud/project/{serviceName}/user/{userId}/regeneratePassword Regenerate user password
## Example
ExOvh.Ovh.V1.Cloud.Query.regenerate_credentials(service_name, user_id) |> ExOvh.request!()
"""
@spec regenerate_credentials(String.t, String.t) :: Query.t
def regenerate_credentials(service_name, user_id) do
%Query{
method: :post,
uri: "/cloud/project/#{service_name}/user/#{user_id}/regeneratePassword",
params: :nil
}
end
@doc ~s"""
POST /cloud/project/{serviceName}/user/{userId}/token Get the token for the user (very similar to
keystone identity)
## Example
ExOvh.Ovh.V1.Cloud.Query.swift_identity(service_name, user_id) |> ExOvh.request!()
"""
@spec swift_identity(String.t, String.t, String.t) :: Query.t
def swift_identity(service_name, user_id, password) do
%Query{
method: :post,
uri: "/cloud/project/#{service_name}/user/#{user_id}/token",
params: %{
"password" => password
}
|> Poison.encode!()
}
end
end