From 3b5e81424229d30069d910729939df01e9b974b0 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Feb 2024 13:26:54 +0100 Subject: [PATCH] cli-plugins/socket: remove use of deprecated distribution uuid package The "github.com/docker/distribution" module moved to the distribution org ("github.com/docker/distribution/v3"), and the new module deprecated and removed the uuid package in favor of Google's UUID package. While we still depend on the old module through packages and as an indirect dependency, we may want to try avoid using it. This patch replaces the use for the socket package, and replaces it for a local utility, taking the same approach as `stringid.GenerateRandomID()`, which should be random enough for this purpose. Signed-off-by: Sebastiaan van Stijn --- cli-plugins/socket/socket.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cli-plugins/socket/socket.go b/cli-plugins/socket/socket.go index 93d7a87b28..67ba11562e 100644 --- a/cli-plugins/socket/socket.go +++ b/cli-plugins/socket/socket.go @@ -1,12 +1,12 @@ package socket import ( + "crypto/rand" + "encoding/hex" "errors" "io" "net" "os" - - "github.com/docker/distribution/uuid" ) // EnvKey represents the well-known environment variable used to pass the plugin being @@ -17,7 +17,7 @@ const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET" // and update the conn pointer, and returns the listener for the socket (which the caller // is responsible for closing when it's no longer needed). func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) { - listener, err := listen("docker_cli_" + uuid.Generate().String()) + listener, err := listen("docker_cli_" + randomID()) if err != nil { return nil, err } @@ -27,6 +27,14 @@ func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) { return listener, nil } +func randomID() string { + b := make([]byte, 16) + if _, err := rand.Read(b); err != nil { + panic(err) // This shouldn't happen + } + return hex.EncodeToString(b) +} + func accept(listener *net.UnixListener, conn **net.UnixConn) { go func() { for {