You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.1 KiB

  1. %% Vendored from hex_core v0.7.0, do not edit manually
  2. %% @doc
  3. %% hex_core entrypoint module.
  4. %%
  5. %% ### Config
  6. %%
  7. %% Most functions in the hex_core API takes a configuration. The configuration sets things
  8. %% like HTTP client to use, and API and repository URL. Some of these configuration options
  9. %% will likely be static for your application and some may change depending on the function
  10. %% you call.
  11. %%
  12. %% ##### Options
  13. %%
  14. %% * `api_key' - Authentication key used when accessing the HTTP API.
  15. %% * `api_organization' - Name of the organization endpoint in the API, this should
  16. %% for example be set when accessing key for a specific organization.
  17. %% * `api_repository' - Name of the repository endpoint in the API, this should
  18. %% for example be set when accessing packages from a specific repository.
  19. %% * `api_url' - URL to the HTTP API (default: `https://hex.pm/api').
  20. %% * `http_adapter' - Callback module used for HTTP requests, see [`r3_hex_http'](r3_hex_http.html)
  21. %% (default: `r3_hex_http_httpc').
  22. %% * `http_etag' - Sets the `if-none-match' HTTP header with the given value to do a
  23. %% conditional HTTP request.
  24. %% * `http_adapter_config' - Configuration to pass to the HTTP adapter.
  25. %% * `http_user_agent_fragment' - Will be appended to the `user-agent` HTTP header (default: `(httpc)').
  26. %% * `repo_key' - Authentication key used when accessing the repository.
  27. %% * `repo_name' - Name of the repository, used for verifying the repository signature
  28. %% authenticity (default: `hexpm').
  29. %% * `repo_public_key' - Public key used to verify the repository signature
  30. %% (defaults to hexpm public key `https://hex.pm/docs/public_keys').
  31. %% * `repo_url' - URL to the repository (default: `https://repo.hex.pm').
  32. %% * `repo_organization' - Name of the organization repository, appends `/repos/:name'
  33. %% to the repository URL and overrides the `repo_name' option.
  34. %% * `repo_verify' - If `true' will verify the repository signature (default: `true').
  35. %% * `repo_verify_origin' - If `true' will verify the repository signature origin,
  36. %% requires protobuf messages as of hex_core v0.4.0 (default: `true').
  37. -module(r3_hex_core).
  38. -export([default_config/0]).
  39. -export_type([config/0]).
  40. %% https://hex.pm/docs/public_keys
  41. -define(HEXPM_PUBLIC_KEY, <<"-----BEGIN PUBLIC KEY-----
  42. MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApqREcFDt5vV21JVe2QNB
  43. Edvzk6w36aNFhVGWN5toNJRjRJ6m4hIuG4KaXtDWVLjnvct6MYMfqhC79HAGwyF+
  44. IqR6Q6a5bbFSsImgBJwz1oadoVKD6ZNetAuCIK84cjMrEFRkELtEIPNHblCzUkkM
  45. 3rS9+DPlnfG8hBvGi6tvQIuZmXGCxF/73hU0/MyGhbmEjIKRtG6b0sJYKelRLTPW
  46. XgK7s5pESgiwf2YC/2MGDXjAJfpfCd0RpLdvd4eRiXtVlE9qO9bND94E7PgQ/xqZ
  47. J1i2xWFndWa6nfFnRxZmCStCOZWYYPlaxr+FZceFbpMwzTNs4g3d4tLNUcbKAIH4
  48. 0wIDAQAB
  49. -----END PUBLIC KEY-----">>).
  50. -type config() :: #{
  51. api_key => binary() | undefined,
  52. api_organization => binary() | undefined,
  53. api_repository => binary() | undefined,
  54. api_url => binary(),
  55. http_adapter => module(),
  56. http_etag => binary() | undefined,
  57. http_adapter_config => map(),
  58. http_headers => map(),
  59. http_user_agent_fragment => binary(),
  60. repo_key => binary() | undefined,
  61. repo_name => binary(),
  62. repo_public_key => binary(),
  63. repo_url => binary(),
  64. repo_organization => binary() | undefined,
  65. repo_verify => boolean(),
  66. repo_verify_origin => boolean(),
  67. tarball_max_size => pos_integer(),
  68. tarball_max_uncompressed_size => pos_integer()
  69. }.
  70. -spec default_config() -> config().
  71. default_config() ->
  72. #{
  73. api_key => undefined,
  74. api_organization => undefined,
  75. api_repository => undefined,
  76. api_url => <<"https://hex.pm/api">>,
  77. http_adapter => r3_hex_http_httpc,
  78. http_adapter_config => #{profile => default},
  79. http_etag => undefined,
  80. http_headers => #{},
  81. http_user_agent_fragment => <<"(httpc)">>,
  82. repo_key => undefined,
  83. repo_name => <<"hexpm">>,
  84. repo_public_key => ?HEXPM_PUBLIC_KEY,
  85. repo_url => <<"https://repo.hex.pm">>,
  86. repo_organization => undefined,
  87. repo_verify => true,
  88. repo_verify_origin => true,
  89. tarball_max_size => 8 * 1024 * 1024,
  90. tarball_max_uncompressed_size => 64 * 1024 * 1024
  91. }.