%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE! %% See https://github.com/aws-beam/aws-codegen for more details. %% @doc The frontend service for Cryo Storage. -module(aws_backupstorage). -export([delete_object/4, delete_object/5, get_chunk/3, get_chunk/5, get_chunk/6, get_object_metadata/3, get_object_metadata/5, get_object_metadata/6, list_chunks/3, list_chunks/5, list_chunks/6, list_objects/2, list_objects/4, list_objects/5, notify_object_complete/4, notify_object_complete/5, put_chunk/5, put_chunk/6, put_object/4, put_object/5, start_object/4, start_object/5]). -include_lib("hackney/include/hackney_lib.hrl"). %% Example: %% access_denied_exception() :: #{ %% <<"Message">> => string() %% } -type access_denied_exception() :: #{binary() => any()}. %% Example: %% backup_object() :: #{ %% <<"ChunksCount">> => float(), %% <<"MetadataString">> => string(), %% <<"Name">> => string(), %% <<"ObjectChecksum">> => string(), %% <<"ObjectChecksumAlgorithm">> => list(any()), %% <<"ObjectToken">> => string() %% } -type backup_object() :: #{binary() => any()}. %% Example: %% chunk() :: #{ %% <<"Checksum">> => string(), %% <<"ChecksumAlgorithm">> => list(any()), %% <<"ChunkToken">> => string(), %% <<"Index">> => float(), %% <<"Length">> => float() %% } -type chunk() :: #{binary() => any()}. %% Example: %% data_already_exists_exception() :: #{ %% <<"Checksum">> => string(), %% <<"ChecksumAlgorithm">> => string(), %% <<"Message">> => string() %% } -type data_already_exists_exception() :: #{binary() => any()}. %% Example: %% delete_object_input() :: #{} -type delete_object_input() :: #{}. %% Example: %% get_chunk_input() :: #{} -type get_chunk_input() :: #{}. %% Example: %% get_chunk_output() :: #{ %% <<"Checksum">> => string(), %% <<"ChecksumAlgorithm">> => list(any()), %% <<"Data">> => binary(), %% <<"Length">> => float() %% } -type get_chunk_output() :: #{binary() => any()}. %% Example: %% get_object_metadata_input() :: #{} -type get_object_metadata_input() :: #{}. %% Example: %% get_object_metadata_output() :: #{ %% <<"MetadataBlob">> => binary(), %% <<"MetadataBlobChecksum">> => string(), %% <<"MetadataBlobChecksumAlgorithm">> => list(any()), %% <<"MetadataBlobLength">> => float(), %% <<"MetadataString">> => string() %% } -type get_object_metadata_output() :: #{binary() => any()}. %% Example: %% illegal_argument_exception() :: #{ %% <<"Message">> => string() %% } -type illegal_argument_exception() :: #{binary() => any()}. %% Example: %% kms_invalid_key_usage_exception() :: #{ %% <<"Message">> => string() %% } -type kms_invalid_key_usage_exception() :: #{binary() => any()}. %% Example: %% list_chunks_input() :: #{ %% <<"MaxResults">> => integer(), %% <<"NextToken">> => string() %% } -type list_chunks_input() :: #{binary() => any()}. %% Example: %% list_chunks_output() :: #{ %% <<"ChunkList">> => list(chunk()()), %% <<"NextToken">> => string() %% } -type list_chunks_output() :: #{binary() => any()}. %% Example: %% list_objects_input() :: #{ %% <<"CreatedAfter">> => non_neg_integer(), %% <<"CreatedBefore">> => non_neg_integer(), %% <<"MaxResults">> => integer(), %% <<"NextToken">> => string(), %% <<"StartingObjectName">> => string(), %% <<"StartingObjectPrefix">> => string() %% } -type list_objects_input() :: #{binary() => any()}. %% Example: %% list_objects_output() :: #{ %% <<"NextToken">> => string(), %% <<"ObjectList">> => list(backup_object()()) %% } -type list_objects_output() :: #{binary() => any()}. %% Example: %% not_readable_input_stream_exception() :: #{ %% <<"Message">> => string() %% } -type not_readable_input_stream_exception() :: #{binary() => any()}. %% Example: %% notify_object_complete_input() :: #{ %% <<"MetadataBlob">> => binary(), %% <<"MetadataBlobChecksum">> => string(), %% <<"MetadataBlobChecksumAlgorithm">> => list(any()), %% <<"MetadataBlobLength">> => float(), %% <<"MetadataString">> => string(), %% <<"ObjectChecksum">> := string(), %% <<"ObjectChecksumAlgorithm">> := list(any()) %% } -type notify_object_complete_input() :: #{binary() => any()}. %% Example: %% notify_object_complete_output() :: #{ %% <<"ObjectChecksum">> => string(), %% <<"ObjectChecksumAlgorithm">> => list(any()) %% } -type notify_object_complete_output() :: #{binary() => any()}. %% Example: %% put_chunk_input() :: #{ %% <<"Checksum">> := string(), %% <<"ChecksumAlgorithm">> := list(any()), %% <<"Data">> := binary(), %% <<"Length">> := float() %% } -type put_chunk_input() :: #{binary() => any()}. %% Example: %% put_chunk_output() :: #{ %% <<"ChunkChecksum">> => string(), %% <<"ChunkChecksumAlgorithm">> => list(any()) %% } -type put_chunk_output() :: #{binary() => any()}. %% Example: %% put_object_input() :: #{ %% <<"InlineChunk">> => binary(), %% <<"InlineChunkChecksum">> => string(), %% <<"InlineChunkChecksumAlgorithm">> => string(), %% <<"InlineChunkLength">> => float(), %% <<"MetadataString">> => string(), %% <<"ObjectChecksum">> => string(), %% <<"ObjectChecksumAlgorithm">> => list(any()), %% <<"ThrowOnDuplicate">> => boolean() %% } -type put_object_input() :: #{binary() => any()}. %% Example: %% put_object_output() :: #{ %% <<"InlineChunkChecksum">> => string(), %% <<"InlineChunkChecksumAlgorithm">> => list(any()), %% <<"ObjectChecksum">> => string(), %% <<"ObjectChecksumAlgorithm">> => list(any()) %% } -type put_object_output() :: #{binary() => any()}. %% Example: %% resource_not_found_exception() :: #{ %% <<"Message">> => string() %% } -type resource_not_found_exception() :: #{binary() => any()}. %% Example: %% retryable_exception() :: #{ %% <<"Message">> => string() %% } -type retryable_exception() :: #{binary() => any()}. %% Example: %% service_internal_exception() :: #{ %% <<"Message">> => string() %% } -type service_internal_exception() :: #{binary() => any()}. %% Example: %% service_unavailable_exception() :: #{ %% <<"Message">> => string() %% } -type service_unavailable_exception() :: #{binary() => any()}. %% Example: %% start_object_input() :: #{ %% <<"ThrowOnDuplicate">> => boolean() %% } -type start_object_input() :: #{binary() => any()}. %% Example: %% start_object_output() :: #{ %% <<"UploadId">> => string() %% } -type start_object_output() :: #{binary() => any()}. %% Example: %% throttling_exception() :: #{ %% <<"Message">> => string() %% } -type throttling_exception() :: #{binary() => any()}. -type delete_object_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | illegal_argument_exception() | access_denied_exception(). -type get_chunk_errors() :: throttling_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type get_object_metadata_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type list_chunks_errors() :: service_unavailable_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | illegal_argument_exception() | access_denied_exception(). -type list_objects_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type notify_object_complete_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | not_readable_input_stream_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type put_chunk_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | not_readable_input_stream_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type put_object_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | not_readable_input_stream_exception() | kms_invalid_key_usage_exception() | illegal_argument_exception() | access_denied_exception(). -type start_object_errors() :: throttling_exception() | service_unavailable_exception() | service_internal_exception() | retryable_exception() | resource_not_found_exception() | illegal_argument_exception() | data_already_exists_exception() | access_denied_exception(). %%==================================================================== %% API %%==================================================================== %% @doc Delete Object from the incremental base Backup. -spec delete_object(aws_client:aws_client(), binary() | list(), binary() | list(), delete_object_input()) -> {ok, undefined, tuple()} | {error, any()} | {error, delete_object_errors(), tuple()}. delete_object(Client, BackupJobId, ObjectName, Input) -> delete_object(Client, BackupJobId, ObjectName, Input, []). -spec delete_object(aws_client:aws_client(), binary() | list(), binary() | list(), delete_object_input(), proplists:proplist()) -> {ok, undefined, tuple()} | {error, any()} | {error, delete_object_errors(), tuple()}. delete_object(Client, BackupJobId, ObjectName, Input0, Options0) -> Method = delete, Path = ["/backup-jobs/", aws_util:encode_uri(BackupJobId), "/object/", aws_util:encode_uri(ObjectName), ""], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Gets the specified object's chunk. -spec get_chunk(aws_client:aws_client(), binary() | list(), binary() | list()) -> {ok, get_chunk_output(), tuple()} | {error, any()} | {error, get_chunk_errors(), tuple()}. get_chunk(Client, ChunkToken, StorageJobId) when is_map(Client) -> get_chunk(Client, ChunkToken, StorageJobId, #{}, #{}). -spec get_chunk(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map()) -> {ok, get_chunk_output(), tuple()} | {error, any()} | {error, get_chunk_errors(), tuple()}. get_chunk(Client, ChunkToken, StorageJobId, QueryMap, HeadersMap) when is_map(Client), is_map(QueryMap), is_map(HeadersMap) -> get_chunk(Client, ChunkToken, StorageJobId, QueryMap, HeadersMap, []). -spec get_chunk(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map(), proplists:proplist()) -> {ok, get_chunk_output(), tuple()} | {error, any()} | {error, get_chunk_errors(), tuple()}. get_chunk(Client, ChunkToken, StorageJobId, QueryMap, HeadersMap, Options0) when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) -> Path = ["/restore-jobs/", aws_util:encode_uri(StorageJobId), "/chunk/", aws_util:encode_uri(ChunkToken), ""], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary} | Options2], Headers = [], Query_ = [], case request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode) of {ok, Body0, {_, ResponseHeaders, _} = Response} -> ResponseHeadersParams = [ {<<"x-amz-checksum">>, <<"Checksum">>}, {<<"x-amz-checksum-algorithm">>, <<"ChecksumAlgorithm">>}, {<<"x-amz-data-length">>, <<"Length">>} ], FoldFun = fun({Name_, Key_}, Acc_) -> case lists:keyfind(Name_, 1, ResponseHeaders) of false -> Acc_; {_, Value_} -> Acc_#{Key_ => Value_} end end, Body = lists:foldl(FoldFun, Body0, ResponseHeadersParams), {ok, Body, Response}; Result -> Result end. %% @doc Get metadata associated with an Object. -spec get_object_metadata(aws_client:aws_client(), binary() | list(), binary() | list()) -> {ok, get_object_metadata_output(), tuple()} | {error, any()} | {error, get_object_metadata_errors(), tuple()}. get_object_metadata(Client, ObjectToken, StorageJobId) when is_map(Client) -> get_object_metadata(Client, ObjectToken, StorageJobId, #{}, #{}). -spec get_object_metadata(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map()) -> {ok, get_object_metadata_output(), tuple()} | {error, any()} | {error, get_object_metadata_errors(), tuple()}. get_object_metadata(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap) when is_map(Client), is_map(QueryMap), is_map(HeadersMap) -> get_object_metadata(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap, []). -spec get_object_metadata(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map(), proplists:proplist()) -> {ok, get_object_metadata_output(), tuple()} | {error, any()} | {error, get_object_metadata_errors(), tuple()}. get_object_metadata(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap, Options0) when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) -> Path = ["/restore-jobs/", aws_util:encode_uri(StorageJobId), "/object/", aws_util:encode_uri(ObjectToken), "/metadata"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary} | Options2], Headers = [], Query_ = [], case request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode) of {ok, Body0, {_, ResponseHeaders, _} = Response} -> ResponseHeadersParams = [ {<<"x-amz-checksum">>, <<"MetadataBlobChecksum">>}, {<<"x-amz-checksum-algorithm">>, <<"MetadataBlobChecksumAlgorithm">>}, {<<"x-amz-data-length">>, <<"MetadataBlobLength">>}, {<<"x-amz-metadata-string">>, <<"MetadataString">>} ], FoldFun = fun({Name_, Key_}, Acc_) -> case lists:keyfind(Name_, 1, ResponseHeaders) of false -> Acc_; {_, Value_} -> Acc_#{Key_ => Value_} end end, Body = lists:foldl(FoldFun, Body0, ResponseHeadersParams), {ok, Body, Response}; Result -> Result end. %% @doc List chunks in a given Object -spec list_chunks(aws_client:aws_client(), binary() | list(), binary() | list()) -> {ok, list_chunks_output(), tuple()} | {error, any()} | {error, list_chunks_errors(), tuple()}. list_chunks(Client, ObjectToken, StorageJobId) when is_map(Client) -> list_chunks(Client, ObjectToken, StorageJobId, #{}, #{}). -spec list_chunks(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map()) -> {ok, list_chunks_output(), tuple()} | {error, any()} | {error, list_chunks_errors(), tuple()}. list_chunks(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap) when is_map(Client), is_map(QueryMap), is_map(HeadersMap) -> list_chunks(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap, []). -spec list_chunks(aws_client:aws_client(), binary() | list(), binary() | list(), map(), map(), proplists:proplist()) -> {ok, list_chunks_output(), tuple()} | {error, any()} | {error, list_chunks_errors(), tuple()}. list_chunks(Client, ObjectToken, StorageJobId, QueryMap, HeadersMap, Options0) when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) -> Path = ["/restore-jobs/", aws_util:encode_uri(StorageJobId), "/chunks/", aws_util:encode_uri(ObjectToken), "/list"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary} | Options2], Headers = [], Query0_ = [ {<<"max-results">>, maps:get(<<"max-results">>, QueryMap, undefined)}, {<<"next-token">>, maps:get(<<"next-token">>, QueryMap, undefined)} ], Query_ = [H || {_, V} = H <- Query0_, V =/= undefined], request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode). %% @doc List all Objects in a given Backup. -spec list_objects(aws_client:aws_client(), binary() | list()) -> {ok, list_objects_output(), tuple()} | {error, any()} | {error, list_objects_errors(), tuple()}. list_objects(Client, StorageJobId) when is_map(Client) -> list_objects(Client, StorageJobId, #{}, #{}). -spec list_objects(aws_client:aws_client(), binary() | list(), map(), map()) -> {ok, list_objects_output(), tuple()} | {error, any()} | {error, list_objects_errors(), tuple()}. list_objects(Client, StorageJobId, QueryMap, HeadersMap) when is_map(Client), is_map(QueryMap), is_map(HeadersMap) -> list_objects(Client, StorageJobId, QueryMap, HeadersMap, []). -spec list_objects(aws_client:aws_client(), binary() | list(), map(), map(), proplists:proplist()) -> {ok, list_objects_output(), tuple()} | {error, any()} | {error, list_objects_errors(), tuple()}. list_objects(Client, StorageJobId, QueryMap, HeadersMap, Options0) when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) -> Path = ["/restore-jobs/", aws_util:encode_uri(StorageJobId), "/objects/list"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary} | Options2], Headers = [], Query0_ = [ {<<"created-after">>, maps:get(<<"created-after">>, QueryMap, undefined)}, {<<"created-before">>, maps:get(<<"created-before">>, QueryMap, undefined)}, {<<"max-results">>, maps:get(<<"max-results">>, QueryMap, undefined)}, {<<"next-token">>, maps:get(<<"next-token">>, QueryMap, undefined)}, {<<"starting-object-name">>, maps:get(<<"starting-object-name">>, QueryMap, undefined)}, {<<"starting-object-prefix">>, maps:get(<<"starting-object-prefix">>, QueryMap, undefined)} ], Query_ = [H || {_, V} = H <- Query0_, V =/= undefined], request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode). %% @doc Complete upload -spec notify_object_complete(aws_client:aws_client(), binary() | list(), binary() | list(), notify_object_complete_input()) -> {ok, notify_object_complete_output(), tuple()} | {error, any()} | {error, notify_object_complete_errors(), tuple()}. notify_object_complete(Client, BackupJobId, UploadId, Input) -> notify_object_complete(Client, BackupJobId, UploadId, Input, []). -spec notify_object_complete(aws_client:aws_client(), binary() | list(), binary() | list(), notify_object_complete_input(), proplists:proplist()) -> {ok, notify_object_complete_output(), tuple()} | {error, any()} | {error, notify_object_complete_errors(), tuple()}. notify_object_complete(Client, BackupJobId, UploadId, Input0, Options0) -> Method = put, Path = ["/backup-jobs/", aws_util:encode_uri(BackupJobId), "/object/", aws_util:encode_uri(UploadId), "/complete"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, QueryMapping = [ {<<"metadata-checksum">>, <<"MetadataBlobChecksum">>}, {<<"metadata-checksum-algorithm">>, <<"MetadataBlobChecksumAlgorithm">>}, {<<"metadata-blob-length">>, <<"MetadataBlobLength">>}, {<<"metadata-string">>, <<"MetadataString">>}, {<<"checksum">>, <<"ObjectChecksum">>}, {<<"checksum-algorithm">>, <<"ObjectChecksumAlgorithm">>} ], {Query_, Input} = aws_request:build_headers(QueryMapping, Input2), request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Upload chunk. -spec put_chunk(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), put_chunk_input()) -> {ok, put_chunk_output(), tuple()} | {error, any()} | {error, put_chunk_errors(), tuple()}. put_chunk(Client, BackupJobId, ChunkIndex, UploadId, Input) -> put_chunk(Client, BackupJobId, ChunkIndex, UploadId, Input, []). -spec put_chunk(aws_client:aws_client(), binary() | list(), binary() | list(), binary() | list(), put_chunk_input(), proplists:proplist()) -> {ok, put_chunk_output(), tuple()} | {error, any()} | {error, put_chunk_errors(), tuple()}. put_chunk(Client, BackupJobId, ChunkIndex, UploadId, Input0, Options0) -> Method = put, Path = ["/backup-jobs/", aws_util:encode_uri(BackupJobId), "/chunk/", aws_util:encode_uri(UploadId), "/", aws_util:encode_uri(ChunkIndex), ""], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, QueryMapping = [ {<<"checksum">>, <<"Checksum">>}, {<<"checksum-algorithm">>, <<"ChecksumAlgorithm">>}, {<<"length">>, <<"Length">>} ], {Query_, Input} = aws_request:build_headers(QueryMapping, Input2), request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Upload object that can store object metadata String and data blob in %% single API call using inline chunk field. -spec put_object(aws_client:aws_client(), binary() | list(), binary() | list(), put_object_input()) -> {ok, put_object_output(), tuple()} | {error, any()} | {error, put_object_errors(), tuple()}. put_object(Client, BackupJobId, ObjectName, Input) -> put_object(Client, BackupJobId, ObjectName, Input, []). -spec put_object(aws_client:aws_client(), binary() | list(), binary() | list(), put_object_input(), proplists:proplist()) -> {ok, put_object_output(), tuple()} | {error, any()} | {error, put_object_errors(), tuple()}. put_object(Client, BackupJobId, ObjectName, Input0, Options0) -> Method = put, Path = ["/backup-jobs/", aws_util:encode_uri(BackupJobId), "/object/", aws_util:encode_uri(ObjectName), "/put-object"], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, QueryMapping = [ {<<"checksum">>, <<"InlineChunkChecksum">>}, {<<"checksum-algorithm">>, <<"InlineChunkChecksumAlgorithm">>}, {<<"length">>, <<"InlineChunkLength">>}, {<<"metadata-string">>, <<"MetadataString">>}, {<<"object-checksum">>, <<"ObjectChecksum">>}, {<<"object-checksum-algorithm">>, <<"ObjectChecksumAlgorithm">>}, {<<"throwOnDuplicate">>, <<"ThrowOnDuplicate">>} ], {Query_, Input} = aws_request:build_headers(QueryMapping, Input2), request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %% @doc Start upload containing one or many chunks. -spec start_object(aws_client:aws_client(), binary() | list(), binary() | list(), start_object_input()) -> {ok, start_object_output(), tuple()} | {error, any()} | {error, start_object_errors(), tuple()}. start_object(Client, BackupJobId, ObjectName, Input) -> start_object(Client, BackupJobId, ObjectName, Input, []). -spec start_object(aws_client:aws_client(), binary() | list(), binary() | list(), start_object_input(), proplists:proplist()) -> {ok, start_object_output(), tuple()} | {error, any()} | {error, start_object_errors(), tuple()}. start_object(Client, BackupJobId, ObjectName, Input0, Options0) -> Method = put, Path = ["/backup-jobs/", aws_util:encode_uri(BackupJobId), "/object/", aws_util:encode_uri(ObjectName), ""], SuccessStatusCode = 200, {SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, false), {ReceiveBodyAsBinary, Options2} = proplists_take(receive_body_as_binary, Options1, false), Options = [{send_body_as_binary, SendBodyAsBinary}, {receive_body_as_binary, ReceiveBodyAsBinary}, {append_sha256_content_hash, false} | Options2], Headers = [], Input1 = Input0, CustomHeaders = [], Input2 = Input1, Query_ = [], Input = Input2, request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode). %%==================================================================== %% Internal functions %%==================================================================== -spec proplists_take(any(), proplists:proplist(), any()) -> {any(), proplists:proplist()}. proplists_take(Key, Proplist, Default) -> Value = proplists:get_value(Key, Proplist, Default), {Value, proplists:delete(Key, Proplist)}. -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 => <<"backup-storage">>}, Host = build_host(<<"backupstorage">>, 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) when StatusCode =:= 503 -> %% Retriable error if retries are enabled {error, service_unavailable}; 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 = aws_client:proto(Client), Path = erlang:iolist_to_binary(Path0), Port = aws_client: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).