%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE! %% See https://github.com/jkakar/aws-codegen for more details. %% @doc Amazon WorkSpaces Service %% %% This is the Amazon WorkSpaces API Reference. This guide provides %% detailed information about Amazon WorkSpaces operations, data types, %% parameters, and errors. -module(aws_workspaces). -export([create_workspaces/2, create_workspaces/3, describe_workspace_bundles/2, describe_workspace_bundles/3, describe_workspace_directories/2, describe_workspace_directories/3, describe_workspaces/2, describe_workspaces/3, reboot_workspaces/2, reboot_workspaces/3, rebuild_workspaces/2, rebuild_workspaces/3, terminate_workspaces/2, terminate_workspaces/3]). -include_lib("hackney/include/hackney_lib.hrl"). %%==================================================================== %% API %%==================================================================== %% @doc Creates one or more WorkSpaces. %% %% This operation is asynchronous and returns before the WorkSpaces %% are created. %% %% create_workspaces(Client, Input) when is_map(Client), is_map(Input) -> create_workspaces(Client, Input, []). create_workspaces(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"CreateWorkspaces">>, Input, Options). %% @doc Obtains information about the WorkSpace bundles that are available to %% your account in the specified region. %% %% You can filter the results with either the BundleIds %% parameter, or the Owner parameter, but not both. %% %% This operation supports pagination with the use of the %% NextToken request and response parameters. If more results %% are available, the NextToken response member contains a token %% that you pass in the next call to this operation to retrieve the next set %% of items. describe_workspace_bundles(Client, Input) when is_map(Client), is_map(Input) -> describe_workspace_bundles(Client, Input, []). describe_workspace_bundles(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"DescribeWorkspaceBundles">>, Input, Options). %% @doc Retrieves information about the AWS Directory Service directories in %% the region that are registered with Amazon WorkSpaces and are available to %% your account. %% %% This operation supports pagination with the use of the %% NextToken request and response parameters. If more results %% are available, the NextToken response member contains a token %% that you pass in the next call to this operation to retrieve the next set %% of items. describe_workspace_directories(Client, Input) when is_map(Client), is_map(Input) -> describe_workspace_directories(Client, Input, []). describe_workspace_directories(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"DescribeWorkspaceDirectories">>, Input, Options). %% @doc Obtains information about the specified WorkSpaces. %% %% Only one of the filter parameters, such as BundleId, %% DirectoryId, or WorkspaceIds, can be specified %% at a time. %% %% This operation supports pagination with the use of the %% NextToken request and response parameters. If more results %% are available, the NextToken response member contains a token %% that you pass in the next call to this operation to retrieve the next set %% of items. describe_workspaces(Client, Input) when is_map(Client), is_map(Input) -> describe_workspaces(Client, Input, []). describe_workspaces(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"DescribeWorkspaces">>, Input, Options). %% @doc Reboots the specified WorkSpaces. %% %% To be able to reboot a WorkSpace, the WorkSpace must have a State %% of AVAILABLE, IMPAIRED, or %% INOPERABLE. %% %% This operation is asynchronous and will return before the %% WorkSpaces have rebooted. %% %% reboot_workspaces(Client, Input) when is_map(Client), is_map(Input) -> reboot_workspaces(Client, Input, []). reboot_workspaces(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"RebootWorkspaces">>, Input, Options). %% @doc Rebuilds the specified WorkSpaces. %% %% Rebuilding a WorkSpace is a potentially destructive action that can result %% in the loss of data. Rebuilding a WorkSpace causes the following to occur: %% %% To be able to rebuild a WorkSpace, the WorkSpace must have a %% State of AVAILABLE or ERROR. %% %% This operation is asynchronous and will return before the %% WorkSpaces have been completely rebuilt. %% %% rebuild_workspaces(Client, Input) when is_map(Client), is_map(Input) -> rebuild_workspaces(Client, Input, []). rebuild_workspaces(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"RebuildWorkspaces">>, Input, Options). %% @doc Terminates the specified WorkSpaces. %% %% Terminating a WorkSpace is a permanent action and cannot be undone. The %% user's data is not maintained and will be destroyed. If you need to %% archive any user data, contact Amazon Web Services before terminating the %% WorkSpace. %% %% You can terminate a WorkSpace that is in any state except %% SUSPENDED. %% %% This operation is asynchronous and will return before the %% WorkSpaces have been completely terminated. %% %% terminate_workspaces(Client, Input) when is_map(Client), is_map(Input) -> terminate_workspaces(Client, Input, []). terminate_workspaces(Client, Input, Options) when is_map(Client), is_map(Input), is_list(Options) -> request(Client, <<"TerminateWorkspaces">>, Input, Options). %%==================================================================== %% Internal functions %%==================================================================== -spec request(aws_client:aws_client(), binary(), map(), list()) -> {ok, Result, {integer(), list(), hackney:client()}} | {error, Error, {integer(), list(), hackney:client()}} | {error, term()} when Result :: map() | undefined, Error :: {binary(), binary()}. request(Client, Action, Input, Options) -> Client1 = Client#{service => <<"workspaces">>}, Host = get_host(<<"workspaces">>, Client1), URL = get_url(Host, Client1), Headers = [{<<"Host">>, Host}, {<<"Content-Type">>, <<"application/x-amz-json-1.1">>}, {<<"X-Amz-Target">>, << <<"WorkspacesService.">>/binary, Action/binary>>}], Payload = jsx:encode(Input), Headers1 = aws_request:sign_request(Client1, <<"POST">>, URL, Headers, Payload), Response = hackney:request(post, URL, Headers1, Payload, Options), handle_response(Response). handle_response({ok, 200, ResponseHeaders, Client}) -> case hackney:body(Client) of {ok, <<>>} -> {ok, undefined, {200, ResponseHeaders, Client}}; {ok, Body} -> Result = jsx:decode(Body, [return_maps]), {ok, Result, {200, ResponseHeaders, Client}} end; handle_response({ok, StatusCode, ResponseHeaders, Client}) -> {ok, Body} = hackney:body(Client), Error = jsx:decode(Body, [return_maps]), Exception = maps:get(<<"__type">>, Error, undefined), Reason = maps:get(<<"message">>, Error, undefined), {error, {Exception, Reason}, {StatusCode, ResponseHeaders, Client}}; handle_response({error, Reason}) -> {error, Reason}. get_host(_EndpointPrefix, #{region := <<"local">>}) -> <<"localhost">>; get_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) -> aws_util:binary_join([EndpointPrefix, <<".">>, Region, <<".">>, Endpoint], <<"">>). get_url(Host, Client) -> Proto = maps:get(proto, Client), Port = maps:get(port, Client), aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, <<"/">>], <<"">>).