mirror of
https://github.com/containers/podman.git
synced 2025-08-16 20:53:13 +08:00

* Support the `X-Registry-Auth` http-request header. * The content of the header is a base64 encoded JSON payload which can either be a single auth config or a map of auth configs (user+pw or token) with the corresponding registries being the keys. Vanilla Docker, projectatomic Docker and the bindings are transparantly supported. * Add a hidden `--registries-conf` flag. Buildah exposes the same flag, mostly for testing purposes. * Do all credential parsing in the client (i.e., `cmd/podman`) pass the username and password in the backend instead of unparsed credentials. * Add a `pkg/auth` which handles most of the heavy lifting. * Go through the authentication-handling code of most commands, bindings and endpoints. Migrate them to the new code and fix issues as seen. A final evaluation and more tests is still required *after* this change. * The manifest-push endpoint is missing certain parameters and should use the ABI function instead. Adding auth-support isn't really possible without these parts working. * The container commands and endpoints (i.e., create and run) have not been changed yet. The APIs don't yet account for the authfile. * Add authentication tests to `pkg/bindings`. Fixes: #6384 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package containers
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"github.com/containers/libpod/pkg/bindings"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Logs obtains a container's logs given the options provided. The logs are then sent to the
|
|
// stdout|stderr channels as strings.
|
|
func Logs(ctx context.Context, nameOrID string, opts LogOptions, stdoutChan, stderrChan chan string) error {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
params := url.Values{}
|
|
if opts.Follow != nil {
|
|
params.Set("follow", strconv.FormatBool(*opts.Follow))
|
|
}
|
|
if opts.Since != nil {
|
|
params.Set("since", *opts.Since)
|
|
}
|
|
if opts.Stderr != nil {
|
|
params.Set("stderr", strconv.FormatBool(*opts.Stderr))
|
|
}
|
|
if opts.Stdout != nil {
|
|
params.Set("stdout", strconv.FormatBool(*opts.Stdout))
|
|
}
|
|
if opts.Tail != nil {
|
|
params.Set("tail", *opts.Tail)
|
|
}
|
|
if opts.Timestamps != nil {
|
|
params.Set("timestamps", strconv.FormatBool(*opts.Timestamps))
|
|
}
|
|
if opts.Until != nil {
|
|
params.Set("until", *opts.Until)
|
|
}
|
|
// The API requires either stdout|stderr be used. If neither are specified, we specify stdout
|
|
if opts.Stdout == nil && opts.Stderr == nil {
|
|
params.Set("stdout", strconv.FormatBool(true))
|
|
}
|
|
response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/logs", params, nil, nameOrID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
buffer := make([]byte, 1024)
|
|
for {
|
|
fd, l, err := DemuxHeader(response.Body, buffer)
|
|
if err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
frame, err := DemuxFrame(response.Body, buffer, l)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
frame = bytes.Replace(frame[0:l], []byte{13}, []byte{10}, -1)
|
|
|
|
switch fd {
|
|
case 0:
|
|
stdoutChan <- string(frame)
|
|
case 1:
|
|
stdoutChan <- string(frame)
|
|
case 2:
|
|
stderrChan <- string(frame)
|
|
case 3:
|
|
return errors.New("error from service in stream: " + string(frame))
|
|
default:
|
|
return fmt.Errorf("unrecognized input header: %d", fd)
|
|
}
|
|
}
|
|
}
|