MCPcopy Create free account
hub / github.com/evcc-io/evcc / createRemoteClientHandler

Function createRemoteClientHandler

server/http_remote_handler.go:20–49  ·  view source on GitHub ↗

createRemoteClientHandler creates a new tunnel client and returns the cleartext password (shown to the user only once).

(r *remote.Remote)

Source from the content-addressed store, hash-verified

18// createRemoteClientHandler creates a new tunnel client and returns the
19// cleartext password (shown to the user only once).
20func createRemoteClientHandler(r *remote.Remote) http.HandlerFunc {
21 return func(w http.ResponseWriter, req *http.Request) {
22 var body struct {
23 Username string `json:"username"`
24 ExpiresIn int64 `json:"expiresIn"` // seconds; 0 = never
25 }
26 if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
27 jsonError(w, http.StatusBadRequest, err)
28 return
29 }
30
31 client, password, err := r.CreateClient(body.Username, time.Duration(body.ExpiresIn)*time.Second)
32 if err != nil {
33 jsonError(w, http.StatusBadRequest, err)
34 return
35 }
36
37 jsonWrite(w, struct {
38 Username string `json:"username"`
39 Password string `json:"password"`
40 CreatedAt time.Time `json:"createdAt"`
41 ExpiresAt *time.Time `json:"expiresAt,omitempty"`
42 }{
43 Username: client.Username,
44 Password: password,
45 CreatedAt: client.CreatedAt,
46 ExpiresAt: client.ExpiresAt,
47 })
48 }
49}
50
51// deleteRemoteClientHandler removes a tunnel client by username.
52// Username is passed as a query parameter to allow arbitrary characters.

Callers 1

RegisterSystemHandlerMethod · 0.85

Calls 4

CreateClientMethod · 0.80
DurationMethod · 0.80
jsonErrorFunction · 0.70
jsonWriteFunction · 0.70

Tested by

no test coverage detected