Skip to content

Commit 3b5e814

Browse files
committed
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 <[email protected]>
1 parent a253318 commit 3b5e814

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cli-plugins/socket/socket.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package socket
22

33
import (
4+
"crypto/rand"
5+
"encoding/hex"
46
"errors"
57
"io"
68
"net"
79
"os"
8-
9-
"github.com/docker/distribution/uuid"
1010
)
1111

1212
// EnvKey represents the well-known environment variable used to pass the plugin being
@@ -17,7 +17,7 @@ const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET"
1717
// and update the conn pointer, and returns the listener for the socket (which the caller
1818
// is responsible for closing when it's no longer needed).
1919
func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
20-
listener, err := listen("docker_cli_" + uuid.Generate().String())
20+
listener, err := listen("docker_cli_" + randomID())
2121
if err != nil {
2222
return nil, err
2323
}
@@ -27,6 +27,14 @@ func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
2727
return listener, nil
2828
}
2929

30+
func randomID() string {
31+
b := make([]byte, 16)
32+
if _, err := rand.Read(b); err != nil {
33+
panic(err) // This shouldn't happen
34+
}
35+
return hex.EncodeToString(b)
36+
}
37+
3038
func accept(listener *net.UnixListener, conn **net.UnixConn) {
3139
go func() {
3240
for {

0 commit comments

Comments
 (0)