fix --format {{json .}} output to match docker

`--format json` should not be the same as `--format {{json .}}`, the
later should actually run through the go template and thus create one
json object per entry instead of an json array.

Includes a vendor of c/common@main since it requires a fix from there as
well.

This matches docker compat.
Fixes #16436

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2022-11-08 14:28:33 +01:00
parent 919678d2f8
commit 3e08f85353
26 changed files with 433 additions and 118 deletions

View File

@ -10,6 +10,7 @@ import (
"net/url"
"os"
"os/user"
"path"
"path/filepath"
"regexp"
"strings"
@ -289,11 +290,24 @@ func ValidateAndConfigure(uri *url.URL, iden string, insecureIsMachineConnection
keyFilePath := filepath.Join(homedir.Get(), ".ssh", "known_hosts")
known, err := knownhosts.New(keyFilePath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
logrus.Warn("please create a known_hosts file. The next time this host is connected to, podman will add it to known_hosts")
return nil
if !errors.Is(err, os.ErrNotExist) {
return err
}
keyDir := path.Dir(keyFilePath)
if _, err := os.Stat(keyDir); errors.Is(err, os.ErrNotExist) {
if err := os.Mkdir(keyDir, 0o700); err != nil {
return err
}
}
k, err := os.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
return err
}
k.Close()
known, err = knownhosts.New(keyFilePath)
if err != nil {
return err
}
return err
}
// we need to check if there is an error from reading known hosts for this public key and if there is an error, what is it, and why is it happening?
// if it is a key mismatch we want to error since we know the host using another key