Skip to content

Commit ccda608

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix_494
2 parents 2cf451a + 4066c84 commit ccda608

27 files changed

+416
-37
lines changed

.github/workflows/docker-build.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ jobs:
4646
latest=false
4747
tags: |
4848
type=ref,enable=true,event=branch,suffix=-collector
49-
type=ref,enable=true,event=tag,suffix=-collector
49+
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-collector
50+
type=semver,pattern=v{{major}}.{{minor}},suffix=-collector
51+
type=semver,pattern=v{{major}},suffix=-collector
5052
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5153

5254
# Build and push Docker image with Buildx (don't push on PR)
@@ -99,7 +101,9 @@ jobs:
99101
latest=false
100102
tags: |
101103
type=ref,enable=true,event=branch,suffix=-web
102-
type=ref,enable=true,event=tag,suffix=-web
104+
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-web
105+
type=semver,pattern=v{{major}}.{{minor}},suffix=-web
106+
type=semver,pattern=v{{major}},suffix=-web
103107
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
104108
# Build and push Docker image with Buildx (don't push on PR)
105109
# https://github.com/docker/build-push-action
@@ -148,7 +152,9 @@ jobs:
148152
with:
149153
tags: |
150154
type=ref,enable=true,event=branch,suffix=-omnibus
151-
type=ref,enable=true,event=tag,suffix=-omnibus
155+
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-omnibus
156+
type=semver,pattern=v{{major}}.{{minor}},suffix=-omnibus
157+
type=semver,pattern=v{{major}},suffix=-omnibus
152158
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
153159
# Build and push Docker image with Buildx (don't push on PR)
154160
# https://github.com/docker/build-push-action

docs/dbdiagram.io.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SQLite Table(s)
33

44
Table Device {
5+
Archived bool
56
//GORM attributes, see: http://gorm.io/docs/conventions.html
67
CreatedAt time
78
UpdatedAt time

webapp/backend/pkg/database/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type DeviceRepo interface {
2020
UpdateDevice(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (models.Device, error)
2121
UpdateDeviceStatus(ctx context.Context, wwn string, status pkg.DeviceStatus) (models.Device, error)
2222
GetDeviceDetails(ctx context.Context, wwn string) (models.Device, error)
23+
UpdateDeviceArchived(ctx context.Context, wwn string, archived bool) error
2324
DeleteDevice(ctx context.Context, wwn string) error
2425

2526
SaveSmartAttributes(ctx context.Context, wwn string, collectorSmartData collector.SmartInfo) (measurements.Smart, error)

webapp/backend/pkg/database/migrations/m20220509170100/device.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66
)
77

8+
// Deprecated: m20220509170100.Device is deprecated, only used by db migrations
89
type Device struct {
910
//GORM attributes, see: http://gorm.io/docs/conventions.html
1011
CreatedAt time.Time
@@ -14,9 +15,9 @@ type Device struct {
1415
WWN string `json:"wwn" gorm:"primary_key"`
1516

1617
DeviceName string `json:"device_name"`
17-
DeviceUUID string `json:"device_uuid"`
18-
DeviceSerialID string `json:"device_serial_id"`
19-
DeviceLabel string `json:"device_label"`
18+
DeviceUUID string `json:"device_uuid"`
19+
DeviceSerialID string `json:"device_serial_id"`
20+
DeviceLabel string `json:"device_label"`
2021

2122
Manufacturer string `json:"manufacturer"`
2223
ModelName string `json:"model_name"`
@@ -38,4 +39,3 @@ type Device struct {
3839
// Data set by Scrutiny
3940
DeviceStatus pkg.DeviceStatus `json:"device_status"`
4041
}
41-
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package m20250221084400
2+
3+
import (
4+
"github.com/analogj/scrutiny/webapp/backend/pkg"
5+
"time"
6+
)
7+
8+
type Device struct {
9+
Archived bool `json:"archived"`
10+
//GORM attributes, see: http://gorm.io/docs/conventions.html
11+
CreatedAt time.Time
12+
UpdatedAt time.Time
13+
DeletedAt *time.Time
14+
15+
WWN string `json:"wwn" gorm:"primary_key"`
16+
17+
DeviceName string `json:"device_name"`
18+
DeviceUUID string `json:"device_uuid"`
19+
DeviceSerialID string `json:"device_serial_id"`
20+
DeviceLabel string `json:"device_label"`
21+
22+
Manufacturer string `json:"manufacturer"`
23+
ModelName string `json:"model_name"`
24+
InterfaceType string `json:"interface_type"`
25+
InterfaceSpeed string `json:"interface_speed"`
26+
SerialNumber string `json:"serial_number"`
27+
Firmware string `json:"firmware"`
28+
RotationSpeed int `json:"rotational_speed"`
29+
Capacity int64 `json:"capacity"`
30+
FormFactor string `json:"form_factor"`
31+
SmartSupport bool `json:"smart_support"`
32+
DeviceProtocol string `json:"device_protocol"` //protocol determines which smart attribute types are available (ATA, NVMe, SCSI)
33+
DeviceType string `json:"device_type"` //device type is used for querying with -d/t flag, should only be used by collector.
34+
35+
// User provided metadata
36+
Label string `json:"label"`
37+
HostId string `json:"host_id"`
38+
39+
// Data set by Scrutiny
40+
DeviceStatus pkg.DeviceStatus `json:"device_status"`
41+
}

webapp/backend/pkg/database/mock/mock_database.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/backend/pkg/database/scrutiny_repository_device.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// Device
1515
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1616

17-
//insert device into DB (and update specified columns if device is already registered)
17+
// insert device into DB (and update specified columns if device is already registered)
1818
// update device fields that may change: (DeviceType, HostID)
1919
func (sr *scrutinyRepository) RegisterDevice(ctx context.Context, dev models.Device) error {
2020
if err := sr.gormClient.WithContext(ctx).Clauses(clause.OnConflict{
@@ -51,7 +51,7 @@ func (sr *scrutinyRepository) UpdateDevice(ctx context.Context, wwn string, coll
5151
return device, sr.gormClient.Model(&device).Updates(device).Error
5252
}
5353

54-
//Update Device Status
54+
// Update Device Status
5555
func (sr *scrutinyRepository) UpdateDeviceStatus(ctx context.Context, wwn string, status pkg.DeviceStatus) (models.Device, error) {
5656
var device models.Device
5757
if err := sr.gormClient.WithContext(ctx).Where("wwn = ?", wwn).First(&device).Error; err != nil {
@@ -74,6 +74,16 @@ func (sr *scrutinyRepository) GetDeviceDetails(ctx context.Context, wwn string)
7474
return device, nil
7575
}
7676

77+
// Update Device Archived State
78+
func (sr *scrutinyRepository) UpdateDeviceArchived(ctx context.Context, wwn string, archived bool) error {
79+
var device models.Device
80+
if err := sr.gormClient.WithContext(ctx).Where("wwn = ?", wwn).First(&device).Error; err != nil {
81+
return fmt.Errorf("Could not get device from DB: %v", err)
82+
}
83+
84+
return sr.gormClient.Model(&device).Where("wwn = ?", wwn).Update("archived", archived).Error
85+
}
86+
7787
func (sr *scrutinyRepository) DeleteDevice(ctx context.Context, wwn string) error {
7888
if err := sr.gormClient.WithContext(ctx).Where("wwn = ?", wwn).Delete(&models.Device{}).Error; err != nil {
7989
return err

webapp/backend/pkg/database/scrutiny_repository_migrations.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220503120000"
1313
"github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220509170100"
1414
"github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220716214900"
15+
"github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20250221084400"
1516
"github.com/analogj/scrutiny/webapp/backend/pkg/models"
1617
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
1718
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
@@ -400,7 +401,16 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error {
400401
},
401402
},
402403
{
403-
ID: "m20240804113900", // add retrieve_sct_history setting.
404+
ID: "m20250221084400", // add archived to device data
405+
Migrate: func(tx *gorm.DB) error {
406+
407+
//migrate the device database.
408+
// adding column (archived)
409+
return tx.AutoMigrate(m20250221084400.Device{})
410+
},
411+
},
412+
{
413+
ID: "m20250609210800", // add retrieve_sct_history setting.
404414
Migrate: func(tx *gorm.DB) error {
405415
//add retrieve_sct_history setting default.
406416
var defaultSettings = []m20220716214900.Setting{

webapp/backend/pkg/models/device.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type DeviceWrapper struct {
1414

1515
type Device struct {
1616
//GORM attributes, see: http://gorm.io/docs/conventions.html
17+
Archived bool `json:"archived"`
1718
CreatedAt time.Time
1819
UpdatedAt time.Time
1920
DeletedAt *time.Time
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package handler
2+
3+
import (
4+
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
5+
"github.com/gin-gonic/gin"
6+
"github.com/sirupsen/logrus"
7+
"net/http"
8+
)
9+
10+
func ArchiveDevice(c *gin.Context) {
11+
logger := c.MustGet("LOGGER").(*logrus.Entry)
12+
deviceRepo := c.MustGet("DEVICE_REPOSITORY").(database.DeviceRepo)
13+
14+
err := deviceRepo.UpdateDeviceArchived(c, c.Param("wwn"), true)
15+
if err != nil {
16+
logger.Errorln("An error occurred while archiving device", err)
17+
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
18+
return
19+
}
20+
21+
c.JSON(http.StatusOK, gin.H{"success": true})
22+
}

0 commit comments

Comments
 (0)