Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Return certs on bootstrap view response #1855

Merged
merged 17 commits into from
Jul 31, 2023
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