From 8d1a12a7f0cd01651a958b0490690b3098cbbebc Mon Sep 17 00:00:00 2001 From: thomas morgan Date: Fri, 4 Dec 2020 17:48:48 -0700 Subject: [PATCH] add authentication arg to Image#distribution --- README.md | 3 ++- lib/docker/api/image.rb | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 421d509..bc5a472 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ image.details("image") # Return image digest and platform information by contacting the registry. image.distribution("image") +image.distribution("image", {username: "janedoe", password: "password"}) # private repository # History image.history("image") @@ -94,7 +95,7 @@ image.tag("current:tag", repo: "new", tag: "tag") # Push image image.push("repo:tag") # to dockerhub image.push("localhost:5000/repo:tag") # to local registry -image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"} # to private repository +image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"}) # to private repository # Remove image image.remove("image") diff --git a/lib/docker/api/image.rb b/lib/docker/api/image.rb index e39bfde..e4ed9d9 100644 --- a/lib/docker/api/image.rb +++ b/lib/docker/api/image.rb @@ -21,8 +21,11 @@ def details name # @see https://docs.docker.com/engine/api/v1.40/#tag/Distribution # # @param name [String]: The ID or name of the image. - def distribution name - @connection.get("/distribution/#{name}/json") + # @param authentication [Hash]: Authentication parameters. + def distribution name, authentication = {} + request = {method: :get, path: "/distribution/#{name}/json"} + request[:headers] = {"X-Registry-Auth" => auth_encoder(authentication)} if authentication.any? + @connection.request(request) end ##