Skip to content

Commit e09c05e

Browse files
coryodanielclaude
andcommitted
Define common OCI types in Registry module
Add repo_t, digest_t, reference_t, tag_t, and uuid_t type aliases to OCI.Registry and use them across Registry specs and Adapter callbacks to replace bare String.t() params. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent feab01d commit e09c05e

2 files changed

Lines changed: 64 additions & 46 deletions

File tree

lib/oci/registry.ex

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ defmodule OCI.Registry do
66

77
use TypedStruct
88

9+
@typedoc "Repository name, e.g. `\"myorg/myrepo\"`"
10+
@type repo_t :: String.t()
11+
12+
@typedoc "Content-addressable digest, e.g. `\"sha256:abc123...\"`"
13+
@type digest_t :: String.t()
14+
15+
@typedoc "A tag or digest used to identify a manifest"
16+
@type reference_t :: String.t()
17+
18+
@typedoc "Human-readable tag, e.g. `\"latest\"` or `\"v1.0.0\"`"
19+
@type tag_t :: String.t()
20+
21+
@typedoc "Upload session identifier (UUID)"
22+
@type uuid_t :: String.t()
23+
924
@repo_name_pattern ~r/^([a-z0-9]+(?:[._-][a-z0-9]+)*)(\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*$/
1025

1126
typedstruct do
@@ -64,8 +79,8 @@ defmodule OCI.Registry do
6479
adapter(auth).challenge(registry)
6580
end
6681

67-
@spec validate_repository_name(registry :: t(), repo :: String.t()) ::
68-
{:ok, repo :: String.t()} | {:error, :NAME_INVALID, String.t()}
82+
@spec validate_repository_name(registry :: t(), repo :: repo_t()) ::
83+
{:ok, repo :: repo_t()} | {:error, :NAME_INVALID, String.t()}
6984

7085
def validate_repository_name(registry, repo) do
7186
if Regex.match?(registry.repo_name_pattern, repo) do
@@ -329,7 +344,7 @@ defmodule OCI.Registry do
329344
iex> OCI.Registry.verify_digest("hello", "invalid-digest")
330345
{:error, :DIGEST_INVALID, %{digest: "invalid-digest", msg: "Invalid digest format"}}
331346
"""
332-
@spec verify_digest(binary(), String.t()) :: :ok | {:error, :DIGEST_INVALID, map()}
347+
@spec verify_digest(binary(), digest_t()) :: :ok | {:error, :DIGEST_INVALID, map()}
333348
def verify_digest(data, digest) do
334349
case digest do
335350
"sha256:" <> hash ->
@@ -376,7 +391,7 @@ defmodule OCI.Registry do
376391
iex> OCI.Registry.blobs_digest_path("myrepo", "sha256:abc123")
377392
"/v2/myrepo/blobs/sha256:abc123"
378393
"""
379-
@spec blobs_digest_path(String.t(), String.t()) :: String.t()
394+
@spec blobs_digest_path(repo_t(), digest_t()) :: String.t()
380395
def blobs_digest_path(repo, digest) do
381396
"/#{api_version()}/#{repo}/blobs/#{digest}"
382397
end
@@ -395,7 +410,7 @@ defmodule OCI.Registry do
395410
iex> OCI.Registry.manifests_reference_path("library/alpine", "sha256:24dda0a1be6293020e5355d4a09b9a8bb72a8b44c27b0ca8560669b8ed52d3ec")
396411
"/v2/library/alpine/manifests/sha256:24dda0a1be6293020e5355d4a09b9a8bb72a8b44c27b0ca8560669b8ed52d3ec"
397412
"""
398-
@spec manifests_reference_path(String.t(), String.t()) :: String.t()
413+
@spec manifests_reference_path(repo_t(), reference_t()) :: String.t()
399414
def manifests_reference_path(repo, reference) do
400415
"/#{api_version()}/#{repo}/manifests/#{reference}"
401416
end
@@ -411,7 +426,7 @@ defmodule OCI.Registry do
411426
iex> OCI.Registry.blobs_uploads_path("myrepo", "123e4567-e89b-12d3-a456-426614174000")
412427
"/v2/myrepo/blobs/uploads/123e4567-e89b-12d3-a456-426614174000"
413428
"""
414-
@spec blobs_uploads_path(String.t(), String.t()) :: String.t()
429+
@spec blobs_uploads_path(repo_t(), uuid_t()) :: String.t()
415430
def blobs_uploads_path(repo, uuid) do
416431
"/#{api_version()}/#{repo}/blobs/uploads/#{uuid}"
417432
end

lib/oci/storage/adapter.ex

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ defmodule OCI.Storage.Adapter do
3535
```
3636
"""
3737

38+
alias OCI.Registry
39+
3840
@type t :: struct()
3941

4042
@type error_details_t :: any()
@@ -44,8 +46,8 @@ defmodule OCI.Storage.Adapter do
4446
"""
4547
@callback blob_exists?(
4648
storage :: t(),
47-
repo :: String.t(),
48-
digest :: String.t(),
49+
repo :: Registry.repo_t(),
50+
digest :: Registry.digest_t(),
4951
ctx :: OCI.Context.t()
5052
) ::
5153
boolean()
@@ -55,8 +57,8 @@ defmodule OCI.Storage.Adapter do
5557
"""
5658
@callback cancel_blob_upload(
5759
storage :: t(),
58-
repo :: String.t(),
59-
uuid :: String.t(),
60+
repo :: Registry.repo_t(),
61+
uuid :: Registry.uuid_t(),
6062
ctx :: OCI.Context.t()
6163
) ::
6264
:ok
@@ -68,9 +70,9 @@ defmodule OCI.Storage.Adapter do
6870
"""
6971
@callback complete_blob_upload(
7072
storage :: t(),
71-
repo :: String.t(),
72-
upload_id :: String.t(),
73-
digest :: String.t(),
73+
repo :: Registry.repo_t(),
74+
upload_id :: Registry.uuid_t(),
75+
digest :: Registry.digest_t(),
7476
ctx :: OCI.Context.t()
7577
) ::
7678
:ok | {:error, atom()} | {:error, atom(), error_details_t}
@@ -80,8 +82,8 @@ defmodule OCI.Storage.Adapter do
8082
"""
8183
@callback delete_blob(
8284
storage :: t(),
83-
repo :: String.t(),
84-
digest :: String.t(),
85+
repo :: Registry.repo_t(),
86+
digest :: Registry.digest_t(),
8587
ctx :: OCI.Context.t()
8688
) ::
8789
:ok | {:error, :BLOB_UNKNOWN} | {:error, :BLOB_UNKNOWN, error_details_t}
@@ -91,8 +93,8 @@ defmodule OCI.Storage.Adapter do
9193
"""
9294
@callback delete_manifest(
9395
storage :: t(),
94-
repo :: String.t(),
95-
reference :: String.t(),
96+
repo :: Registry.repo_t(),
97+
reference :: Registry.reference_t(),
9698
ctx :: OCI.Context.t()
9799
) ::
98100
:ok | {:error, atom()}
@@ -102,8 +104,8 @@ defmodule OCI.Storage.Adapter do
102104
"""
103105
@callback get_blob(
104106
storage :: t(),
105-
repo :: String.t(),
106-
digest :: String.t(),
107+
repo :: Registry.repo_t(),
108+
digest :: Registry.digest_t(),
107109
ctx :: OCI.Context.t()
108110
) ::
109111
{:ok, content :: binary()}
@@ -115,8 +117,8 @@ defmodule OCI.Storage.Adapter do
115117
"""
116118
@callback get_manifest(
117119
storage :: t(),
118-
repo :: String.t(),
119-
reference :: String.t(),
120+
repo :: Registry.repo_t(),
121+
reference :: Registry.reference_t(),
120122
ctx :: OCI.Context.t()
121123
) ::
122124
{:ok, manifest :: binary(), content_type :: String.t()}
@@ -127,8 +129,8 @@ defmodule OCI.Storage.Adapter do
127129
"""
128130
@callback get_blob_upload_status(
129131
storage :: t(),
130-
repo :: String.t(),
131-
uuid :: String.t(),
132+
repo :: Registry.repo_t(),
133+
uuid :: Registry.uuid_t(),
132134
ctx :: OCI.Context.t()
133135
) ::
134136
{:ok, range :: String.t()} | {:error, term()} | {:error, term(), error_details_t}
@@ -138,8 +140,8 @@ defmodule OCI.Storage.Adapter do
138140
"""
139141
@callback get_blob_upload_offset(
140142
storage :: t(),
141-
repo :: String.t(),
142-
uuid :: String.t(),
143+
repo :: Registry.repo_t(),
144+
uuid :: Registry.uuid_t(),
143145
ctx :: OCI.Context.t()
144146
) ::
145147
{:ok, size :: non_neg_integer()}
@@ -151,8 +153,8 @@ defmodule OCI.Storage.Adapter do
151153
"""
152154
@callback manifest_exists?(
153155
storage :: t(),
154-
repo :: String.t(),
155-
reference :: String.t(),
156+
repo :: Registry.repo_t(),
157+
reference :: Registry.reference_t(),
156158
ctx :: OCI.Context.t()
157159
) ::
158160
boolean()
@@ -166,8 +168,8 @@ defmodule OCI.Storage.Adapter do
166168
@doc """
167169
Initiates a blob upload session.
168170
"""
169-
@callback initiate_blob_upload(storage :: t(), repo :: String.t(), ctx :: OCI.Context.t()) ::
170-
{:ok, upload_id :: String.t()}
171+
@callback initiate_blob_upload(storage :: t(), repo :: Registry.repo_t(), ctx :: OCI.Context.t()) ::
172+
{:ok, upload_id :: Registry.uuid_t()}
171173
| {:error, term()}
172174
| {:error, term(), error_details_t}
173175

@@ -176,11 +178,11 @@ defmodule OCI.Storage.Adapter do
176178
"""
177179
@callback list_tags(
178180
storage :: t(),
179-
repo :: String.t(),
181+
repo :: Registry.repo_t(),
180182
pagination :: OCI.Pagination.t(),
181183
ctx :: OCI.Context.t()
182184
) ::
183-
{:ok, tags :: [String.t()]}
185+
{:ok, tags :: [Registry.tag_t()]}
184186
| {:error, :NAME_UNKNOWN}
185187
| {:error, :NAME_UNKNOWN, error_details_t}
186188

@@ -189,9 +191,9 @@ defmodule OCI.Storage.Adapter do
189191
"""
190192
@callback mount_blob(
191193
storage :: t(),
192-
repo :: String.t(),
193-
digest :: String.t(),
194-
from_repo :: String.t(),
194+
repo :: Registry.repo_t(),
195+
digest :: Registry.digest_t(),
196+
from_repo :: Registry.repo_t(),
195197
ctx :: OCI.Context.t()
196198
) ::
197199
:ok | {:error, :BLOB_UNKNOWN} | {:error, :BLOB_UNKNOWN, error_details_t}
@@ -201,10 +203,10 @@ defmodule OCI.Storage.Adapter do
201203
"""
202204
@callback store_manifest(
203205
storage :: t(),
204-
repo :: String.t(),
205-
reference :: String.t(),
206+
repo :: Registry.repo_t(),
207+
reference :: Registry.reference_t(),
206208
manifest :: map(),
207-
manifest_digest :: String.t(),
209+
manifest_digest :: Registry.digest_t(),
208210
ctx :: OCI.Context.t()
209211
) ::
210212
:ok
@@ -214,15 +216,16 @@ defmodule OCI.Storage.Adapter do
214216
@doc """
215217
Checks if a repository exists.
216218
"""
217-
@callback repo_exists?(storage :: t(), repo :: String.t(), ctx :: OCI.Context.t()) :: boolean()
219+
@callback repo_exists?(storage :: t(), repo :: Registry.repo_t(), ctx :: OCI.Context.t()) ::
220+
boolean()
218221

219222
@doc """
220223
Uploads a chunk of data to an ongoing blob upload.
221224
"""
222225
@callback upload_blob_chunk(
223226
storage :: t(),
224-
repo :: String.t(),
225-
uuid :: String.t(),
227+
repo :: Registry.repo_t(),
228+
uuid :: Registry.uuid_t(),
226229
chunk :: binary(),
227230
content_range :: String.t(),
228231
ctx :: OCI.Context.t()
@@ -239,8 +242,8 @@ defmodule OCI.Storage.Adapter do
239242
"""
240243
@callback list_referrers(
241244
storage :: t(),
242-
repo :: String.t(),
243-
subject_digest :: String.t(),
245+
repo :: Registry.repo_t(),
246+
subject_digest :: Registry.digest_t(),
244247
filters :: map(),
245248
ctx :: OCI.Context.t()
246249
) ::
@@ -251,8 +254,8 @@ defmodule OCI.Storage.Adapter do
251254
"""
252255
@callback put_referrer(
253256
storage :: t(),
254-
repo :: String.t(),
255-
subject_digest :: String.t(),
257+
repo :: Registry.repo_t(),
258+
subject_digest :: Registry.digest_t(),
256259
descriptor :: map(),
257260
ctx :: OCI.Context.t()
258261
) ::
@@ -263,8 +266,8 @@ defmodule OCI.Storage.Adapter do
263266
"""
264267
@callback upload_exists?(
265268
storage :: t(),
266-
repo :: String.t(),
267-
uuid :: String.t(),
269+
repo :: Registry.repo_t(),
270+
uuid :: Registry.uuid_t(),
268271
ctx :: OCI.Context.t()
269272
) ::
270273
boolean()

0 commit comments

Comments
 (0)