Current section

Files

Jump to
aws_erlang src aws_marketplace_catalog.erl
Raw

src/aws_marketplace_catalog.erl

%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
%% See https://github.com/aws-beam/aws-codegen for more details.
%% @doc Catalog API actions allow you to manage your entities through list,
%% describe, and update capabilities.
%%
%% An entity can be a product or an offer on AWS Marketplace.
%%
%% You can automate your entity update process by integrating the AWS
%% Marketplace Catalog API with your AWS Marketplace product build or
%% deployment pipelines. You can also create your own applications on top of
%% the Catalog API to manage your products on AWS Marketplace.
-module(aws_marketplace_catalog).
-export([cancel_change_set/2,
cancel_change_set/3,
describe_change_set/3,
describe_change_set/5,
describe_change_set/6,
describe_entity/3,
describe_entity/5,
describe_entity/6,
list_change_sets/2,
list_change_sets/3,
list_entities/2,
list_entities/3,
list_tags_for_resource/2,
list_tags_for_resource/3,
start_change_set/2,
start_change_set/3,
tag_resource/2,
tag_resource/3,
untag_resource/2,
untag_resource/3]).
-include_lib("hackney/include/hackney_lib.hrl").
%%====================================================================
%% API
%%====================================================================
%% @doc Used to cancel an open change request.
%%
%% Must be sent before the status of the request changes to `APPLYING',
%% the final stage of completing your change request. You can describe a
%% change during the 60-day request history retention period for API calls.
cancel_change_set(Client, Input) ->
cancel_change_set(Client, Input, []).
cancel_change_set(Client, Input0, Options0) ->
Method = patch,
Path = ["/CancelChangeSet"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
QueryMapping = [
{<<"catalog">>, <<"Catalog">>},
{<<"changeSetId">>, <<"ChangeSetId">>}
],
{Query_, Input} = aws_request:build_headers(QueryMapping, Input2),
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Provides information about a given change set.
describe_change_set(Client, Catalog, ChangeSetId)
when is_map(Client) ->
describe_change_set(Client, Catalog, ChangeSetId, #{}, #{}).
describe_change_set(Client, Catalog, ChangeSetId, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
describe_change_set(Client, Catalog, ChangeSetId, QueryMap, HeadersMap, []).
describe_change_set(Client, Catalog, ChangeSetId, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/DescribeChangeSet"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"catalog">>, Catalog},
{<<"changeSetId">>, ChangeSetId}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc Returns the metadata and content of the entity.
describe_entity(Client, Catalog, EntityId)
when is_map(Client) ->
describe_entity(Client, Catalog, EntityId, #{}, #{}).
describe_entity(Client, Catalog, EntityId, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
describe_entity(Client, Catalog, EntityId, QueryMap, HeadersMap, []).
describe_entity(Client, Catalog, EntityId, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["/DescribeEntity"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false}
| Options0],
Headers = [],
Query0_ =
[
{<<"catalog">>, Catalog},
{<<"entityId">>, EntityId}
],
Query_ = [H || {_, V} = H <- Query0_, V =/= undefined],
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode).
%% @doc Returns the list of change sets owned by the account being used to
%% make the call.
%%
%% You can filter this list by providing any combination of `entityId',
%% `ChangeSetName', and status. If you provide more than one filter, the
%% API operation applies a logical AND between the filters.
%%
%% You can describe a change during the 60-day request history retention
%% period for API calls.
list_change_sets(Client, Input) ->
list_change_sets(Client, Input, []).
list_change_sets(Client, Input0, Options0) ->
Method = post,
Path = ["/ListChangeSets"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Provides the list of entities of a given type.
list_entities(Client, Input) ->
list_entities(Client, Input, []).
list_entities(Client, Input0, Options0) ->
Method = post,
Path = ["/ListEntities"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Lists all tags that have been added to a resource (either an entity
%% or change set).
list_tags_for_resource(Client, Input) ->
list_tags_for_resource(Client, Input, []).
list_tags_for_resource(Client, Input0, Options0) ->
Method = post,
Path = ["/ListTagsForResource"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Allows you to request changes for your entities.
%%
%% Within a single `ChangeSet', you can't start the same change type
%% against the same entity multiple times. Additionally, when a
%% `ChangeSet' is running, all the entities targeted by the different
%% changes are locked until the change set has completed (either succeeded,
%% cancelled, or failed). If you try to start a change set containing a
%% change against an entity that is already locked, you will receive a
%% `ResourceInUseException' error.
%%
%% For example, you can't start the `ChangeSet' described in the
%% example later in this topic because it contains two changes to run the
%% same change type (`AddRevisions') against the same entity
%% (`entity-id@1').
%%
%% For more information about working with change sets, see Working with
%% change sets.
start_change_set(Client, Input) ->
start_change_set(Client, Input, []).
start_change_set(Client, Input0, Options0) ->
Method = post,
Path = ["/StartChangeSet"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Tags a resource (either an entity or change set).
tag_resource(Client, Input) ->
tag_resource(Client, Input, []).
tag_resource(Client, Input0, Options0) ->
Method = post,
Path = ["/TagResource"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%% @doc Removes a tag or list of tags from a resource (either an entity or
%% change set).
untag_resource(Client, Input) ->
untag_resource(Client, Input, []).
untag_resource(Client, Input0, Options0) ->
Method = post,
Path = ["/UntagResource"],
SuccessStatusCode = undefined,
Options = [{send_body_as_binary, false},
{receive_body_as_binary, false},
{append_sha256_content_hash, false}
| Options0],
Headers = [],
Input1 = Input0,
CustomHeaders = [],
Input2 = Input1,
Query_ = [],
Input = Input2,
request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode).
%%====================================================================
%% Internal functions
%%====================================================================
-spec request(aws_client:aws_client(), atom(), iolist(), list(),
list(), map() | undefined, list(), pos_integer() | undefined) ->
{ok, {integer(), list()}} |
{ok, Result, {integer(), list(), hackney:client()}} |
{error, Error, {integer(), list(), hackney:client()}} |
{error, term()} when
Result :: map(),
Error :: map().
request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) ->
RequestFun = fun() -> do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) end,
aws_request:request(RequestFun, Options).
do_request(Client, Method, Path, Query, Headers0, Input, Options, SuccessStatusCode) ->
Client1 = Client#{service => <<"aws-marketplace">>},
Host = build_host(<<"catalog.marketplace">>, Client1),
URL0 = build_url(Host, Path, Client1),
URL = aws_request:add_query(URL0, Query),
AdditionalHeaders1 = [ {<<"Host">>, Host}
, {<<"Content-Type">>, <<"application/x-amz-json-1.1">>}
],
Payload =
case proplists:get_value(send_body_as_binary, Options) of
true ->
maps:get(<<"Body">>, Input, <<"">>);
false ->
encode_payload(Input)
end,
AdditionalHeaders = case proplists:get_value(append_sha256_content_hash, Options, false) of
true ->
add_checksum_hash_header(AdditionalHeaders1, Payload);
false ->
AdditionalHeaders1
end,
Headers1 = aws_request:add_headers(AdditionalHeaders, Headers0),
MethodBin = aws_request:method_to_binary(Method),
SignedHeaders = aws_request:sign_request(Client1, MethodBin, URL, Headers1, Payload),
Response = hackney:request(Method, URL, SignedHeaders, Payload, Options),
DecodeBody = not proplists:get_value(receive_body_as_binary, Options),
handle_response(Response, SuccessStatusCode, DecodeBody).
add_checksum_hash_header(Headers, Body) ->
[ {<<"X-Amz-CheckSum-SHA256">>, base64:encode(crypto:hash(sha256, Body))}
| Headers
].
handle_response({ok, StatusCode, ResponseHeaders}, SuccessStatusCode, _DecodeBody)
when StatusCode =:= 200;
StatusCode =:= 202;
StatusCode =:= 204;
StatusCode =:= 206;
StatusCode =:= SuccessStatusCode ->
{ok, {StatusCode, ResponseHeaders}};
handle_response({ok, StatusCode, ResponseHeaders}, _, _DecodeBody) ->
{error, {StatusCode, ResponseHeaders}};
handle_response({ok, StatusCode, ResponseHeaders, Client}, SuccessStatusCode, DecodeBody)
when StatusCode =:= 200;
StatusCode =:= 202;
StatusCode =:= 204;
StatusCode =:= 206;
StatusCode =:= SuccessStatusCode ->
case hackney:body(Client) of
{ok, <<>>} when StatusCode =:= 200;
StatusCode =:= SuccessStatusCode ->
{ok, #{}, {StatusCode, ResponseHeaders, Client}};
{ok, Body} ->
Result = case DecodeBody of
true ->
try
jsx:decode(Body)
catch
Error:Reason:Stack ->
erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack)
end;
false -> #{<<"Body">> => Body}
end,
{ok, Result, {StatusCode, ResponseHeaders, Client}}
end;
handle_response({ok, StatusCode, ResponseHeaders, Client}, _, _DecodeBody) ->
{ok, Body} = hackney:body(Client),
try
DecodedError = jsx:decode(Body),
{error, DecodedError, {StatusCode, ResponseHeaders, Client}}
catch
Error:Reason:Stack ->
erlang:raise(error, {body_decode_failed, Error, Reason, StatusCode, Body}, Stack)
end;
handle_response({error, Reason}, _, _DecodeBody) ->
{error, Reason}.
build_host(_EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) ->
Endpoint;
build_host(_EndpointPrefix, #{region := <<"local">>}) ->
<<"localhost">>;
build_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) ->
aws_util:binary_join([EndpointPrefix, Region, Endpoint], <<".">>).
build_url(Host, Path0, Client) ->
Proto = maps:get(proto, Client),
Path = erlang:iolist_to_binary(Path0),
Port = maps:get(port, Client),
aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, Path], <<"">>).
-spec encode_payload(undefined | map()) -> binary().
encode_payload(undefined) ->
<<>>;
encode_payload(Input) ->
jsx:encode(Input).