Skip to content

Commit 4b8817c

Browse files
committed
simplify peer-query and remove REST-API for registration
1 parent f1f611d commit 4b8817c

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

apiserver/api/api.go

-11
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ func (a *api) updateHealth(w http.ResponseWriter, r *http.Request) {
8989
}
9090
}
9191

92-
func (a *api) registerClient(w http.ResponseWriter, r *http.Request) {
93-
var reg ClientRegistrationRequest
94-
if err := json.NewDecoder(r.Body).Decode(&reg); err != nil {
95-
respondf(w, http.StatusBadRequest, "error during JSON unmarshal: %s\n", err)
96-
}
97-
98-
if err := a.db.AddClient(reg.Username, reg.PublicKey, reg.Serial); err != nil {
99-
respondf(w, http.StatusInternalServerError, "unable to add new peer: %s\n", err)
100-
}
101-
}
102-
10392
func respondf(w http.ResponseWriter, statusCode int, format string, args ...interface{}) {
10493
w.WriteHeader(statusCode)
10594

apiserver/api/router.go

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func New(cfg Config) chi.Router {
1616
r.Get("/gateways/{gateway}", api.gatewayConfig)
1717
r.Get("/clients", api.clients)
1818
r.Put("/clients/health", api.updateHealth)
19-
r.Put("/clients/register", api.registerClient)
2019

2120
return r
2221
}

apiserver/database/database.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,15 @@ INSERT
190190
return tx.Commit(ctx)
191191
}
192192

193-
func (d *APIServerDB) ReadControlPlanePeer(serial string) (*Peer, error) {
193+
func (d *APIServerDB) ReadControlPlanePeer(publicKey string) (*Peer, error) {
194194
ctx := context.Background()
195195

196196
query := `
197197
SELECT public_key, ip
198-
FROM client_peer
199-
JOIN client c on c.id = client_id
200-
JOIN peer p on p.id = peer_id
201-
WHERE c.serial = $1
202-
AND p.type = 'control'
203-
LIMIT 1;`
204-
205-
row := d.conn.QueryRow(ctx, query, serial)
198+
FROM peer
199+
WHERE public_key = $1;`
200+
201+
row := d.conn.QueryRow(ctx, query, publicKey)
206202

207203
var peer Peer
208204
err := row.Scan(&peer.PublicKey, &peer.IP)

apiserver/slack/slack.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (s *slackbot) handleRegister(msg slack.Msg) string {
5252
log.Errorf("adding client to database: %v", err)
5353
return "Something went wrong during registration :sweat_smile:, I've notified the nais device team for you. (1)"
5454
} else {
55-
c, err := s.database.ReadControlPlanePeer(serial)
55+
c, err := s.database.ReadControlPlanePeer(publicKey)
5656
if err != nil {
5757
return "Something went wrong during registration :sweat_smile:, I've notified the nais device team for you. (2)"
5858
}

0 commit comments

Comments
 (0)