8000 api: add undocumented /grpc endpoint available since API 1.40 by tiborvass · Pull Request #2944 · docker-archive/classicswarm · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,3 +1670,23 @@ func stripNodeNamesFromNetworkingConfig(n network.NetworkingConfig, nodeNames []
n.EndpointsConfig = endpointsConfig
return n
}

// postGRPC randomly chooses a node on the cluster and hijacks that connection.
func postGRPC(c *context, w http.ResponseWriter, r *http.Request) {
engine, err := c.cluster.RANDOMENGINE()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ideal, but seems acceptable for the time being.

if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}

if engine == nil {
httpError(w, "no node available in the cluster", http.StatusInternalServerError)
return
}

err = hijack(c.tlsConfig, engine.Addr, w, r)
engine.CheckConnectionErr(err)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
}
1 change: 1 addition & 0 deletions api/primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var routes = map[string]map[string]handler{
"/networks/{networkid:.*}/connect": proxyNetworkConnect,
"/networks/{networkid:.*}/disconnect": networkDisconnect,
"/volumes/create": postVolumesCreate,
"/grpc": postGRPC,

// TODO(dperny): this route is WIP, remove this comment
"/session": postSession,
Expand Down
0