mirror of https://github.com/docker/cli.git
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 <github@gone.nl>
This commit is contained in:
parent
a253318869
commit
3b5e814242
|
@ -1,12 +1,12 @@
|
||||||
package socket
|
package socket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/distribution/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnvKey represents the well-known environment variable used to pass the plugin being
|
// 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
|
// 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).
|
// is responsible for closing when it's no longer needed).
|
||||||
func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,14 @@ func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
|
||||||
return listener, nil
|
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) {
|
func accept(listener *net.UnixListener, conn **net.UnixConn) {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in New Issue