Procházet zdrojové kódy

Merge pull request #11670 from runcom/11607-api-route-post-auth-response

Return AuthResponse from postAuth api endpoint
Alexander Morozov před 10 roky
rodič
revize
9d7f58100f
3 změnil soubory, kde provedl 15 přidání a 6 odebrání
  1. 6 5
      api/client/commands.go
  2. 3 1
      api/server/server.go
  3. 6 0
      api/types/types.go

+ 6 - 5
api/client/commands.go

@@ -450,17 +450,18 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	var out2 engine.Env
-	err = out2.Decode(stream)
-	if err != nil {
+
+	var response types.AuthResponse
+	if err := json.NewDecoder(stream).Decode(response); err != nil {
 		cli.configFile, _ = registry.LoadConfig(homedir.Get())
 		cli.configFile, _ = registry.LoadConfig(homedir.Get())
 		return err
 		return err
 	}
 	}
+
 	registry.SaveConfig(cli.configFile)
 	registry.SaveConfig(cli.configFile)
 	fmt.Fprintf(cli.out, "WARNING: login credentials saved in %s.\n", path.Join(homedir.Get(), registry.CONFIGFILE))
 	fmt.Fprintf(cli.out, "WARNING: login credentials saved in %s.\n", path.Join(homedir.Get(), registry.CONFIGFILE))
 
 
-	if out2.Get("Status") != "" {
-		fmt.Fprintf(cli.out, "%s\n", out2.Get("Status"))
+	if response.Status != "" {
+		fmt.Fprintf(cli.out, "%s\n", response.Status)
 	}
 	}
 	return nil
 	return nil
 }
 }

+ 3 - 1
api/server/server.go

@@ -192,7 +192,9 @@ func postAuth(eng *engine.Engine, version version.Version, w http.ResponseWriter
 	if status := engine.Tail(stdoutBuffer, 1); status != "" {
 	if status := engine.Tail(stdoutBuffer, 1); status != "" {
 		var env engine.Env
 		var env engine.Env
 		env.Set("Status", status)
 		env.Set("Status", status)
-		return writeJSONEnv(w, http.StatusOK, env)
+		return writeJSON(w, http.StatusOK, &types.AuthResponse{
+			Status: status,
+		})
 	}
 	}
 	w.WriteHeader(http.StatusNoContent)
 	w.WriteHeader(http.StatusNoContent)
 	return nil
 	return nil

+ 6 - 0
api/types/types.go

@@ -18,3 +18,9 @@ type ContainerExecCreateResponse struct {
 	// Warnings are any warnings encountered during the execution of the command.
 	// Warnings are any warnings encountered during the execution of the command.
 	Warnings []string `json:"Warnings"`
 	Warnings []string `json:"Warnings"`
 }
 }
+
+// POST /auth
+type AuthResponse struct {
+	// Status is the authentication status
+	Status string `json:"Status"`
+}