From 0e2de4c754deff99c999af2ffb56babac14be210 Mon Sep 17 00:00:00 2001 From: SammyOina Date: Fri, 14 Jul 2023 14:09:40 +0300 Subject: [PATCH] rename mainflux_id to thing_id rename MFThing to ThingID rename MFKey to ThingKey rename mainflux_key to thing_key Signed-off-by: SammyOina --- api/openapi/bootstrap.yml | 18 ++--- bootstrap/api/endpoint.go | 18 ++--- bootstrap/api/endpoint_test.go | 90 ++++++++++++------------ bootstrap/api/logging.go | 6 +- bootstrap/api/requests.go | 2 +- bootstrap/api/responses.go | 6 +- bootstrap/api/transport.go | 2 +- bootstrap/configs.go | 4 +- bootstrap/mocks/configs.go | 24 +++---- bootstrap/postgres/configs.go | 16 ++--- bootstrap/postgres/configs_test.go | 86 +++++++++++----------- bootstrap/reader.go | 8 +-- bootstrap/reader_test.go | 12 ++-- bootstrap/redis/producer/events.go | 8 +-- bootstrap/redis/producer/streams_test.go | 42 +++++------ bootstrap/service.go | 14 ++-- bootstrap/service_test.go | 48 ++++++------- bootstrap/tracing/tracing.go | 4 +- cli/README.md | 2 +- pkg/sdk/go/bootstrap.go | 10 +-- provision/service.go | 14 ++-- 21 files changed, 217 insertions(+), 217 deletions(-) diff --git a/api/openapi/bootstrap.yml b/api/openapi/bootstrap.yml index caf501dc85e..05a362e9544 100644 --- a/api/openapi/bootstrap.yml +++ b/api/openapi/bootstrap.yml @@ -240,7 +240,7 @@ components: Config: type: object properties: - mainflux_id: + thing_id: type: string format: uuid description: Corresponding Mainflux Thing ID. @@ -312,11 +312,11 @@ 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. @@ -338,14 +338,14 @@ components: type: string description: Issuing CA certificate. required: - - mainflux_id - - mainflux_key + - thing_id + - thing_key - mainflux_channels - content ConfigUpdateCerts: type: object properties: - mainflux_id: + thing_id: type: string format: uuid description: Corresponding Mainflux Thing ID. @@ -359,8 +359,8 @@ components: type: string description: Issuing CA certificate. required: - - mainflux_id - - mainflux_key + - thing_id + - thing_key - mainflux_channels - content @@ -429,7 +429,7 @@ components: external_key: type: string description: External key. - mainflux_id: + thing_id: type: string description: ID of the corresponding Mainflux Thing. channels: diff --git a/bootstrap/api/endpoint.go b/bootstrap/api/endpoint.go index 7b3c9e6224b..d1d7ec5ebb1 100644 --- a/bootstrap/api/endpoint.go +++ b/bootstrap/api/endpoint.go @@ -23,7 +23,7 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint { } config := bootstrap.Config{ - MFThing: req.ThingID, + ThingID: req.ThingID, ExternalID: req.ExternalID, ExternalKey: req.ExternalKey, MFChannels: channels, @@ -40,7 +40,7 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint { } res := configRes{ - id: saved.MFThing, + id: saved.ThingID, created: true, } @@ -61,7 +61,7 @@ func updateCertEndpoint(svc bootstrap.Service) endpoint.Endpoint { } res := updateConfigRes{ - MFThing: cfg.MFThing, + ThingID: cfg.ThingID, ClientCert: cfg.ClientCert, CACert: cfg.CACert, ClientKey: cfg.ClientKey, @@ -94,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, @@ -117,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, } @@ -127,7 +127,7 @@ func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint { } res := configRes{ - id: config.MFThing, + id: config.ThingID, created: false, } @@ -186,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, diff --git a/bootstrap/api/endpoint_test.go b/bootstrap/api/endpoint_test.go index 9b290cde342..94999c545a0 100644 --- a/bootstrap/api/endpoint_test.go +++ b/bootstrap/api/endpoint_test.go @@ -58,7 +58,7 @@ var ( encKey = []byte("1234567891011121") metadata = map[string]interface{}{"meta": "data"} addReq = struct { - ThingID string `json:"mainflux_id"` + ThingID string `json:"thing_id"` ExternalID string `json:"external_id"` ExternalKey string `json:"external_key"` Channels []string `json:"channels"` @@ -370,8 +370,8 @@ func TestView(t *testing.T) { } data := config{ - MFThing: saved.MFThing, - MFKey: saved.MFKey, + ThingID: saved.ThingID, + ThingKey: saved.ThingKey, State: saved.State, Channels: channels, ExternalID: saved.ExternalID, @@ -390,14 +390,14 @@ func TestView(t *testing.T) { { desc: "view a config with invalid token", auth: invalidToken, - id: saved.MFThing, + id: saved.ThingID, status: http.StatusUnauthorized, res: config{}, }, { desc: "view a config", auth: validToken, - id: saved.MFThing, + id: saved.ThingID, status: http.StatusOK, res: data, }, @@ -411,7 +411,7 @@ func TestView(t *testing.T) { { desc: "view a config with an empty token", auth: "", - id: saved.MFThing, + id: saved.ThingID, status: http.StatusUnauthorized, res: config{}, }, @@ -466,7 +466,7 @@ func TestUpdate(t *testing.T) { { desc: "update with invalid token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: invalidToken, contentType: contentType, status: http.StatusUnauthorized, @@ -474,7 +474,7 @@ func TestUpdate(t *testing.T) { { desc: "update with an empty token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: "", contentType: contentType, status: http.StatusUnauthorized, @@ -482,7 +482,7 @@ func TestUpdate(t *testing.T) { { desc: "update a valid config", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusOK, @@ -490,7 +490,7 @@ func TestUpdate(t *testing.T) { { desc: "update a config with wrong content type", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: "", status: http.StatusUnsupportedMediaType, @@ -506,14 +506,14 @@ func TestUpdate(t *testing.T) { { desc: "update a config with invalid request format", req: "}", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusBadRequest, }, { desc: "update a config with an empty request", - id: saved.MFThing, + id: saved.ThingID, req: "", auth: validToken, contentType: contentType, @@ -560,7 +560,7 @@ func TestUpdateCert(t *testing.T) { { desc: "update with invalid token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: invalidToken, contentType: contentType, status: http.StatusUnauthorized, @@ -568,7 +568,7 @@ func TestUpdateCert(t *testing.T) { { desc: "update with an empty token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: "", contentType: contentType, status: http.StatusUnauthorized, @@ -576,7 +576,7 @@ func TestUpdateCert(t *testing.T) { { desc: "update a valid config", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusOK, @@ -584,7 +584,7 @@ func TestUpdateCert(t *testing.T) { { desc: "update a config with wrong content type", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: "", status: http.StatusUnsupportedMediaType, @@ -600,14 +600,14 @@ func TestUpdateCert(t *testing.T) { { desc: "update a config with invalid request format", req: "}", - id: saved.MFKey, + id: saved.ThingKey, auth: validToken, contentType: contentType, status: http.StatusBadRequest, }, { desc: "update a config with an empty request", - id: saved.MFThing, + id: saved.ThingID, req: "", auth: validToken, contentType: contentType, @@ -660,7 +660,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections with invalid token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: invalidToken, contentType: contentType, status: http.StatusUnauthorized, @@ -668,7 +668,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections with an empty token", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: "", contentType: contentType, status: http.StatusUnauthorized, @@ -676,7 +676,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections valid config", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusOK, @@ -684,7 +684,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections with wrong content type", req: data, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: "", status: http.StatusUnsupportedMediaType, @@ -700,7 +700,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections with invalid channels", req: wrongData, - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusBadRequest, @@ -708,14 +708,14 @@ func TestUpdateConnections(t *testing.T) { { desc: "update a config with invalid request format", req: "}", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, contentType: contentType, status: http.StatusBadRequest, }, { desc: "update a config with an empty request", - id: saved.MFThing, + id: saved.ThingID, req: "", auth: validToken, contentType: contentType, @@ -754,7 +754,7 @@ func TestList(t *testing.T) { for i := 0; i < configNum; i++ { c.ExternalID = strconv.Itoa(i) - c.MFKey = c.ExternalID + c.ThingKey = c.ExternalID c.Name = fmt.Sprintf("%s-%d", addName, i) c.ExternalKey = fmt.Sprintf("%s%s", addExternalKey, strconv.Itoa(i)) @@ -766,8 +766,8 @@ func TestList(t *testing.T) { channels = append(channels, channel{ID: ch.ID, Name: ch.Name, Metadata: ch.Metadata}) } s := config{ - MFThing: saved.MFThing, - MFKey: saved.MFKey, + ThingID: saved.ThingID, + ThingKey: saved.ThingKey, Channels: channels, ExternalID: saved.ExternalID, ExternalKey: saved.ExternalKey, @@ -784,7 +784,7 @@ func TestList(t *testing.T) { if i%2 == 0 { state = bootstrap.Inactive } - err := svc.ChangeState(context.Background(), validToken, list[i].MFThing, state) + err := svc.ChangeState(context.Background(), validToken, list[i].ThingID, state) assert.Nil(t, err, fmt.Sprintf("Changing state expected to succeed: %s.\n", err)) list[i].State = state if state == bootstrap.Inactive { @@ -1008,12 +1008,12 @@ func TestRemove(t *testing.T) { }{ { desc: "remove with invalid token", - id: saved.MFThing, + id: saved.ThingID, auth: invalidToken, status: http.StatusUnauthorized, }, { desc: "remove with an empty token", - id: saved.MFThing, + id: saved.ThingID, auth: "", status: http.StatusUnauthorized, }, @@ -1025,7 +1025,7 @@ func TestRemove(t *testing.T) { }, { desc: "remove config", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, status: http.StatusNoContent, }, @@ -1071,16 +1071,16 @@ func TestBootstrap(t *testing.T) { } s := struct { - MFThing string `json:"mainflux_id"` - MFKey string `json:"mainflux_key"` + ThingID string `json:"thing_id"` + ThingKey string `json:"thing_key"` MFChannels []channel `json:"mainflux_channels"` Content string `json:"content"` ClientCert string `json:"client_cert"` ClientKey string `json:"client_key"` CACert string `json:"ca_cert"` }{ - MFThing: saved.MFThing, - MFKey: saved.MFKey, + ThingID: saved.ThingID, + ThingKey: saved.ThingKey, MFChannels: channels, Content: saved.Content, ClientCert: saved.ClientCert, @@ -1204,7 +1204,7 @@ func TestChangeState(t *testing.T) { }{ { desc: "change state with invalid token", - id: saved.MFThing, + id: saved.ThingID, auth: invalidToken, state: active, contentType: contentType, @@ -1212,7 +1212,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state with an empty token", - id: saved.MFThing, + id: saved.ThingID, auth: "", state: active, contentType: contentType, @@ -1220,7 +1220,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state with invalid content type", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, state: active, contentType: "", @@ -1228,7 +1228,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state to active", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, state: active, contentType: contentType, @@ -1236,7 +1236,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state to inactive", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, state: inactive, contentType: contentType, @@ -1252,7 +1252,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state to invalid value", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, state: fmt.Sprintf("{\"state\": %d}", -3), contentType: contentType, @@ -1260,7 +1260,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state with invalid data", - id: saved.MFThing, + id: saved.ThingID, auth: validToken, state: "", contentType: contentType, @@ -1290,8 +1290,8 @@ type channel struct { } type config struct { - MFThing string `json:"mainflux_id,omitempty"` - MFKey string `json:"mainflux_key,omitempty"` + ThingID string `json:"thing_id,omitempty"` + ThingKey string `json:"thing_key,omitempty"` Channels []channel `json:"mainflux_channels,omitempty"` ExternalID string `json:"external_id"` ExternalKey string `json:"external_key,omitempty"` diff --git a/bootstrap/api/logging.go b/bootstrap/api/logging.go index 17b4d632345..bde6e0c7396 100644 --- a/bootstrap/api/logging.go +++ b/bootstrap/api/logging.go @@ -30,7 +30,7 @@ func LoggingMiddleware(svc bootstrap.Service, logger mflog.Logger) bootstrap.Ser // If the request fails, it logs the error. func (lm *loggingMiddleware) Add(ctx context.Context, token string, cfg bootstrap.Config) (saved bootstrap.Config, err error) { defer func(begin time.Time) { - message := fmt.Sprintf("Method add using token %s with thing %s took %s to complete", token, saved.MFThing, time.Since(begin)) + message := fmt.Sprintf("Method add using token %s with thing %s took %s to complete", token, saved.ThingID, time.Since(begin)) if err != nil { lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) return @@ -45,7 +45,7 @@ func (lm *loggingMiddleware) Add(ctx context.Context, token string, cfg bootstra // If the request fails, it logs the error. func (lm *loggingMiddleware) View(ctx context.Context, token, id string) (saved bootstrap.Config, err error) { defer func(begin time.Time) { - message := fmt.Sprintf("Method view using token %s with thing %s took %s to complete", token, saved.MFThing, time.Since(begin)) + message := fmt.Sprintf("Method view using token %s with thing %s took %s to complete", token, saved.ThingID, time.Since(begin)) if err != nil { lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) return @@ -60,7 +60,7 @@ func (lm *loggingMiddleware) View(ctx context.Context, token, id string) (saved // If the request fails, it logs the error. func (lm *loggingMiddleware) Update(ctx context.Context, token string, cfg bootstrap.Config) (err error) { defer func(begin time.Time) { - message := fmt.Sprintf("Method update using token %s with thing %s took %s to complete", token, cfg.MFThing, time.Since(begin)) + message := fmt.Sprintf("Method update using token %s with thing %s took %s to complete", token, cfg.ThingID, time.Since(begin)) if err != nil { lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) return diff --git a/bootstrap/api/requests.go b/bootstrap/api/requests.go index 8b51d6eab92..62f1f495e66 100644 --- a/bootstrap/api/requests.go +++ b/bootstrap/api/requests.go @@ -12,7 +12,7 @@ const maxLimitSize = 100 type addReq struct { token string - ThingID string `json:"mainflux_id"` + ThingID string `json:"thing_id"` ExternalID string `json:"external_id"` ExternalKey string `json:"external_key"` Channels []string `json:"channels"` diff --git a/bootstrap/api/responses.go b/bootstrap/api/responses.go index ecc864c5d2a..e52677e199f 100644 --- a/bootstrap/api/responses.go +++ b/bootstrap/api/responses.go @@ -67,8 +67,8 @@ type channelRes struct { } type viewRes struct { - MFThing string `json:"mainflux_id,omitempty"` - MFKey string `json:"mainflux_key,omitempty"` + ThingID string `json:"thing_id,omitempty"` + ThingKey string `json:"thing_key,omitempty"` Channels []channelRes `json:"mainflux_channels,omitempty"` ExternalID string `json:"external_id"` ExternalKey string `json:"external_key,omitempty"` @@ -125,7 +125,7 @@ func (res stateRes) Empty() bool { } type updateConfigRes struct { - MFThing string `json:"mainflux_id,omitempty"` + ThingID string `json:"thing_id,omitempty"` ClientCert string `json:"client_cert,omitempty"` CACert string `json:"ca_cert,omitempty"` ClientKey string `json:"client_key,omitempty"` diff --git a/bootstrap/api/transport.go b/bootstrap/api/transport.go index 1de61e809c8..fab928650a6 100644 --- a/bootstrap/api/transport.go +++ b/bootstrap/api/transport.go @@ -30,7 +30,7 @@ const ( ) var ( - fullMatch = []string{"state", "external_id", "mainflux_id", "mainflux_key"} + fullMatch = []string{"state", "external_id", "thing_id", "thing_key"} partialMatch = []string{"name"} ) diff --git a/bootstrap/configs.go b/bootstrap/configs.go index 1e07a29066f..06d38d06f1a 100644 --- a/bootstrap/configs.go +++ b/bootstrap/configs.go @@ -16,13 +16,13 @@ import ( // MFKey is key of corresponding Mainflux Thing. // MFChannels is a list of Mainflux Channels corresponding Mainflux Thing connects to. type Config struct { - MFThing string `json:"mainflux_thing"` + ThingID string `json:"thing_id"` Owner string `json:"owner,omitempty"` Name string `json:"name,omitempty"` ClientCert string `json:"client_cert,omitempty"` ClientKey string `json:"client_key,omitempty"` CACert string `json:"ca_cert,omitempty"` - MFKey string `json:"mainflux_key"` + ThingKey string `json:"thing_key"` MFChannels []Channel `json:"mainflux_channels,omitempty"` ExternalID string `json:"external_id"` ExternalKey string `json:"external_key"` diff --git a/bootstrap/mocks/configs.go b/bootstrap/mocks/configs.go index 689db8388df..7d1aedfc13d 100644 --- a/bootstrap/mocks/configs.go +++ b/bootstrap/mocks/configs.go @@ -38,14 +38,14 @@ func (crm *configRepositoryMock) Save(_ context.Context, config bootstrap.Config defer crm.mu.Unlock() for _, v := range crm.configs { - if v.MFThing == config.MFThing || v.ExternalID == config.ExternalID { + if v.ThingID == config.ThingID || v.ExternalID == config.ExternalID { return "", errors.ErrConflict } } crm.counter++ - config.MFThing = strconv.FormatUint(crm.counter, 10) - crm.configs[config.MFThing] = config + config.ThingID = strconv.FormatUint(crm.counter, 10) + crm.configs[config.ThingID] = config for _, ch := range config.MFChannels { crm.channels[ch.ID] = ch @@ -57,9 +57,9 @@ func (crm *configRepositoryMock) Save(_ context.Context, config bootstrap.Config config.MFChannels = append(config.MFChannels, crm.channels[ch]) } - crm.configs[config.MFThing] = config + crm.configs[config.ThingID] = config - return config.MFThing, nil + return config.ThingID, nil } func (crm *configRepositoryMock) RetrieveByID(_ context.Context, token, id string) (bootstrap.Config, error) { @@ -99,7 +99,7 @@ func (crm *configRepositoryMock) RetrieveAll(_ context.Context, token string, fi var total uint64 for _, v := range crm.configs { - id, _ := strconv.ParseUint(v.MFThing, 10, 64) + id, _ := strconv.ParseUint(v.ThingID, 10, 64) if (state == emptyState || v.State == state) && (name == "" || strings.Contains(strings.ToLower(v.Name), name)) && v.Owner == token { @@ -111,7 +111,7 @@ func (crm *configRepositoryMock) RetrieveAll(_ context.Context, token string, fi } sort.SliceStable(configs, func(i, j int) bool { - return configs[i].MFThing < configs[j].MFThing + return configs[i].ThingID < configs[j].ThingID }) return bootstrap.ConfigsPage{ @@ -139,14 +139,14 @@ func (crm *configRepositoryMock) Update(_ context.Context, config bootstrap.Conf crm.mu.Lock() defer crm.mu.Unlock() - cfg, ok := crm.configs[config.MFThing] + cfg, ok := crm.configs[config.ThingID] if !ok || cfg.Owner != config.Owner { return errors.ErrNotFound } cfg.Name = config.Name cfg.Content = config.Content - crm.configs[config.MFThing] = cfg + crm.configs[config.ThingID] = cfg return nil } @@ -156,18 +156,18 @@ func (crm *configRepositoryMock) UpdateCert(_ context.Context, owner, thingID, c defer crm.mu.Unlock() var forUpdate bootstrap.Config for _, v := range crm.configs { - if v.MFThing == thingID && v.Owner == owner { + if v.ThingID == thingID && v.Owner == owner { forUpdate = v break } } - if _, ok := crm.configs[forUpdate.MFThing]; !ok { + if _, ok := crm.configs[forUpdate.ThingID]; !ok { return bootstrap.Config{}, errors.ErrNotFound } forUpdate.ClientCert = clientCert forUpdate.ClientKey = clientKey forUpdate.CACert = caCert - crm.configs[forUpdate.MFThing] = forUpdate + crm.configs[forUpdate.ThingID] = forUpdate return forUpdate, nil } diff --git a/bootstrap/postgres/configs.go b/bootstrap/postgres/configs.go index 14d7e56ddcc..b95e1378817 100644 --- a/bootstrap/postgres/configs.go +++ b/bootstrap/postgres/configs.go @@ -82,7 +82,7 @@ func (cr configRepository) Save(ctx context.Context, cfg bootstrap.Config, chsCo return "", err } - return cfg.MFThing, nil + return cfg.ThingID, nil } func (cr configRepository) RetrieveByID(ctx context.Context, owner, id string) (bootstrap.Config, error) { @@ -165,7 +165,7 @@ func (cr configRepository) RetrieveAll(ctx context.Context, owner string, filter for rows.Next() { c := bootstrap.Config{Owner: owner} - if err := rows.Scan(&c.MFThing, &c.MFKey, &c.ExternalID, &c.ExternalKey, &name, &content, &c.State); err != nil { + if err := rows.Scan(&c.ThingID, &c.ThingKey, &c.ExternalID, &c.ExternalKey, &name, &content, &c.State); err != nil { cr.log.Error(fmt.Sprintf("Failed to read retrieved config due to %s", err)) return bootstrap.ConfigsPage{} } @@ -256,7 +256,7 @@ func (cr configRepository) Update(ctx context.Context, cfg bootstrap.Config) err dbcfg := dbConfig{ Name: nullString(cfg.Name), Content: nullString(cfg.Content), - MFThing: cfg.MFThing, + MFThing: cfg.ThingID, Owner: cfg.Owner, } @@ -524,7 +524,7 @@ func insertConnections(ctx context.Context, cfg bootstrap.Config, connections [] conns := []dbConnection{} for _, conn := range connections { dbconn := dbConnection{ - Config: cfg.MFThing, + Config: cfg.ThingID, Channel: conn, ConfigOwner: cfg.Owner, ChannelOwner: cfg.Owner, @@ -625,13 +625,13 @@ type dbConfig struct { func toDBConfig(cfg bootstrap.Config) dbConfig { return dbConfig{ - MFThing: cfg.MFThing, + MFThing: cfg.ThingID, Owner: cfg.Owner, Name: nullString(cfg.Name), ClientCert: nullString(cfg.ClientCert), ClientKey: nullString(cfg.ClientKey), CaCert: nullString(cfg.CACert), - MFKey: cfg.MFKey, + MFKey: cfg.ThingKey, ExternalID: cfg.ExternalID, ExternalKey: cfg.ExternalKey, Content: nullString(cfg.Content), @@ -641,9 +641,9 @@ func toDBConfig(cfg bootstrap.Config) dbConfig { func toConfig(dbcfg dbConfig) bootstrap.Config { cfg := bootstrap.Config{ - MFThing: dbcfg.MFThing, + ThingID: dbcfg.MFThing, Owner: dbcfg.Owner, - MFKey: dbcfg.MFKey, + ThingKey: dbcfg.MFKey, ExternalID: dbcfg.ExternalID, ExternalKey: dbcfg.ExternalKey, State: dbcfg.State, diff --git a/bootstrap/postgres/configs_test.go b/bootstrap/postgres/configs_test.go index e568a34bfd3..4d7ff15ef0f 100644 --- a/bootstrap/postgres/configs_test.go +++ b/bootstrap/postgres/configs_test.go @@ -21,8 +21,8 @@ const numConfigs = 10 var ( config = bootstrap.Config{ - MFThing: "mf-thing", - MFKey: "mf-key", + ThingID: "mf-thing", + ThingKey: "mf-key", ExternalID: "external-id", ExternalKey: "external-key", Owner: "user@email.com", @@ -46,18 +46,18 @@ func TestSave(t *testing.T) { duplicateThing := config duplicateThing.ExternalID = diff - duplicateThing.MFKey = diff + duplicateThing.ThingKey = diff duplicateThing.MFChannels = []bootstrap.Channel{} duplicateExternal := config - duplicateExternal.MFThing = diff - duplicateExternal.MFKey = diff + duplicateExternal.ThingID = diff + duplicateExternal.ThingKey = diff duplicateExternal.MFChannels = []bootstrap.Channel{} duplicateChannels := config duplicateChannels.ExternalID = diff - duplicateChannels.MFKey = diff - duplicateChannels.MFThing = diff + duplicateChannels.ThingKey = diff + duplicateChannels.ThingID = diff cases := []struct { desc string @@ -94,7 +94,7 @@ func TestSave(t *testing.T) { id, err := repo.Save(context.Background(), tc.config, tc.connections) assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err)) if err == nil { - assert.Equal(t, id, tc.config.MFThing, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.config.MFThing, id)) + assert.Equal(t, id, tc.config.ThingID, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.config.ThingID, id)) } } } @@ -108,8 +108,8 @@ func TestRetrieveByID(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() require.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() id, err := repo.Save(context.Background(), c, channels) @@ -168,8 +168,8 @@ func TestRetrieveAll(t *testing.T) { require.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) c.ExternalID = uid.String() c.Name = fmt.Sprintf("name %d", i) - c.MFThing = uid.String() - c.MFKey = uid.String() + c.ThingID = uid.String() + c.ThingKey = uid.String() if i%2 == 0 { c.State = bootstrap.Active @@ -245,8 +245,8 @@ func TestRetrieveByExternalID(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -283,8 +283,8 @@ func TestUpdate(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -328,8 +328,8 @@ func TestUpdateCert(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -363,13 +363,13 @@ func TestUpdateCert(t *testing.T) { }, { desc: "update a config", - thingID: c.MFThing, + thingID: c.ThingID, cert: "cert", certKey: "certKey", ca: "ca", owner: c.Owner, expectedConfig: bootstrap.Config{ - MFThing: c.MFThing, + ThingID: c.ThingID, ClientCert: "cert", CACert: "ca", ClientKey: "certKey", @@ -394,8 +394,8 @@ func TestUpdateConnections(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -403,8 +403,8 @@ func TestUpdateConnections(t *testing.T) { // Use UUID to prevent conflicts. uid, err = uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() c.MFChannels = []bootstrap.Channel{} @@ -430,7 +430,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections", owner: config.Owner, - id: c.MFThing, + id: c.ThingID, channels: nil, connections: []string{channels[1]}, err: nil, @@ -446,7 +446,7 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections no channels", owner: config.Owner, - id: c.MFThing, + id: c.ThingID, channels: nil, connections: nil, err: nil, @@ -467,8 +467,8 @@ func TestRemove(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() id, err := repo.Save(context.Background(), c, channels) @@ -494,8 +494,8 @@ func TestChangeState(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() saved, err := repo.Save(context.Background(), c, channels) @@ -550,8 +550,8 @@ func TestListExisting(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -601,8 +601,8 @@ func TestRemoveThing(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() saved, err := repo.Save(context.Background(), c, channels) @@ -622,8 +622,8 @@ func TestUpdateChannel(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -638,7 +638,7 @@ func TestUpdateChannel(t *testing.T) { err = repo.UpdateChannel(context.Background(), update) assert.Nil(t, err, fmt.Sprintf("updating config expected to succeed: %s.\n", err)) - cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.MFThing) + cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.ThingID) assert.Nil(t, err, fmt.Sprintf("Retrieving config expected to succeed: %s.\n", err)) var retreved bootstrap.Channel for _, c := range cfg.MFChannels { @@ -659,8 +659,8 @@ func TestRemoveChannel(t *testing.T) { c := config uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() _, err = repo.Save(context.Background(), c, channels) @@ -669,7 +669,7 @@ func TestRemoveChannel(t *testing.T) { err = repo.RemoveChannel(context.Background(), c.MFChannels[0].ID) assert.Nil(t, err, fmt.Sprintf("Retrieving config expected to succeed: %s.\n", err)) - cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.MFThing) + cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.ThingID) assert.Nil(t, err, fmt.Sprintf("Retrieving config expected to succeed: %s.\n", err)) assert.NotContains(t, cfg.MFChannels, c.MFChannels[0], fmt.Sprintf("expected to remove channel %s from %s", c.MFChannels[0], cfg.MFChannels)) } @@ -683,8 +683,8 @@ func TestDisconnectThing(t *testing.T) { // Use UUID to prevent conflicts. uid, err := uuid.NewV4() assert.Nil(t, err, fmt.Sprintf("Got unexpected error: %s.\n", err)) - c.MFKey = uid.String() - c.MFThing = uid.String() + c.ThingKey = uid.String() + c.ThingID = uid.String() c.ExternalID = uid.String() c.ExternalKey = uid.String() saved, err := repo.Save(context.Background(), c, channels) @@ -693,7 +693,7 @@ func TestDisconnectThing(t *testing.T) { err = repo.DisconnectThing(context.Background(), c.MFChannels[0].ID, saved) assert.Nil(t, err, fmt.Sprintf("Retrieving config expected to succeed: %s.\n", err)) - cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.MFThing) + cfg, err := repo.RetrieveByID(context.Background(), c.Owner, c.ThingID) assert.Nil(t, err, fmt.Sprintf("Retrieving config expected to succeed: %s.\n", err)) assert.Equal(t, cfg.State, bootstrap.Inactive, fmt.Sprintf("expected ti be inactive when a connection is removed from %s", cfg)) } diff --git a/bootstrap/reader.go b/bootstrap/reader.go index a627e9ca835..3c4c3b47c06 100644 --- a/bootstrap/reader.go +++ b/bootstrap/reader.go @@ -16,8 +16,8 @@ import ( // This is used as a response from ConfigReader and can easily be // replace with any other response format. type bootstrapRes struct { - MFThing string `json:"mainflux_id"` - MFKey string `json:"mainflux_key"` + ThingID string `json:"thing_id"` + ThingKey string `json:"thing_key"` MFChannels []channelRes `json:"mainflux_channels"` Content string `json:"content,omitempty"` ClientCert string `json:"client_cert,omitempty"` @@ -60,8 +60,8 @@ func (r reader) ReadConfig(cfg Config, secure bool) (interface{}, error) { } res := bootstrapRes{ - MFKey: cfg.MFKey, - MFThing: cfg.MFThing, + ThingKey: cfg.ThingKey, + ThingID: cfg.ThingID, MFChannels: channels, Content: cfg.Content, ClientCert: cfg.ClientCert, diff --git a/bootstrap/reader_test.go b/bootstrap/reader_test.go index 91485e14e5d..03e15d310f4 100644 --- a/bootstrap/reader_test.go +++ b/bootstrap/reader_test.go @@ -24,8 +24,8 @@ type readChan struct { } type readResp struct { - MFThing string `json:"mainflux_id"` - MFKey string `json:"mainflux_key"` + ThingID string `json:"thing_id"` + ThingKey string `json:"thing_key"` MFChannels []readChan `json:"mainflux_channels"` Content string `json:"content,omitempty"` ClientCert string `json:"client_cert,omitempty"` @@ -50,11 +50,11 @@ func dec(in []byte) ([]byte, error) { func TestReadConfig(t *testing.T) { cfg := bootstrap.Config{ - MFThing: "mf_id", + ThingID: "mf_id", ClientCert: "client_cert", ClientKey: "client_key", CACert: "ca_cert", - MFKey: "mf_key", + ThingKey: "mf_key", MFChannels: []bootstrap.Channel{ { ID: "mf_id", @@ -65,8 +65,8 @@ func TestReadConfig(t *testing.T) { Content: "content", } ret := readResp{ - MFThing: "mf_id", - MFKey: "mf_key", + ThingID: "mf_id", + ThingKey: "mf_key", MFChannels: []readChan{ { ID: "mf_id", diff --git a/bootstrap/redis/producer/events.go b/bootstrap/redis/producer/events.go index e1966da5d0b..1f832974fb5 100644 --- a/bootstrap/redis/producer/events.go +++ b/bootstrap/redis/producer/events.go @@ -57,8 +57,8 @@ func (ce configEvent) encode() (map[string]interface{}, error) { "state": ce.State.String(), "operation": ce.operation, } - if ce.MFThing != "" { - val["mainflux_thing"] = ce.MFThing + if ce.ThingID != "" { + val["thing_id"] = ce.ThingID } if ce.Content != "" { val["content"] = ce.Content @@ -152,8 +152,8 @@ func (be bootstrapEvent) encode() (map[string]interface{}, error) { "operation": thingBootstrap, } - if be.MFThing != "" { - val["mainflux_thing"] = be.MFThing + if be.ThingID != "" { + val["thing_id"] = be.ThingID } if be.Content != "" { val["content"] = be.Content diff --git a/bootstrap/redis/producer/streams_test.go b/bootstrap/redis/producer/streams_test.go index 1ce76ff3034..b471015a3ff 100644 --- a/bootstrap/redis/producer/streams_test.go +++ b/bootstrap/redis/producer/streams_test.go @@ -188,10 +188,10 @@ func TestView(t *testing.T) { saved, err := svc.Add(context.Background(), validToken, config) assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) - svcConfig, svcErr := svc.View(context.Background(), validToken, saved.MFThing) + svcConfig, svcErr := svc.View(context.Background(), validToken, saved.ThingID) svc = producer.NewEventStoreMiddleware(svc, redisClient) - esConfig, esErr := svc.View(context.Background(), validToken, saved.MFThing) + esConfig, esErr := svc.View(context.Background(), validToken, saved.ThingID) assert.Equal(t, svcConfig, esConfig, fmt.Sprintf("event sourcing changed service behavior: expected %v got %v", svcConfig, esConfig)) assert.Equal(t, svcErr, esErr, fmt.Sprintf("event sourcing changed service behavior: expected %v got %v", svcErr, esErr)) @@ -222,7 +222,7 @@ func TestUpdate(t *testing.T) { modified.Name = "new name" nonExisting := config - nonExisting.MFThing = "unknown" + nonExisting.ThingID = "unknown" cases := []struct { desc string @@ -237,15 +237,15 @@ func TestUpdate(t *testing.T) { token: validToken, err: nil, event: map[string]interface{}{ - "name": modified.Name, - "content": modified.Content, - "timestamp": time.Now().Unix(), - "operation": configUpdate, - "channels": "[1, 2]", - "external_id": "external_id", - "mainflux_thing": "1", - "owner": email, - "state": "0", + "name": modified.Name, + "content": modified.Content, + "timestamp": time.Now().Unix(), + "operation": configUpdate, + "channels": "[1, 2]", + "external_id": "external_id", + "thing_id": "1", + "owner": email, + "state": "0", }, }, { @@ -304,12 +304,12 @@ func TestUpdateConnections(t *testing.T) { }{ { desc: "update connections successfully", - id: saved.MFThing, + id: saved.ThingID, token: validToken, connections: []string{"2"}, err: nil, event: map[string]interface{}{ - "thing_id": saved.MFThing, + "thing_id": saved.ThingID, "channels": "2", "timestamp": time.Now().Unix(), "operation": thingUpdateConnections, @@ -317,7 +317,7 @@ func TestUpdateConnections(t *testing.T) { }, { desc: "update connections unsuccessfully", - id: saved.MFThing, + id: saved.ThingID, token: validToken, connections: []string{"256"}, err: errors.ErrMalformedEntity, @@ -388,18 +388,18 @@ func TestRemove(t *testing.T) { }{ { desc: "remove config successfully", - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, event: map[string]interface{}{ - "thing_id": saved.MFThing, + "thing_id": saved.ThingID, "timestamp": time.Now().Unix(), "operation": configRemove, }, }, { desc: "remove config with invalid credentials", - id: saved.MFThing, + id: saved.ThingID, token: "", err: errors.ErrAuthentication, event: nil, @@ -522,12 +522,12 @@ func TestChangeState(t *testing.T) { }{ { desc: "change state to active", - id: saved.MFThing, + id: saved.ThingID, token: validToken, state: bootstrap.Active, err: nil, event: map[string]interface{}{ - "thing_id": saved.MFThing, + "thing_id": saved.ThingID, "state": bootstrap.Active.String(), "timestamp": time.Now().Unix(), "operation": thingStateChange, @@ -535,7 +535,7 @@ func TestChangeState(t *testing.T) { }, { desc: "change state invalid credentials", - id: saved.MFThing, + id: saved.ThingID, token: "", state: bootstrap.Inactive, err: errors.ErrAuthentication, diff --git a/bootstrap/service.go b/bootstrap/service.go index 971c2e50a87..3a03e5543b3 100644 --- a/bootstrap/service.go +++ b/bootstrap/service.go @@ -139,28 +139,28 @@ func (bs bootstrapService) Add(ctx context.Context, token string, cfg Config) (C return Config{}, errors.Wrap(errConnectionChannels, err) } - id := cfg.MFThing + id := cfg.ThingID mfThing, err := bs.thing(id, token) if err != nil { return Config{}, errors.Wrap(errThingNotFound, err) } - cfg.MFThing = mfThing.ID + cfg.ThingID = mfThing.ID cfg.Owner = owner cfg.State = Inactive - cfg.MFKey = mfThing.Credentials.Secret + cfg.ThingKey = mfThing.Credentials.Secret saved, err := bs.configs.Save(ctx, cfg, toConnect) if err != nil { if id == "" { - if _, errT := bs.sdk.DisableThing(cfg.MFThing, token); errT != nil { + if _, errT := bs.sdk.DisableThing(cfg.ThingID, token); errT != nil { err = errors.Wrap(err, errT) } } return Config{}, errors.Wrap(errAddBootstrap, err) } - cfg.MFThing = saved + cfg.ThingID = saved cfg.MFChannels = append(cfg.MFChannels, existing...) return cfg, nil @@ -311,7 +311,7 @@ func (bs bootstrapService) ChangeState(ctx context.Context, token, id string, st for _, c := range cfg.MFChannels { conIDs := mfsdk.ConnectionIDs{ ChannelIDs: []string{c.ID}, - ThingIDs: []string{cfg.MFThing}, + ThingIDs: []string{cfg.ThingID}, } if err := bs.sdk.Connect(conIDs, token); err != nil { return ErrThings @@ -319,7 +319,7 @@ func (bs bootstrapService) ChangeState(ctx context.Context, token, id string, st } case Inactive: for _, c := range cfg.MFChannels { - if err := bs.sdk.DisconnectThing(cfg.MFThing, c.ID, token); err != nil { + if err := bs.sdk.DisconnectThing(cfg.ThingID, c.ID, token); err != nil { if errors.Contains(err, errors.ErrNotFound) { continue } diff --git a/bootstrap/service_test.go b/bootstrap/service_test.go index 92be4e8c53a..ca7012df513 100644 --- a/bootstrap/service_test.go +++ b/bootstrap/service_test.go @@ -122,7 +122,7 @@ func TestAdd(t *testing.T) { svc := newService(users, server.URL) neID := config - neID.MFThing = "non-existent" + neID.ThingID = "non-existent" wrongChannels := config ch := channel @@ -184,7 +184,7 @@ func TestView(t *testing.T) { }{ { desc: "view an existing config", - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, @@ -196,7 +196,7 @@ func TestView(t *testing.T) { }, { desc: "view a config with wrong credentials", - id: config.MFThing, + id: config.ThingID, token: invalidToken, err: errors.ErrAuthentication, }, @@ -226,7 +226,7 @@ func TestUpdate(t *testing.T) { modifiedCreated.Name = "new name" nonExisting := config - nonExisting.MFThing = unknown + nonExisting.ThingID = unknown cases := []struct { desc string @@ -285,21 +285,21 @@ func TestUpdateCert(t *testing.T) { }{ { desc: "update certs for the valid config", - thingKey: saved.MFKey, + thingKey: saved.ThingKey, clientCert: "newCert", clientKey: "newKey", caCert: "newCert", token: validToken, expectedConfig: bootstrap.Config{ Name: saved.Name, - MFKey: saved.MFKey, + ThingKey: saved.ThingKey, MFChannels: saved.MFChannels, ExternalID: saved.ExternalID, ExternalKey: saved.ExternalKey, Content: saved.Content, State: saved.State, Owner: saved.Owner, - MFThing: saved.MFThing, + ThingID: saved.ThingID, ClientCert: "newCert", CACert: "newCert", ClientKey: "newKey", @@ -318,7 +318,7 @@ func TestUpdateCert(t *testing.T) { }, { desc: "update config cert with wrong credentials", - thingKey: saved.MFKey, + thingKey: saved.ThingKey, clientCert: "newCert", clientKey: "newKey", caCert: "newCert", @@ -359,11 +359,11 @@ func TestUpdateConnections(t *testing.T) { c.ExternalID = externalID.String() active, err := svc.Add(context.Background(), validToken, c) assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) - err = svc.ChangeState(context.Background(), validToken, active.MFThing, bootstrap.Active) + err = svc.ChangeState(context.Background(), validToken, active.ThingID, bootstrap.Active) assert.Nil(t, err, fmt.Sprintf("Changing state expected to succeed: %s.\n", err)) nonExisting := config - nonExisting.MFThing = unknown + nonExisting.ThingID = unknown cases := []struct { desc string @@ -375,14 +375,14 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections for config with state Inactive", token: validToken, - id: created.MFThing, + id: created.ThingID, connections: []string{"2"}, err: nil, }, { desc: "update connections for config with state Active", token: validToken, - id: active.MFThing, + id: active.ThingID, connections: []string{"3"}, err: nil, }, @@ -396,14 +396,14 @@ func TestUpdateConnections(t *testing.T) { { desc: "update connections with invalid channels", token: validToken, - id: created.MFThing, + id: created.ThingID, connections: []string{"wrong"}, err: errors.ErrMalformedEntity, }, { desc: "update connections a config with wrong credentials", token: invalidToken, - id: created.MFKey, + id: created.ThingKey, connections: []string{"2", "3"}, err: errors.ErrAuthentication, }, @@ -540,19 +540,19 @@ func TestRemove(t *testing.T) { }{ { desc: "view a config with wrong credentials", - id: saved.MFThing, + id: saved.ThingID, token: invalidToken, err: errors.ErrAuthentication, }, { desc: "remove an existing config", - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, { desc: "remove removed config", - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, @@ -650,7 +650,7 @@ func TestChangeState(t *testing.T) { { desc: "change state with wrong credentials", state: bootstrap.Active, - id: saved.MFThing, + id: saved.ThingID, token: invalidToken, err: errors.ErrAuthentication, }, @@ -664,21 +664,21 @@ func TestChangeState(t *testing.T) { { desc: "change state to Active", state: bootstrap.Active, - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, { desc: "change state to current state", state: bootstrap.Active, - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, { desc: "change state to Inactive", state: bootstrap.Inactive, - id: saved.MFThing, + id: saved.ThingID, token: validToken, err: nil, }, @@ -775,7 +775,7 @@ func TestRemoveCoinfigHandler(t *testing.T) { }{ { desc: "remove an existing config", - id: saved.MFThing, + id: saved.ThingID, err: nil, }, { @@ -809,13 +809,13 @@ func TestDisconnectThingsHandler(t *testing.T) { { desc: "disconnect", channelID: channel.ID, - thingID: saved.MFThing, + thingID: saved.ThingID, err: nil, }, { desc: "disconnect disconnected", channelID: channel.ID, - thingID: saved.MFThing, + thingID: saved.ThingID, err: nil, }, } diff --git a/bootstrap/tracing/tracing.go b/bootstrap/tracing/tracing.go index d87a6ae8007..cbb54f5addc 100644 --- a/bootstrap/tracing/tracing.go +++ b/bootstrap/tracing/tracing.go @@ -26,7 +26,7 @@ func New(svc bootstrap.Service, tracer trace.Tracer) bootstrap.Service { // Add traces the "Add" operation of the wrapped bootstrap.Service. func (tm *tracingMiddleware) Add(ctx context.Context, token string, cfg bootstrap.Config) (bootstrap.Config, error) { ctx, span := tm.tracer.Start(ctx, "svc_register_client", trace.WithAttributes( - attribute.String("mainflux_thing", cfg.MFThing), + attribute.String("thing_id", cfg.ThingID), attribute.String("owner", cfg.Owner), attribute.String("name", cfg.Name), attribute.String("external_id", cfg.ExternalID), @@ -53,7 +53,7 @@ func (tm *tracingMiddleware) Update(ctx context.Context, token string, cfg boots ctx, span := tm.tracer.Start(ctx, "svc_update_client", trace.WithAttributes( attribute.String("name", cfg.Name), attribute.String("content", cfg.Content), - attribute.String("mainflux_thing", cfg.MFThing), + attribute.String("thing_id", cfg.ThingID), attribute.String("owner", cfg.Owner), )) defer span.End() diff --git a/cli/README.md b/cli/README.md index 015e66cac92..d3a7cc4bb8c 100644 --- a/cli/README.md +++ b/cli/README.md @@ -343,7 +343,7 @@ mainflux-cli bootstrap get -b #### Update configuration ```bash -mainflux-cli bootstrap update '{"mainflux_id":"", "name": "newName", "content": "newContent"}' -b +mainflux-cli bootstrap update '{"thing_id":"", "name": "newName", "content": "newContent"}' -b ``` #### Remove configuration diff --git a/pkg/sdk/go/bootstrap.go b/pkg/sdk/go/bootstrap.go index 505a5e82b18..33c1b125281 100644 --- a/pkg/sdk/go/bootstrap.go +++ b/pkg/sdk/go/bootstrap.go @@ -30,9 +30,9 @@ type BootstrapConfig struct { Channels []string `json:"channels,omitempty"` ExternalID string `json:"external_id,omitempty"` ExternalKey string `json:"external_key,omitempty"` - MFThing string `json:"mainflux_id,omitempty"` + ThingID string `json:"thing_id,omitempty"` MFChannels []Channel `json:"mainflux_channels,omitempty"` - MFKey string `json:"mainflux_key,omitempty"` + ThingKey string `json:"thing_key,omitempty"` Name string `json:"name,omitempty"` ClientCert string `json:"client_cert,omitempty"` ClientKey string `json:"client_key,omitempty"` @@ -90,11 +90,11 @@ func (sdk mfSDK) Whitelist(cfg BootstrapConfig, token string) errors.SDKError { return errors.NewSDKError(err) } - if cfg.MFThing == "" { + if cfg.ThingID == "" { return errors.NewSDKError(errors.ErrNotFoundParam) } - url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, whitelistEndpoint, cfg.MFThing) + url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, whitelistEndpoint, cfg.ThingID) _, _, sdkerr := sdk.processRequest(http.MethodPut, url, token, string(CTJSON), data, http.StatusCreated, http.StatusOK) @@ -122,7 +122,7 @@ func (sdk mfSDK) UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKEr return errors.NewSDKError(err) } - url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, cfg.MFThing) + url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, cfg.ThingID) _, _, sdkerr := sdk.processRequest(http.MethodPut, url, token, string(CTJSON), data, http.StatusOK) return sdkerr diff --git a/provision/service.go b/provision/service.go index a74722c7b9a..17cac8e1768 100644 --- a/provision/service.go +++ b/provision/service.go @@ -192,7 +192,7 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin if ps.conf.Bootstrap.Provision && needsBootstrap(thing) { bsReq := SDK.BootstrapConfig{ - MFThing: thing.ID, + ThingID: thing.ID, ExternalID: externalID, ExternalKey: externalKey, Channels: chanIDs, @@ -226,7 +226,7 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin res.CACert = "" if needsBootstrap(thing) { - if _, err = ps.sdk.UpdateBootstrapCerts(bsConfig.MFThing, cert.ClientCert, cert.ClientKey, "", token); err != nil { + if _, err = ps.sdk.UpdateBootstrapCerts(bsConfig.ThingID, cert.ClientCert, cert.ClientKey, "", token); err != nil { return Result{}, errors.Wrap(ErrFailedCertCreation, err) } } @@ -234,7 +234,7 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin if ps.conf.Bootstrap.AutoWhiteList { wlReq := SDK.BootstrapConfig{ - MFThing: thing.ID, + ThingID: thing.ID, State: Active, } if err := ps.sdk.Whitelist(wlReq, token); err != nil { @@ -310,10 +310,10 @@ func (ps *provisionService) updateGateway(token string, bs SDK.BootstrapConfig, } gw.ExternalID = bs.ExternalID gw.ExternalKey = bs.ExternalKey - gw.CfgID = bs.MFThing + gw.CfgID = bs.ThingID gw.Type = gateway - th, sdkerr := ps.sdk.Thing(bs.MFThing, token) + th, sdkerr := ps.sdk.Thing(bs.ThingID, token) if sdkerr != nil { return errors.Wrap(ErrGatewayUpdate, sdkerr) } @@ -383,7 +383,7 @@ func (ps *provisionService) recover(e *error, ths *[]SDK.Thing, chs *[]SDK.Chann if needsBootstrap(th) { bs, err := ps.sdk.ViewBootstrap(th.ID, token) ps.errLog(errors.Wrap(ErrFailedBootstrapRetrieval, err)) - ps.errLog(ps.sdk.RemoveBootstrap(bs.MFThing, token)) + ps.errLog(ps.sdk.RemoveBootstrap(bs.ThingID, token)) } } } @@ -398,7 +398,7 @@ func (ps *provisionService) recover(e *error, ths *[]SDK.Thing, chs *[]SDK.Chann if needsBootstrap(th) { bs, err := ps.sdk.ViewBootstrap(th.ID, token) ps.errLog(errors.Wrap(ErrFailedBootstrapRetrieval, err)) - ps.errLog(ps.sdk.RemoveBootstrap(bs.MFThing, token)) + ps.errLog(ps.sdk.RemoveBootstrap(bs.ThingID, token)) } } return