Skip to content

Commit

Permalink
Authroize cert update methods
Browse files Browse the repository at this point in the history
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
  • Loading branch information
dborovcanin committed May 20, 2019
1 parent baadb97 commit 1d12479
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bootstrap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader) http.Hand
encodeResponse,
opts...))

r.Post("/things/configs/certs/:id", kithttp.NewServer(
r.Post("/things/configs/certs/:key", kithttp.NewServer(
updateCertEndpoint(svc),
decodeUpdateCertRequest,
encodeResponse,
Expand Down Expand Up @@ -143,7 +143,7 @@ func decodeUpdateCertRequest(_ context.Context, r *http.Request) (interface{}, e
}

req := updateCertReq{key: r.Header.Get("Authorization")}
req.thingKey = bone.GetValue(r, "id")
req.thingKey = bone.GetValue(r, "key")
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type ConfigRepository interface {

// UpdateCerts updates an existing Config certificate and key.
// A non-nil error is returned to indicate operation failure.
UpdateCert(string, string, string, string) error
UpdateCert(string, string, string, string, string) error

// UpdateConnections updates a list of Channels the Config is connected to
// adding new Channels if needed.
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/postgres/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ func (cr configRepository) Update(cfg bootstrap.Config) error {
return nil
}

func (cr configRepository) UpdateCert(thingKey, clientCert, clientKey, caCert string) error {
q := `UPDATE configs SET client_cert = $1, client_key = $2, ca_cert = $3 WHERE mainflux_key = $4`
func (cr configRepository) UpdateCert(key, thingKey, clientCert, clientKey, caCert string) error {
q := `UPDATE configs SET client_cert = $1, client_key = $2, ca_cert = $3 WHERE mainflux_key = $4 AND owner = $5`

res, err := cr.db.Exec(q, clientCert, clientKey, caCert, thingKey)
res, err := cr.db.Exec(q, clientCert, clientKey, caCert, thingKey, key)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Service interface {
// Update updates editable fields of the provided Config.
Update(string, Config) error

// UpdateCerts updates an existing Config certificate and key.
// UpdateCert updates an existing Config certificate and key.
// A non-nil error is returned to indicate operation failure.
UpdateCert(string, string, string, string, string) error

Expand Down Expand Up @@ -175,11 +175,11 @@ func (bs bootstrapService) Update(key string, cfg Config) error {
}

func (bs bootstrapService) UpdateCert(key, thingKey, clientCert, clientKey, caCert string) error {
_, err := bs.identify(key)
owner, err := bs.identify(key)
if err != nil {
return err
}
return bs.configs.UpdateCert(thingKey, clientCert, clientKey, caCert)
return bs.configs.UpdateCert(owner, thingKey, clientCert, clientKey, caCert)
}

func (bs bootstrapService) UpdateConnections(key, id string, connections []string) error {
Expand Down

0 comments on commit 1d12479

Please sign in to comment.