summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-07-19 10:23:21 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-07-20 09:00:44 +0200
commiteaaca499922c4a322bf61b7d9f288a447b1079ba (patch)
tree05602c619b7303558a0b46d43ac3a117ddb09b12 /pkg/api/handlers/compat
parent20c9f74c77683730455df4fb5e7722a192b78a92 (diff)
downloadpodman-eaaca499922c4a322bf61b7d9f288a447b1079ba.tar.gz
podman-eaaca499922c4a322bf61b7d9f288a447b1079ba.tar.bz2
podman-eaaca499922c4a322bf61b7d9f288a447b1079ba.zip
compat: image create: handle platform correctly
Handle the platform parameter correctly. The parameter was only parsed in presence of credentials and the code was a bit complex. Also add a regression test. Fixes: #10977 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/images.go35
1 files changed, 10 insertions, 25 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index 7baa1145a..6f8fb21f0 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -266,41 +266,26 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
}
defer auth.RemoveAuthfile(authfile)
- platformSpecs := strings.Split(query.Platform, "/") // split query into its parts
-
- addOS := true // default assume true due to structure of if/else below
- addArch := false
- addVariant := false
-
- if len(platformSpecs) > 1 { // if we have two arguments then we have os and arch
- addArch = true
- if len(platformSpecs) > 2 { // if we have 3 arguments then we have os arch and variant
- addVariant = true
- }
- } else if len(platformSpecs) == 0 {
- addOS = false
- }
-
pullOptions := &libimage.PullOptions{}
pullOptions.AuthFilePath = authfile
if authConf != nil {
pullOptions.Username = authConf.Username
pullOptions.Password = authConf.Password
pullOptions.IdentityToken = authConf.IdentityToken
- if addOS { // if the len is not 0
- pullOptions.OS = platformSpecs[0]
- if addArch {
- pullOptions.Architecture = platformSpecs[1]
- }
- if addVariant {
- pullOptions.Variant = platformSpecs[2]
- }
- }
}
pullOptions.Writer = os.Stderr // allows for debugging on the server
- progress := make(chan types.ProgressProperties)
+ // Handle the platform.
+ platformSpecs := strings.Split(query.Platform, "/")
+ pullOptions.OS = platformSpecs[0] // may be empty
+ if len(platformSpecs) > 1 {
+ pullOptions.Architecture = platformSpecs[1]
+ if len(platformSpecs) > 2 {
+ pullOptions.Variant = platformSpecs[2]
+ }
+ }
+ progress := make(chan types.ProgressProperties)
pullOptions.Progress = progress
pullResChan := make(chan pullResult)