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 62e2534 commit 48cb23f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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 48cb23f

Please sign in to comment.