mirror of https://github.com/containers/podman.git
				
				
				
			fix: pull error response docker rest api compatibility
This is related to the issue #20013 Signed-off-by: Gabriel Pozo <jackgris2@gmail.com>
This commit is contained in:
		
							parent
							
								
									8de7c48df5
								
							
						
					
					
						commit
						b9f2c4d171
					
				|  | @ -16,6 +16,7 @@ import ( | ||||||
| 	"github.com/containers/image/v5/types" | 	"github.com/containers/image/v5/types" | ||||||
| 	"github.com/containers/podman/v4/libpod" | 	"github.com/containers/podman/v4/libpod" | ||||||
| 	api "github.com/containers/podman/v4/pkg/api/types" | 	api "github.com/containers/podman/v4/pkg/api/types" | ||||||
|  | 	"github.com/containers/podman/v4/pkg/errorhandling" | ||||||
| 	"github.com/containers/podman/v4/pkg/util" | 	"github.com/containers/podman/v4/pkg/util" | ||||||
| 	"github.com/containers/storage" | 	"github.com/containers/storage" | ||||||
| 	"github.com/docker/distribution/registry/api/errcode" | 	"github.com/docker/distribution/registry/api/errcode" | ||||||
|  | @ -141,6 +142,7 @@ func CompatPull(ctx context.Context, w http.ResponseWriter, runtime *libpod.Runt | ||||||
| 			statusWritten = true | 			statusWritten = true | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	progressSent := false | ||||||
| 
 | 
 | ||||||
| loop: // break out of for/select infinite loop
 | loop: // break out of for/select infinite loop
 | ||||||
| 	for { | 	for { | ||||||
|  | @ -149,6 +151,7 @@ loop: // break out of for/select infinite loop | ||||||
| 		select { | 		select { | ||||||
| 		case e := <-progress: | 		case e := <-progress: | ||||||
| 			writeStatusCode(http.StatusOK) | 			writeStatusCode(http.StatusOK) | ||||||
|  | 			progressSent = true | ||||||
| 			switch e.Event { | 			switch e.Event { | ||||||
| 			case types.ProgressEventNewArtifact: | 			case types.ProgressEventNewArtifact: | ||||||
| 				report.Status = "Pulling fs layer" | 				report.Status = "Pulling fs layer" | ||||||
|  | @ -196,9 +199,22 @@ loop: // break out of for/select infinite loop | ||||||
| 					writeStatusCode(http.StatusInternalServerError) | 					writeStatusCode(http.StatusInternalServerError) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			// We need to check if no progress was sent previously. In that case, we should only return the base error message.
 | ||||||
|  | 			// This is necessary for compatibility with the Docker API.
 | ||||||
|  | 			if err != nil && !progressSent { | ||||||
|  | 				msg := errorhandling.Cause(err).Error() | ||||||
|  | 				message := jsonmessage.JSONError{ | ||||||
|  | 					Message: msg, | ||||||
|  | 				} | ||||||
|  | 				if err := enc.Encode(message); err != nil { | ||||||
|  | 					logrus.Warnf("Failed to json encode error %q", err.Error()) | ||||||
|  | 				} | ||||||
|  | 			} else { | ||||||
| 				if err := enc.Encode(report); err != nil { | 				if err := enc.Encode(report); err != nil { | ||||||
| 					logrus.Warnf("Failed to json encode error %q", err.Error()) | 					logrus.Warnf("Failed to json encode error %q", err.Error()) | ||||||
| 				} | 				} | ||||||
|  | 			} | ||||||
| 			flush() | 			flush() | ||||||
| 			break loop // break out of for/select infinite loop
 | 			break loop // break out of for/select infinite loop
 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -96,6 +96,10 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do | ||||||
|     .[0].Comment= |     .[0].Comment= | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
|  | # compat api pull image unauthorized message error | ||||||
|  | t POST "/images/create?fromImage=quay.io/idonotexist/idonotexist:dummy" 401 \ | ||||||
|  |   .message="unauthorized: access to the requested resource is not authorized" | ||||||
|  | 
 | ||||||
| # Export an image on the local | # Export an image on the local | ||||||
| t GET libpod/images/nonesuch/get 404 | t GET libpod/images/nonesuch/get 404 | ||||||
| t GET libpod/images/$iid/get?format=foo 500 | t GET libpod/images/$iid/get?format=foo 500 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue