Skip to content
Draft
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 islmsavailable;
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 islmsavailable BOOLEAN NOT NULL DEFAULT FALSE;
1 change: 1 addition & 0 deletions internal/entity/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Device struct {
UseTLS bool
AllowSelfSigned bool
CertHash *string
IsLMSAvailable bool
}

type Explorer struct {
Expand Down
1 change: 1 addition & 0 deletions internal/entity/dto/v1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Device struct {
UseTLS bool `json:"useTLS"`
AllowSelfSigned bool `json:"allowSelfSigned"`
CertHash string `json:"certHash"`
IsLMSAvailable bool `json:"isLMSAvailable"`
}

type DeviceInfo struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/usecase/devices/transform_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func FuzzDeviceTransforms(f *testing.F) {
UseTLS: useTLS,
AllowSelfSigned: allowSelfSigned,
CertHash: certHash,
IsLMSAvailable: connectionStatus,
LastConnected: buildTimePtr(),
LastSeen: buildTimePtr(),
LastDisconnected: buildTimePtr(),
Expand All @@ -90,6 +91,7 @@ func FuzzDeviceTransforms(f *testing.F) {
UseTLS: useTLS,
AllowSelfSigned: allowSelfSigned,
CertHash: stringPtrOrNilDevice(certHash),
IsLMSAvailable: connectionStatus,
LastConnected: buildTimePtr(),
LastSeen: buildTimePtr(),
LastDisconnected: buildTimePtr(),
Expand Down
2 changes: 2 additions & 0 deletions internal/usecase/devices/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (uc *UseCase) dtoToEntity(d *dto.Device) (*entity.Device, error) {
Password: d.Password,
UseTLS: d.UseTLS,
AllowSelfSigned: d.AllowSelfSigned,
IsLMSAvailable: d.IsLMSAvailable,
}
Comment thread
sinchubhat marked this conversation as resolved.

var err error
Expand Down Expand Up @@ -158,6 +159,7 @@ func (uc *UseCase) entityToDTO(d *entity.Device) *dto.Device {
// Password: d.Password,
UseTLS: d.UseTLS,
AllowSelfSigned: d.AllowSelfSigned,
IsLMSAvailable: d.IsLMSAvailable,
}

if d.CertHash != nil {
Expand Down
20 changes: 12 additions & 8 deletions internal/usecase/sqldb/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (r *DeviceRepo) Get(_ context.Context, top, skip int, tenantID string) ([]e
"password",
"usetls",
"allowselfsigned",
"certhash").
"certhash",
"islmsavailable").
From("devices").
Where("tenantid = ?", tenantID).
OrderBy("guid").
Expand All @@ -114,7 +115,7 @@ func (r *DeviceRepo) Get(_ context.Context, top, skip int, tenantID string) ([]e
for rows.Next() {
d := entity.Device{}

err = rows.Scan(&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.UseTLS, &d.AllowSelfSigned, &d.CertHash)
err = rows.Scan(&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.UseTLS, &d.AllowSelfSigned, &d.CertHash, &d.IsLMSAvailable)
if err != nil {
return nil, ErrDeviceDatabase.Wrap("Get", "rows.Scan: ", err)
}
Expand Down Expand Up @@ -145,7 +146,8 @@ func (r *DeviceRepo) GetByID(_ context.Context, guid, tenantID string) (*entity.
"mebxpassword",
"usetls",
"allowselfsigned",
"certhash").
"certhash",
"islmsavailable").
From("devices").
Where("guid = ? and tenantid = ?").
ToSql()
Expand All @@ -169,7 +171,7 @@ func (r *DeviceRepo) GetByID(_ context.Context, guid, tenantID string) (*entity.
for rows.Next() {
d := &entity.Device{}

err = rows.Scan(&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)
err = rows.Scan(&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.IsLMSAvailable)
if err != nil {
return d, ErrDeviceDatabase.Wrap("Get", "rows.Scan: ", err)
}
Expand Down Expand Up @@ -346,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("islmsavailable", d.IsLMSAvailable).
Where("guid = ? AND tenantid = ?", d.GUID, d.TenantID).
ToSql()
if err != nil {
Expand Down Expand Up @@ -418,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", "islmsavailable").
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.IsLMSAvailable)

Comment thread
sinchubhat marked this conversation as resolved.
if !r.IsEmbedded {
insertBuilder = insertBuilder.Suffix("RETURNING xmin::text")
Expand Down Expand Up @@ -466,7 +469,8 @@ func (r *DeviceRepo) GetByColumn(_ context.Context, columnName, queryValue, tena
"password",
"usetls",
"allowselfsigned",
"certhash").
"certhash",
"islmsavailable").
From("devices").
Where(columnName+" = ? AND tenantid = ?", queryValue, tenantID).
ToSql()
Expand All @@ -490,7 +494,7 @@ func (r *DeviceRepo) GetByColumn(_ context.Context, columnName, queryValue, tena
for rows.Next() {
d := entity.Device{}

err = rows.Scan(&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.UseTLS, &d.AllowSelfSigned, &d.CertHash)
err = rows.Scan(&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.UseTLS, &d.AllowSelfSigned, &d.CertHash, &d.IsLMSAvailable)
if err != nil {
return nil, ErrDeviceDatabase.Wrap("Get", "rows.Scan: ", err)
}
Expand Down
59 changes: 55 additions & 4 deletions internal/usecase/sqldb/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func setupDeviceTable(t *testing.T) *sql.DB {
certhash TEXT NOT NULL DEFAULT '',
lastconnected TEXT,
lastdisconnected TEXT,
lastseen TEXT
lastseen TEXT,
islmsavailable BOOLEAN NOT NULL DEFAULT FALSE
Comment thread
sinchubhat marked this conversation as resolved.
);
`)
require.NoError(t, err)
Expand Down Expand Up @@ -662,7 +663,8 @@ func TestDeviceRepo_Delete(t *testing.T) {
mpspassword TEXT,
mebxpassword TEXT,
usetls BOOLEAN NOT NULL DEFAULT FALSE,
allowselfsigned BOOLEAN NOT NULL DEFAULT FALSE
allowselfsigned BOOLEAN NOT NULL DEFAULT FALSE,
islmsavailable BOOLEAN NOT NULL DEFAULT FALSE
);
`)
require.NoError(t, err)
Expand Down Expand Up @@ -813,7 +815,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 '',
islmsavailable BOOLEAN NOT NULL DEFAULT FALSE
);
`)
require.NoError(t, err)
Expand Down Expand Up @@ -1068,7 +1071,8 @@ func TestDeviceRepo_GetByColumn(t *testing.T) {
password TEXT NOT NULL DEFAULT '',
usetls BOOLEAN NOT NULL DEFAULT FALSE,
allowselfsigned BOOLEAN NOT NULL DEFAULT FALSE,
certhash TEXT NOT NULL DEFAULT ''
certhash TEXT NOT NULL DEFAULT '',
islmsavailable BOOLEAN NOT NULL DEFAULT FALSE
);
`)
require.NoError(t, err)
Expand Down Expand Up @@ -1290,3 +1294,50 @@ func TestDeviceRepo_UpdateLastSeen(t *testing.T) {
})
}
}

func TestDeviceRepo_IsLMSAvailable_RoundTrip(t *testing.T) {
t.Parallel()

dbConn := setupDeviceTable(t)
defer dbConn.Close()

sqlConfig := &db.SQL{
Builder: squirrel.StatementBuilder.PlaceholderFormat(squirrel.Question),
Pool: dbConn,
IsEmbedded: true,
}

mockLog := mocks.NewMockLogger(nil)
repo := sqldb.NewDeviceRepo(sqlConfig, mockLog)

// Insert a device with IsLMSAvailable = true
dev := &entity.Device{
GUID: "guid-lms-true",
Hostname: "host-lms",
TenantID: "tenant1",
Username: "admin",
Password: "pass",
CertHash: Certhash,
IsLMSAvailable: true,
}

_, err := repo.Insert(context.Background(), dev)
require.NoError(t, err)

// Retrieve and verify the field round-trips
got, err := repo.GetByID(context.Background(), "guid-lms-true", "tenant1")
require.NoError(t, err)
require.NotNil(t, got)
assert.True(t, got.IsLMSAvailable, "IsLMSAvailable should be true after insert")

// Update the device with IsLMSAvailable = false
dev.IsLMSAvailable = false

_, err = repo.Update(context.Background(), dev)
require.NoError(t, err)

got, err = repo.GetByID(context.Background(), "guid-lms-true", "tenant1")
require.NoError(t, err)
require.NotNil(t, got)
assert.False(t, got.IsLMSAvailable, "IsLMSAvailable should be false after update")
}
Loading