Skip to content

Commit

Permalink
NOISSUE - Return certs on bootstrap view response (absmach#1855)
Browse files Browse the repository at this point in the history
* return certs on bootstrap view response

Signed-off-by: SammyOina <[email protected]>

* return updated certs when updated

Signed-off-by: SammyOina <[email protected]>

* fix test

Signed-off-by: SammyOina <[email protected]>

* fix test

Signed-off-by: SammyOina <[email protected]>

* fix test

Signed-off-by: SammyOina <[email protected]>

* fix test

Signed-off-by: SammyOina <[email protected]>

* fix tests

Signed-off-by: SammyOina <[email protected]>

* simplify tests

Signed-off-by: SammyOina <[email protected]>

* use named query

Signed-off-by: SammyOina <[email protected]>

* fix test

Signed-off-by: SammyOina <[email protected]>

* use named params

Signed-off-by: SammyOina <[email protected]>

* fix typo

Signed-off-by: SammyOina <[email protected]>

* use inline error checks
remove unrequired conditions

Signed-off-by: SammyOina <[email protected]>

* sort slices before comparison

Signed-off-by: SammyOina <[email protected]>

* rename mainflux_id to thing_id
rename MFThing to ThingID
rename MFKey to ThingKey
rename mainflux_key to thing_key

Signed-off-by: SammyOina <[email protected]>

* remove mainflux_channels

Signed-off-by: SammyOina <[email protected]>

* simplify unmarshaller

Signed-off-by: SammyOina <[email protected]>

---------

Signed-off-by: SammyOina <[email protected]>
  • Loading branch information
SammyOina authored and WashingtonKK committed Aug 4, 2023
1 parent d27c4c1 commit dbfd5c3
Show file tree
Hide file tree
Showing 24 changed files with 567 additions and 383 deletions.
50 changes: 42 additions & 8 deletions api/openapi/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ paths:
responses:
'200':
description: Config updated.
$ref: "#/components/responses/ConfigUpdateCertsRes"
'400':
description: Failed due to malformed JSON.
'401':
Expand Down Expand Up @@ -239,15 +240,15 @@ components:
Config:
type: object
properties:
mainflux_id:
thing_id:
type: string
format: uuid
description: Corresponding Mainflux Thing ID.
mainflux_key:
type: string
format: uuid
description: Corresponding Mainflux Thing key.
mainflux_channels:
channels:
type: array
minItems: 0
items:
Expand All @@ -274,6 +275,12 @@ components:
description: Free-form custom configuration.
state:
$ref: "#/components/schemas/State"
client_cert:
type: string
description: Client certificate.
ca_cert:
type: string
description: Issuing CA certificate.
required:
- external_id
- external_key
Expand Down Expand Up @@ -305,15 +312,15 @@ components:
BootstrapConfig:
type: object
properties:
mainflux_id:
thing_id:
type: string
format: uuid
description: Corresponding Mainflux Thing ID.
mainflux_key:
thing_key:
type: string
format: uuid
description: Corresponding Mainflux Thing key.
mainflux_channels:
channels:
type: array
minItems: 0
items:
Expand All @@ -331,9 +338,30 @@ components:
type: string
description: Issuing CA certificate.
required:
- mainflux_id
- mainflux_key
- mainflux_channels
- thing_id
- thing_key
- channels
- content
ConfigUpdateCerts:
type: object
properties:
thing_id:
type: string
format: uuid
description: Corresponding Mainflux Thing ID.
client_cert:
type: string
description: Client certificate.
client_key:
type: string
description: Key for the client_cert.
ca_cert:
type: string
description: Issuing CA certificate.
required:
- thing_id
- thing_key
- channels
- content

parameters:
Expand Down Expand Up @@ -511,6 +539,12 @@ components:
application/json:
schema:
$ref: "./schemas/HealthInfo.yml"
ConfigUpdateCertsRes:
description: Data retrieved. Config certs updated.
content:
application/json:
schema:
$ref: "#/components/schemas/ConfigUpdateCerts"

securitySchemes:
bearerAuth:
Expand Down
32 changes: 19 additions & 13 deletions bootstrap/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

config := bootstrap.Config{
MFThing: req.ThingID,
ThingID: req.ThingID,
ExternalID: req.ExternalID,
ExternalKey: req.ExternalKey,
MFChannels: channels,
Channels: channels,
Name: req.Name,
ClientCert: req.ClientCert,
ClientKey: req.ClientKey,
Expand All @@ -40,7 +40,7 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

res := configRes{
id: saved.MFThing,
id: saved.ThingID,
created: true,
}

Expand All @@ -55,11 +55,17 @@ func updateCertEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, err
}

if err := svc.UpdateCert(ctx, req.token, req.thingID, req.ClientCert, req.ClientKey, req.CACert); err != nil {
cfg, err := svc.UpdateCert(ctx, req.token, req.thingID, req.ClientCert, req.ClientKey, req.CACert)
if err != nil {
return nil, err
}

res := configRes{}
res := updateConfigRes{
ThingID: cfg.ThingID,
ClientCert: cfg.ClientCert,
CACert: cfg.CACert,
ClientKey: cfg.ClientKey,
}

return res, nil
}
Expand All @@ -79,7 +85,7 @@ func viewEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

var channels []channelRes
for _, ch := range config.MFChannels {
for _, ch := range config.Channels {
channels = append(channels, channelRes{
ID: ch.ID,
Name: ch.Name,
Expand All @@ -88,8 +94,8 @@ func viewEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

res := viewRes{
MFThing: config.MFThing,
MFKey: config.MFKey,
ThingID: config.ThingID,
ThingKey: config.ThingKey,
Channels: channels,
ExternalID: config.ExternalID,
ExternalKey: config.ExternalKey,
Expand All @@ -111,7 +117,7 @@ func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

config := bootstrap.Config{
MFThing: req.id,
ThingID: req.id,
Name: req.Name,
Content: req.Content,
}
Expand All @@ -121,7 +127,7 @@ func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

res := configRes{
id: config.MFThing,
id: config.ThingID,
created: false,
}

Expand Down Expand Up @@ -171,7 +177,7 @@ func listEndpoint(svc bootstrap.Service) endpoint.Endpoint {

for _, cfg := range page.Configs {
var channels []channelRes
for _, ch := range cfg.MFChannels {
for _, ch := range cfg.Channels {
channels = append(channels, channelRes{
ID: ch.ID,
Name: ch.Name,
Expand All @@ -180,8 +186,8 @@ func listEndpoint(svc bootstrap.Service) endpoint.Endpoint {
}

view := viewRes{
MFThing: cfg.MFThing,
MFKey: cfg.MFKey,
ThingID: cfg.ThingID,
ThingKey: cfg.ThingKey,
Channels: channels,
ExternalID: cfg.ExternalID,
ExternalKey: cfg.ExternalKey,
Expand Down
Loading

0 comments on commit dbfd5c3

Please sign in to comment.