From 209c02ec57c2cc3207ee0174c3af3675b8dc8f79 Mon Sep 17 00:00:00 2001 From: Bryan Paxton <39971740+starbelly@users.noreply.github.com> Date: Thu, 7 Mar 2019 10:54:01 -0600 Subject: Fix fetching of private packages from orgs on hex repos (#2020) - vendor in hex_core at v0.5.0 - Change where repo_name should be the org and not the parent - Changed rebar_utils:url_append_path/2 to not explicitly add a '?', this is returned in the Query chunk by http_uri:parse/1 (e.g., "?foo=bar") - update organization_merging test to expect the sub-repo as the repo_name - Add tests for rebar_utils:url_append_path/2 - Stop referencing/setting "organization" in config and use new organization settings (api_repository and repo_organization) - Do not set (assume) the read key is valid for any/every repo - Set repo_organization and api_repository to org - Update tests to check for new config opts --- src/r3_hex_api_release.erl | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/r3_hex_api_release.erl (limited to 'src/r3_hex_api_release.erl') diff --git a/src/r3_hex_api_release.erl b/src/r3_hex_api_release.erl new file mode 100644 index 0000000..4acda0e --- /dev/null +++ b/src/r3_hex_api_release.erl @@ -0,0 +1,60 @@ +%% Vendored from hex_core v0.5.0, do not edit manually + +-module(r3_hex_api_release). +-export([ + delete/3, + get/3, + publish/2, + retire/4, + unretire/3 +]). + +%% @doc +%% Gets package release. +%% +%% Examples: +%% +%% ``` +%% > r3_hex_api:get_release(<<"package">>, <<"1.0.0">>, r3_hex_core:default_config()). +%% {ok, {200, ..., #{ +%% <<"version">> => <<"1.0.0">>, +%% <<"meta">> => #{ +%% <<"description">> => ..., +%% <<"licenses">> => ..., +%% <<"links">> => ..., +%% <<"maintainers">> => ... +%% }, +%% ...}}} +%% ''' +%% @end +get(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) -> + Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]), + r3_hex_api:get(Config, Path). + +publish(Config, Tarball) when is_binary(Tarball) and is_map(Config) -> + Path = r3_hex_api:build_repository_path(Config, ["publish"]), + TarballContentType = "application/octet-stream", + Config2 = put_header(<<"content-length">>, integer_to_binary(byte_size(Tarball)), Config), + Body = {TarballContentType, Tarball}, + r3_hex_api:post(Config2, Path, Body). + +delete(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) -> + Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]), + r3_hex_api:delete(Config, Path). + +retire(Config, Name, Version, Params) when is_binary(Name) and is_binary(Version) and is_map(Config) -> + Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]), + r3_hex_api:post(Config, Path, Params). + +unretire(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) -> + Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]), + r3_hex_api:delete(Config, Path). + +%%==================================================================== +%% Internal functions +%%==================================================================== + +put_header(Name, Value, Config) -> + Headers = maps:get(http_headers, Config, #{}), + Headers2 = maps:put(Name, Value, Headers), + maps:put(http_headers, Headers2, Config). -- cgit v1.1