createRemoteClientHandler creates a new tunnel client and returns the cleartext password (shown to the user only once).
(r *remote.Remote)
| 18 | // createRemoteClientHandler creates a new tunnel client and returns the |
| 19 | // cleartext password (shown to the user only once). |
| 20 | func 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. |
no test coverage detected