Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*********************************************************************
* Copyright (c) Intel Corporation 2026
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

ALTER TABLE devices DROP COLUMN currentmode;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*********************************************************************
* Copyright (c) Intel Corporation 2026
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

ALTER TABLE devices ADD COLUMN currentmode TEXT;
2 changes: 2 additions & 0 deletions internal/entity/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Device struct {
UseTLS bool `bson:"usetls"`
AllowSelfSigned bool `bson:"allowselfsigned"`
CertHash *string `bson:"certhash"`
// Queryable mirror of the deviceinfo currentMode JSON field, synced on every insert/update.
CurrentMode string `bson:"currentmode"`
}
Comment thread
ShradhaGupta31 marked this conversation as resolved.

type Explorer struct {
Expand Down
5 changes: 5 additions & 0 deletions internal/usecase/devices/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (uc *UseCase) dtoToEntity(d *dto.Device) (*entity.Device, error) {
AllowSelfSigned: d.AllowSelfSigned,
}

// Sync the queryable mirror column from the deviceinfo blob (source of truth).
if d.DeviceInfo != nil {
d1.CurrentMode = d.DeviceInfo.CurrentMode
}

d1.Password, err = uc.safeRequirements.Encrypt(d1.Password)
if err != nil {
return nil, ErrDeviceUseCase.Wrap("dtoToEntity", "failed to encrypt password", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/usecase/nosqldb/mongo/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type deviceUpdateFields struct {
UseTLS bool `bson:"usetls"`
AllowSelfSigned bool `bson:"allowselfsigned"`
CertHash *string `bson:"certhash"`
CurrentMode string `bson:"currentmode"`
}

type deviceUpdateDocument struct {
Expand Down Expand Up @@ -247,6 +248,7 @@ func (r *DeviceRepo) Update(ctx context.Context, d *entity.Device) (bool, error)
UseTLS: d.UseTLS,
AllowSelfSigned: d.AllowSelfSigned,
CertHash: d.CertHash,
CurrentMode: d.CurrentMode,
}},
)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/usecase/sqldb/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func (r *DeviceRepo) Update(_ context.Context, d *entity.Device) (bool, error) {
Set("useTLS", d.UseTLS).
Set("allowSelfSigned", d.AllowSelfSigned).
Set("certhash", d.CertHash).
Set("currentmode", d.CurrentMode).
Where("guid = ? AND tenantid = ?", d.GUID, d.TenantID).
ToSql()
if err != nil {
Expand Down Expand Up @@ -420,8 +421,8 @@ func (r *DeviceRepo) UpdateLastSeen(_ context.Context, guid string) error {
func (r *DeviceRepo) Insert(_ context.Context, d *entity.Device) (string, error) {
insertBuilder := r.Builder.
Insert("devices").
Columns("guid", "hostname", "tags", "mpsinstance", "connectionstatus", "mpsusername", "tenantid", "friendlyname", "dnssuffix", "deviceinfo", "username", "password", "mpspassword", "mebxpassword", "usetls", "allowselfsigned", "certhash").
Values(d.GUID, d.Hostname, d.Tags, d.MPSInstance, d.ConnectionStatus, d.MPSUsername, d.TenantID, d.FriendlyName, d.DNSSuffix, d.DeviceInfo, d.Username, d.Password, d.MPSPassword, d.MEBXPassword, d.UseTLS, d.AllowSelfSigned, d.CertHash)
Columns("guid", "hostname", "tags", "mpsinstance", "connectionstatus", "mpsusername", "tenantid", "friendlyname", "dnssuffix", "deviceinfo", "username", "password", "mpspassword", "mebxpassword", "usetls", "allowselfsigned", "certhash", "currentmode").
Values(d.GUID, d.Hostname, d.Tags, d.MPSInstance, d.ConnectionStatus, d.MPSUsername, d.TenantID, d.FriendlyName, d.DNSSuffix, d.DeviceInfo, d.Username, d.Password, d.MPSPassword, d.MEBXPassword, d.UseTLS, d.AllowSelfSigned, d.CertHash, d.CurrentMode)

if !r.IsEmbedded {
insertBuilder = insertBuilder.Suffix("RETURNING xmin::text")
Expand Down
4 changes: 3 additions & 1 deletion internal/usecase/sqldb/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func setupDeviceTable(t *testing.T) *sql.DB {
usetls BOOLEAN NOT NULL DEFAULT FALSE,
allowselfsigned BOOLEAN NOT NULL DEFAULT FALSE,
certhash TEXT NOT NULL DEFAULT '',
currentmode TEXT,
lastconnected TEXT,
lastdisconnected TEXT,
lastseen TEXT
Expand Down Expand Up @@ -815,7 +816,8 @@ func TestDeviceRepo_Update(t *testing.T) {
mebxpassword TEXT,
usetls BOOLEAN NOT NULL DEFAULT FALSE,
allowselfsigned BOOLEAN NOT NULL DEFAULT FALSE,
certhash TEXT NOT NULL DEFAULT ''
certhash TEXT NOT NULL DEFAULT '',
currentmode TEXT
);
`)
require.NoError(t, err)
Expand Down
Loading