Module r3_hex_repo

Repo API.

Description

Repo API.

Function Index

fingerprint/1 Computes a SHA256 fingerprint of a PEM-encoded public key.
fingerprint_equal/2 Compares a PEM-encoded public key against an expected fingerprint.
get_docs/3 Gets docs tarball from the repository.
get_docs_to_file/4 Gets docs tarball from the repository and writes it to a file.
get_hex_installs/1 Gets Hex installation versions CSV from repository.
get_names/1 Gets names resource from the repository.
get_package/2 Gets package resource from the repository.
get_policy/2 Gets policy resource from the repository.
get_public_key/1 Gets the public key from the repository.
get_tarball/3 Gets tarball from the repository.
get_tarball_to_file/4 Gets tarball from the repository and writes it to a file.
get_versions/1 Gets versions resource from the repository.

Function Details

fingerprint/1

fingerprint(PublicKeyPem::binary()) -> string()

Computes a SHA256 fingerprint of a PEM-encoded public key.

Returns a string in the format "SHA256:" followed by base64, which can be used to verify public keys out-of-band.

Examples:

  > r3_hex_repo:fingerprint(PublicKeyPem).
  "SHA256:abc123..."

fingerprint_equal/2

fingerprint_equal(PublicKeyPem::binary(), ExpectedFingerprint::iodata()) -> boolean()

Compares a PEM-encoded public key against an expected fingerprint.

Uses constant-time comparison to prevent timing attacks.

Examples:

  > r3_hex_repo:fingerprint_equal(PublicKeyPem, "SHA256:abc123...").
  true

get_docs/3

get_docs(Config, Name, Version) -> any()

Gets docs tarball from the repository.

Examples:

  > {ok, {200, _, Docs}} = r3_hex_repo:get_docs(r3_hex_core:default_config(), <<"package1">>, <<"1.0.0">>),
  > r3_hex_tarball:unpack_docs(Docs, "/tmp/docs")
  ok

get_docs_to_file/4

get_docs_to_file(Config, Name, Version, Filename) -> any()

Gets docs tarball from the repository and writes it to a file.

Examples:

  > {ok, {200, _}} = r3_hex_repo:get_docs_to_file(r3_hex_core:default_config(), <<"package1">>, <<"1.0.0">>, "/tmp/docs.tar.gz"),
  > ok = r3_hex_tarball:unpack_docs({file, "/tmp/docs.tar.gz"}, "/tmp/docs").

get_hex_installs/1

get_hex_installs(Config) -> any()

Gets Hex installation versions CSV from repository.

Examples:

  > r3_hex_repo:get_hex_installs(r3_hex_core:default_config()).
  {ok, {200, ..., <<"1.0.0,abc123,1.13.0\n1.1.0,def456,1.14.0\n...">>}}

get_names/1

get_names(Config) -> any()

Gets names resource from the repository.

Examples:

  > r3_hex_repo:get_names(r3_hex_core:default_config()).
  {ok,{200, ...,
       #{packages => [
             #{name => <<"package1">>},
             #{name => <<"package2">>},
             ...]}}}

get_package/2

get_package(Config, Name) -> any()

Gets package resource from the repository.

Examples:

  > r3_hex_repo:get_package(r3_hex_core:default_config(), <<"package1">>).
  {ok, {200, ...,
        #{name => <<"package1">>,
          releases => [
              #{checksum => ..., version => <<"0.5.0">>, dependencies => []},
              #{checksum => ..., version => <<"1.0.0">>, dependencies => [
                    #{package => <<"package2">>, optional => true, requirement => <<"~> 0.1">>}
              ]},
      ]}}}

get_policy/2

get_policy(Config, Name) -> any()

Gets policy resource from the repository.

Like the other resources, the URL is built from repo_url (with repo_organization inserting the /repos/:org segment when set), so the caller controls the layout through the config rather than this function requiring a particular field.

Examples:

  > Config = (r3_hex_core:default_config())#{repo_organization => <<"myorg">>},
  > r3_hex_repo:get_policy(Config, <<"strict-prod">>).
  {ok, {200, ...,
        #{repository => <<"myorg">>,
          name => <<"strict-prod">>,
          visibility => 'VISIBILITY_PUBLIC'}}}

get_public_key/1

get_public_key(Config) -> any()

Gets the public key from the repository.

Examples:

  > r3_hex_repo:get_public_key(r3_hex_core:default_config())
  {ok, {200, _, PublicKey}}

get_tarball/3

get_tarball(Config, Name, Version) -> any()

Gets tarball from the repository.

Examples:

  > {ok, {200, _, Tarball}} = r3_hex_repo:get_tarball(r3_hex_core:default_config(), <<"package1">>, <<"1.0.0">>),
  > {ok, #{metadata := Metadata}} = r3_hex_tarball:unpack(Tarball, "/tmp/package").

get_tarball_to_file/4

get_tarball_to_file(Config, Name, Version, Filename) -> any()

Gets tarball from the repository and writes it to a file.

Examples:

  > {ok, {200, _}} = r3_hex_repo:get_tarball_to_file(r3_hex_core:default_config(), <<"package1">>, <<"1.0.0">>, "/tmp/package.tar"),
  > {ok, #{metadata := Metadata}} = r3_hex_tarball:unpack({file, "/tmp/package.tar"}, "/tmp/package").

get_versions/1

get_versions(Config) -> any()

Gets versions resource from the repository.

Examples:

  > r3_hex_repo:get_versions(Config).
  {ok, {200, ...,
        #{packages => [
              #{name => <<"package1">>, retired => [],
                versions => [<<"1.0.0">>]},
              #{name => <<"package2">>, retired => [<<"0.5.0>>"],
                versions => [<<"0.5.0">>, <<"1.0.0">>]},
              ...]}}}


Generated by EDoc