mirror of
https://github.com/containers/skopeo.git
synced 2025-09-19 17:15:32 +00:00
fix(deps): update module github.com/containers/common to v0.56.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
8
vendor/github.com/containers/common/pkg/auth/auth.go
generated
vendored
8
vendor/github.com/containers/common/pkg/auth/auth.go
generated
vendored
@@ -10,13 +10,13 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/util"
|
||||
"github.com/containers/image/v5/docker"
|
||||
"github.com/containers/image/v5/docker/reference"
|
||||
"github.com/containers/image/v5/pkg/docker/config"
|
||||
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
|
||||
// ErrNewCredentialsInvalid means that the new user-provided credentials are
|
||||
@@ -259,7 +259,7 @@ func getUserAndPass(opts *LoginOptions, password, userFromAuthFile string) (user
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("reading username: %w", err)
|
||||
}
|
||||
// If the user just hit enter, use the displayed user from the
|
||||
// If the user just hit enter, use the displayed user from
|
||||
// the authentication file. This allows to do a lazy
|
||||
// `$ buildah login -p $NEW_PASSWORD` without specifying the
|
||||
// user.
|
||||
@@ -269,7 +269,7 @@ func getUserAndPass(opts *LoginOptions, password, userFromAuthFile string) (user
|
||||
}
|
||||
if password == "" {
|
||||
fmt.Fprint(opts.Stdout, "Password: ")
|
||||
pass, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
pass, err := util.ReadPassword(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("reading password: %w", err)
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func Logout(systemContext *types.SystemContext, opts *LogoutOptions, args []stri
|
||||
|
||||
authInvalid := docker.CheckAuth(context.Background(), systemContext, authConfig.Username, authConfig.Password, registry)
|
||||
if authConfig.Username != "" && authConfig.Password != "" && authInvalid == nil {
|
||||
fmt.Printf("Not logged into %s with current tool. Existing credentials were established via docker login. Please use docker logout instead.\n", key)
|
||||
fmt.Printf("Not logged into %s with current tool. Existing credentials were established via docker login. Please use docker logout instead.\n", key) //nolint:forbidigo
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("not logged into %s", key)
|
||||
|
2
vendor/github.com/containers/common/pkg/flag/flag.go
generated
vendored
2
vendor/github.com/containers/common/pkg/flag/flag.go
generated
vendored
@@ -165,7 +165,7 @@ func (ob *optionalIntValue) String() string {
|
||||
if !ob.present {
|
||||
return "" // If the value is not present, just return an empty string, any other value wouldn't make sense.
|
||||
}
|
||||
return strconv.Itoa(int(ob.value))
|
||||
return strconv.Itoa(ob.value)
|
||||
}
|
||||
|
||||
// Type returns the int's type.
|
||||
|
3
vendor/github.com/containers/common/pkg/report/camelcase/camelcase.go
generated
vendored
3
vendor/github.com/containers/common/pkg/report/camelcase/camelcase.go
generated
vendored
@@ -51,8 +51,7 @@ func Split(src string) (entries []string) {
|
||||
}
|
||||
entries = []string{}
|
||||
var runes [][]rune
|
||||
lastClass := 0
|
||||
class := 0
|
||||
var class, lastClass int
|
||||
// split into fields based on class of unicode character
|
||||
for _, r := range src {
|
||||
switch {
|
||||
|
1
vendor/github.com/containers/common/pkg/retry/retry.go
generated
vendored
1
vendor/github.com/containers/common/pkg/retry/retry.go
generated
vendored
@@ -74,7 +74,6 @@ func IsErrorRetryable(err error) bool {
|
||||
}
|
||||
|
||||
switch e := err.(type) {
|
||||
|
||||
case errcode.Error:
|
||||
switch e.Code {
|
||||
case errcode.ErrorCodeUnauthorized, errcode.ErrorCodeDenied,
|
||||
|
57
vendor/github.com/containers/common/pkg/util/copy.go
generated
vendored
Normal file
57
vendor/github.com/containers/common/pkg/util/copy.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
// ErrDetach indicates that an attach session was manually detached by
|
||||
// the user.
|
||||
var ErrDetach = errors.New("detached from container")
|
||||
|
||||
// CopyDetachable is similar to io.Copy but support a detach key sequence to break out.
|
||||
func CopyDetachable(dst io.Writer, src io.Reader, keys []byte) (written int64, err error) {
|
||||
buf := make([]byte, 32*1024)
|
||||
for {
|
||||
nr, er := src.Read(buf)
|
||||
if nr > 0 {
|
||||
preservBuf := []byte{}
|
||||
for i, key := range keys {
|
||||
preservBuf = append(preservBuf, buf[0:nr]...)
|
||||
if nr != 1 || buf[0] != key {
|
||||
break
|
||||
}
|
||||
if i == len(keys)-1 {
|
||||
return 0, ErrDetach
|
||||
}
|
||||
nr, er = src.Read(buf)
|
||||
}
|
||||
var nw int
|
||||
var ew error
|
||||
if len(preservBuf) > 0 {
|
||||
nw, ew = dst.Write(preservBuf)
|
||||
nr = len(preservBuf)
|
||||
} else {
|
||||
nw, ew = dst.Write(buf[0:nr])
|
||||
}
|
||||
if nw > 0 {
|
||||
written += int64(nw)
|
||||
}
|
||||
if ew != nil {
|
||||
err = ew
|
||||
break
|
||||
}
|
||||
if nr != nw {
|
||||
err = io.ErrShortWrite
|
||||
break
|
||||
}
|
||||
}
|
||||
if er != nil {
|
||||
if er != io.EOF {
|
||||
err = er
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return written, err
|
||||
}
|
206
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
Normal file
206
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
UnknownPackage = "Unknown"
|
||||
)
|
||||
|
||||
var ErrInterrupt = errors.New("interrupted")
|
||||
|
||||
// Note: This function is copied from containers/podman libpod/util.go
|
||||
// Please see https://github.com/containers/common/pull/1460
|
||||
func queryPackageVersion(cmdArg ...string) string {
|
||||
output := UnknownPackage
|
||||
if 1 < len(cmdArg) {
|
||||
cmd := exec.Command(cmdArg[0], cmdArg[1:]...)
|
||||
if outp, err := cmd.Output(); err == nil {
|
||||
output = string(outp)
|
||||
deb := false
|
||||
if cmdArg[0] == "/usr/bin/dlocate" {
|
||||
// can return multiple matches
|
||||
l := strings.Split(output, "\n")
|
||||
output = l[0]
|
||||
deb = true
|
||||
} else if cmdArg[0] == "/usr/bin/dpkg" {
|
||||
deb = true
|
||||
}
|
||||
if deb {
|
||||
r := strings.Split(output, ": ")
|
||||
queryFormat := `${Package}_${Version}_${Architecture}`
|
||||
cmd = exec.Command("/usr/bin/dpkg-query", "-f", queryFormat, "-W", r[0])
|
||||
if outp, err := cmd.Output(); err == nil {
|
||||
output = string(outp)
|
||||
}
|
||||
}
|
||||
}
|
||||
if cmdArg[0] == "/sbin/apk" {
|
||||
prefix := cmdArg[len(cmdArg)-1] + " is owned by "
|
||||
output = strings.Replace(output, prefix, "", 1)
|
||||
}
|
||||
}
|
||||
return strings.Trim(output, "\n")
|
||||
}
|
||||
|
||||
// Note: This function is copied from containers/podman libpod/util.go
|
||||
// Please see https://github.com/containers/common/pull/1460
|
||||
func PackageVersion(program string) string { // program is full path
|
||||
_, err := os.Stat(program)
|
||||
if err != nil {
|
||||
return UnknownPackage
|
||||
}
|
||||
packagers := [][]string{
|
||||
{"/usr/bin/rpm", "-q", "-f"},
|
||||
{"/usr/bin/dlocate", "-F"}, // Debian, Ubuntu (quick)
|
||||
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu (slow)
|
||||
{"/usr/bin/pacman", "-Qo"}, // Arch
|
||||
{"/usr/bin/qfile", "-qv"}, // Gentoo (quick)
|
||||
{"/usr/bin/equery", "b"}, // Gentoo (slow)
|
||||
{"/sbin/apk", "info", "-W"}, // Alpine
|
||||
{"/usr/local/sbin/pkg", "which", "-q"}, // FreeBSD
|
||||
}
|
||||
|
||||
for _, cmd := range packagers {
|
||||
cmd = append(cmd, program)
|
||||
if out := queryPackageVersion(cmd...); out != UnknownPackage {
|
||||
return out
|
||||
}
|
||||
}
|
||||
return UnknownPackage
|
||||
}
|
||||
|
||||
// Note: This function is copied from containers/podman libpod/util.go
|
||||
// Please see https://github.com/containers/common/pull/1460
|
||||
func ProgramVersion(program string) (string, error) {
|
||||
return programVersion(program, false)
|
||||
}
|
||||
|
||||
func ProgramVersionDnsname(program string) (string, error) {
|
||||
return programVersion(program, true)
|
||||
}
|
||||
|
||||
func programVersion(program string, dnsname bool) (string, error) {
|
||||
cmd := exec.Command(program, "--version")
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("`%v --version` failed: %v %v (%v)", program, stderr.String(), stdout.String(), err)
|
||||
}
|
||||
|
||||
output := strings.TrimSuffix(stdout.String(), "\n")
|
||||
// dnsname --version returns the information to stderr
|
||||
if dnsname {
|
||||
output = strings.TrimSuffix(stderr.String(), "\n")
|
||||
}
|
||||
|
||||
return output, nil
|
||||
}
|
||||
|
||||
// StringInSlice determines if a string is in a string slice, returns bool
|
||||
func StringInSlice(s string, sl []string) bool {
|
||||
for _, i := range sl {
|
||||
if i == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// StringMatchRegexSlice determines if a given string matches one of the given regexes, returns bool
|
||||
func StringMatchRegexSlice(s string, re []string) bool {
|
||||
for _, r := range re {
|
||||
m, err := regexp.MatchString(r, s)
|
||||
if err == nil && m {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FilterID is a function used to compare an id against a set of ids, if the
|
||||
// input is hex we check if the prefix matches. Otherwise we assume it is a
|
||||
// regex and try to match that.
|
||||
// see https://github.com/containers/podman/issues/18471 for why we do this
|
||||
func FilterID(id string, filters []string) bool {
|
||||
for _, want := range filters {
|
||||
isRegex := types.NotHexRegex.MatchString(want)
|
||||
if isRegex {
|
||||
match, err := regexp.MatchString(want, id)
|
||||
if err == nil && match {
|
||||
return true
|
||||
}
|
||||
} else if strings.HasPrefix(id, strings.ToLower(want)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// WaitForFile waits until a file has been created or the given timeout has occurred
|
||||
func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, error) {
|
||||
var inotifyEvents chan fsnotify.Event
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err == nil {
|
||||
if err := watcher.Add(filepath.Dir(path)); err == nil {
|
||||
inotifyEvents = watcher.Events
|
||||
}
|
||||
defer func() {
|
||||
if err := watcher.Close(); err != nil {
|
||||
logrus.Errorf("Failed to close fsnotify watcher: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
var timeoutChan <-chan time.Time
|
||||
|
||||
if timeout != 0 {
|
||||
timeoutChan = time.After(timeout)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case e := <-chWait:
|
||||
return true, e
|
||||
case <-inotifyEvents:
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return false, nil
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
return false, err
|
||||
}
|
||||
case <-time.After(25 * time.Millisecond):
|
||||
// Check periodically for the file existence. It is needed
|
||||
// if the inotify watcher could not have been created. It is
|
||||
// also useful when using inotify as if for any reasons we missed
|
||||
// a notification, we won't hang the process.
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return false, nil
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
return false, err
|
||||
}
|
||||
case <-timeoutChan:
|
||||
return false, fmt.Errorf("timed out waiting for file %s", path)
|
||||
}
|
||||
}
|
||||
}
|
135
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
Normal file
135
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
//go:build linux || darwin || freebsd
|
||||
// +build linux darwin freebsd
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/containers/storage/pkg/homedir"
|
||||
"github.com/containers/storage/pkg/unshare"
|
||||
"github.com/sirupsen/logrus"
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
|
||||
var (
|
||||
rootlessRuntimeDirOnce sync.Once
|
||||
rootlessRuntimeDir string
|
||||
)
|
||||
|
||||
// isWriteableOnlyByOwner checks that the specified permission mask allows write
|
||||
// access only to the owner.
|
||||
func isWriteableOnlyByOwner(perm os.FileMode) bool {
|
||||
return (perm & 0o722) == 0o700
|
||||
}
|
||||
|
||||
// GetRuntimeDir returns the runtime directory
|
||||
func GetRuntimeDir() (string, error) {
|
||||
var rootlessRuntimeDirError error
|
||||
|
||||
rootlessRuntimeDirOnce.Do(func() {
|
||||
runtimeDir, err := homedir.GetRuntimeDir()
|
||||
if err != nil {
|
||||
logrus.Debug(err)
|
||||
}
|
||||
if runtimeDir != "" {
|
||||
st, err := os.Stat(runtimeDir)
|
||||
if err != nil {
|
||||
rootlessRuntimeDirError = err
|
||||
return
|
||||
}
|
||||
if int(st.Sys().(*syscall.Stat_t).Uid) != os.Geteuid() {
|
||||
rootlessRuntimeDirError = fmt.Errorf("XDG_RUNTIME_DIR directory %q is not owned by the current user", runtimeDir)
|
||||
return
|
||||
}
|
||||
}
|
||||
uid := fmt.Sprintf("%d", unshare.GetRootlessUID())
|
||||
if runtimeDir == "" {
|
||||
tmpDir := filepath.Join("/run", "user", uid)
|
||||
if err := os.MkdirAll(tmpDir, 0o700); err != nil {
|
||||
logrus.Debugf("unable to make temp dir: %v", err)
|
||||
}
|
||||
st, err := os.Stat(tmpDir)
|
||||
if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() && isWriteableOnlyByOwner(st.Mode().Perm()) {
|
||||
runtimeDir = tmpDir
|
||||
}
|
||||
}
|
||||
if runtimeDir == "" {
|
||||
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("podman-run-%s", uid))
|
||||
if err := os.MkdirAll(tmpDir, 0o700); err != nil {
|
||||
logrus.Debugf("unable to make temp dir %v", err)
|
||||
}
|
||||
st, err := os.Stat(tmpDir)
|
||||
if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() && isWriteableOnlyByOwner(st.Mode().Perm()) {
|
||||
runtimeDir = tmpDir
|
||||
}
|
||||
}
|
||||
if runtimeDir == "" {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
rootlessRuntimeDirError = errors.New("neither XDG_RUNTIME_DIR nor HOME was set non-empty")
|
||||
return
|
||||
}
|
||||
resolvedHome, err := filepath.EvalSymlinks(home)
|
||||
if err != nil {
|
||||
rootlessRuntimeDirError = fmt.Errorf("cannot resolve home: %w", err)
|
||||
return
|
||||
}
|
||||
runtimeDir = filepath.Join(resolvedHome, "rundir")
|
||||
}
|
||||
rootlessRuntimeDir = runtimeDir
|
||||
})
|
||||
|
||||
if rootlessRuntimeDirError != nil {
|
||||
return "", rootlessRuntimeDirError
|
||||
}
|
||||
return rootlessRuntimeDir, nil
|
||||
}
|
||||
|
||||
// ReadPassword reads a password from the terminal without echo.
|
||||
func ReadPassword(fd int) ([]byte, error) {
|
||||
// Store and restore the terminal status on interruptions to
|
||||
// avoid that the terminal remains in the password state
|
||||
// This is necessary as for https://github.com/golang/go/issues/31180
|
||||
|
||||
oldState, err := terminal.GetState(fd)
|
||||
if err != nil {
|
||||
return make([]byte, 0), err
|
||||
}
|
||||
|
||||
type Buffer struct {
|
||||
Buffer []byte
|
||||
Error error
|
||||
}
|
||||
errorChannel := make(chan Buffer, 1)
|
||||
|
||||
// SIGINT and SIGTERM restore the terminal, otherwise the no-echo mode would remain intact
|
||||
interruptChannel := make(chan os.Signal, 1)
|
||||
signal.Notify(interruptChannel, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer func() {
|
||||
signal.Stop(interruptChannel)
|
||||
close(interruptChannel)
|
||||
}()
|
||||
go func() {
|
||||
for range interruptChannel {
|
||||
if oldState != nil {
|
||||
_ = terminal.Restore(fd, oldState)
|
||||
}
|
||||
errorChannel <- Buffer{Buffer: make([]byte, 0), Error: ErrInterrupt}
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
buf, err := terminal.ReadPassword(fd)
|
||||
errorChannel <- Buffer{Buffer: buf, Error: err}
|
||||
}()
|
||||
|
||||
buf := <-errorChannel
|
||||
return buf.Buffer, buf.Error
|
||||
}
|
28
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
Normal file
28
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
|
||||
// getRuntimeDir returns the runtime directory
|
||||
func GetRuntimeDir() (string, error) {
|
||||
return "", errors.New("this function is not implemented for windows")
|
||||
}
|
||||
|
||||
// ReadPassword reads a password from the terminal.
|
||||
func ReadPassword(fd int) ([]byte, error) {
|
||||
oldState, err := terminal.GetState(fd)
|
||||
if err != nil {
|
||||
return make([]byte, 0), err
|
||||
}
|
||||
buf, err := terminal.ReadPassword(fd)
|
||||
if oldState != nil {
|
||||
_ = terminal.Restore(fd, oldState)
|
||||
}
|
||||
return buf, err
|
||||
}
|
Reference in New Issue
Block a user