mirror of https://github.com/containers/podman.git
Use request Context() in API handlers
Request object has its own context which must be used during a request lifetime instead of just context.Background() [NO NEW TESTS NEEDED] Signed-off-by: Vladimir Kochnev <hashtable@yandex.ru>
This commit is contained in:
parent
b9fb60c68a
commit
e48681e600
|
@ -1,7 +1,6 @@
|
||||||
package compat
|
package compat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -44,7 +43,7 @@ func Auth(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
fmt.Println("Authenticating with existing credentials...")
|
fmt.Println("Authenticating with existing credentials...")
|
||||||
registry := stripAddressOfScheme(authConfig.ServerAddress)
|
registry := stripAddressOfScheme(authConfig.ServerAddress)
|
||||||
if err := DockerClient.CheckAuth(context.Background(), sysCtx, authConfig.Username, authConfig.Password, registry); err == nil {
|
if err := DockerClient.CheckAuth(r.Context(), sysCtx, authConfig.Username, authConfig.Password, registry); err == nil {
|
||||||
utils.WriteResponse(w, http.StatusOK, entities.AuthReport{
|
utils.WriteResponse(w, http.StatusOK, entities.AuthReport{
|
||||||
IdentityToken: "",
|
IdentityToken: "",
|
||||||
Status: "Login Succeeded",
|
Status: "Login Succeeded",
|
||||||
|
|
|
@ -694,7 +694,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||||
success bool
|
success bool
|
||||||
)
|
)
|
||||||
|
|
||||||
runCtx, cancel := context.WithCancel(context.Background())
|
runCtx, cancel := context.WithCancel(r.Context())
|
||||||
go func() {
|
go func() {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
imageID, _, err = runtime.Build(r.Context(), buildOptions, containerFiles...)
|
imageID, _, err = runtime.Build(r.Context(), buildOptions, containerFiles...)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -63,12 +62,12 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rtSpec, spec, opts, err := generate.MakeContainer(context.Background(), runtime, &sg, false, nil)
|
rtSpec, spec, opts, err := generate.MakeContainer(r.Context(), runtime, &sg, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctr, err := generate.ExecuteCreate(context.Background(), runtime, rtSpec, spec, false, opts...)
|
ctr, err := generate.ExecuteCreate(r.Context(), runtime, rtSpec, spec, false, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -90,7 +90,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Let's keep thing simple when running in quiet mode and push directly.
|
// Let's keep thing simple when running in quiet mode and push directly.
|
||||||
if query.Quiet {
|
if query.Quiet {
|
||||||
if err := imageEngine.Push(context.Background(), source, destination, options); err != nil {
|
if err := imageEngine.Push(r.Context(), source, destination, options); err != nil {
|
||||||
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", destination, err))
|
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", destination, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ func ManifestPushV3(w http.ResponseWriter, r *http.Request) {
|
||||||
options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)
|
options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)
|
||||||
}
|
}
|
||||||
imageEngine := abi.ImageEngine{Libpod: runtime}
|
imageEngine := abi.ImageEngine{Libpod: runtime}
|
||||||
digest, err := imageEngine.ManifestPush(context.Background(), source, query.Destination, options)
|
digest, err := imageEngine.ManifestPush(r.Context(), source, query.Destination, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", query.Destination, err))
|
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", query.Destination, err))
|
||||||
return
|
return
|
||||||
|
@ -367,7 +367,7 @@ func ManifestPush(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Let's keep thing simple when running in quiet mode and push directly.
|
// Let's keep thing simple when running in quiet mode and push directly.
|
||||||
if query.Quiet {
|
if query.Quiet {
|
||||||
digest, err := imageEngine.ManifestPush(context.Background(), source, destination, options)
|
digest, err := imageEngine.ManifestPush(r.Context(), source, destination, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", destination, err))
|
utils.Error(w, http.StatusBadRequest, fmt.Errorf("error pushing image %q: %w", destination, err))
|
||||||
return
|
return
|
||||||
|
|
|
@ -162,7 +162,7 @@ type ExecStartConfig struct {
|
||||||
|
|
||||||
func ImageDataToImageInspect(ctx context.Context, l *libimage.Image) (*ImageInspect, error) {
|
func ImageDataToImageInspect(ctx context.Context, l *libimage.Image) (*ImageInspect, error) {
|
||||||
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
|
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
|
||||||
info, err := l.Inspect(context.Background(), options)
|
info, err := l.Inspect(ctx, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue