Skip to content

Commit

Permalink
dont send auth header if nil and remove push_image from api
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Nov 16, 2024
1 parent 79b5ed2 commit d891b8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 44 deletions.
41 changes: 0 additions & 41 deletions docker_engine_api/api/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -533,47 +533,6 @@ defmodule DockerEngineAPI.Api.Image do
])
end

@doc """
Push an image
Push an image to a registry. If you wish to push an image on to a private registry, that image must already have a tag which references the registry. For example, `registry.example.com/myimage:latest`. The push is cancelled if the HTTP connection is closed.
### Parameters
- `connection` (DockerEngineAPI.Connection): Connection to server
- `name` (String.t): Image name or ID.
- `x_registry_auth` (String.t): A base64url-encoded auth configuration. Refer to the [authentication section](#section/Authentication) for details.
- `opts` (keyword): Optional parameters
- `:tag` (String.t): The tag to associate with the image on the registry.
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec image_push(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, DockerEngineAPI.Model.ErrorResponse.t} | {:error, Tesla.Env.t}
def image_push(connection, name, x_registry_auth, opts \\ []) do
optional_params = %{
:tag => :query
}

request =
%{}
|> method(:post)
|> url("/images/#{name}/push")
|> add_param(:headers, :"X-Registry-Auth", x_registry_auth)
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])

connection
|> Connection.request(request)
|> evaluate_response([
{200, false},
{404, DockerEngineAPI.Model.ErrorResponse},
{500, DockerEngineAPI.Model.ErrorResponse}
])
end

@doc """
Search images
Search for an image on Docker Hub.
Expand Down
7 changes: 4 additions & 3 deletions lib/docker/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ defmodule Testcontainers.Docker.Api do

def pull_image(image, conn, opts \\ []) when is_binary(image) do
auth = Keyword.get(opts, :auth, nil)
headers = if auth, do: ["X-Registry-Auth": auth], else: []

case Api.Image.image_create(conn,
fromImage: image,
"X-Registry-Auth": auth
case Api.Image.image_create(
conn,
Keyword.merge([fromImage: image], headers)
) do
{:ok, %Tesla.Env{status: 200}} ->
{:ok, nil}
Expand Down

0 comments on commit d891b8e

Please sign in to comment.