Skip to content

Commit

Permalink
feat: use dto for gethardwareinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbrache committed Oct 24, 2024
1 parent 85eb30b commit 85061b6
Show file tree
Hide file tree
Showing 15 changed files with 1,319 additions and 66 deletions.
2 changes: 1 addition & 1 deletion internal/controller/http/v1/devicemanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (r *deviceManagementRoutes) deleteAlarmOccurrences(c *gin.Context) {
func (r *deviceManagementRoutes) getHardwareInfo(c *gin.Context) {
guid := c.Param("guid")

hwInfo, err := r.d.GetHardwareInfo(c.Request.Context(), guid)
hwInfo, _, err := r.d.GetHardwareInfo(c.Request.Context(), guid)
if err != nil {
r.l.Error(err, "http - v1 - getHardwareInfo")
ErrorResponse(c, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/http/v1/devicemanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func TestDeviceManagement(t *testing.T) {
method: http.MethodGet,
mock: func(m *mocks.MockDeviceManagementFeature) {
m.EXPECT().GetHardwareInfo(context.Background(), "valid-guid").
Return(map[string]interface{}{"hardware": "info"}, nil)
Return(dto.HardwareInfoResults{}, dtov2.HardwareInfoResults{}, nil)
},
expectedCode: http.StatusOK,
response: map[string]interface{}{"hardware": "info"},
response: dto.HardwareInfoResults{},
},
{
name: "getDiskInfo - successful retrieval",
Expand Down
15 changes: 15 additions & 0 deletions internal/controller/http/v2/devicemanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewAmtRoutes(handler *gin.RouterGroup, d devices.Feature, l logger.Interfac
h.GET("version/:guid", r.getVersion)
h.GET("features/:guid", r.getFeatures)
h.POST("features/:guid", r.setFeatures)
h.GET("hardwareInfo/:guid", r.getHardwareInfo)
}
}

Expand Down Expand Up @@ -77,3 +78,17 @@ func (r *deviceManagementRoutes) setFeatures(c *gin.Context) {

c.JSON(http.StatusOK, v2)
}

func (r *deviceManagementRoutes) getHardwareInfo(c *gin.Context) {
guid := c.Param("guid")

_, hwInfo, err := r.d.GetHardwareInfo(c.Request.Context(), guid)
if err != nil {
r.l.Error(err, "http - v2 - getHardwareInfo")
v1.ErrorResponse(c, err)

return
}

Check warning on line 91 in internal/controller/http/v2/devicemanagement.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/http/v2/devicemanagement.go#L87-L91

Added lines #L87 - L91 were not covered by tests

c.JSON(http.StatusOK, hwInfo)
}
11 changes: 11 additions & 0 deletions internal/controller/http/v2/devicemanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ func TestDeviceManagement(t *testing.T) {
requestBody: featuresInput,
response: featuresOutput,
},
{
name: "getHardwareInfo - successful retrieval",
url: "/api/v2/amt/hardwareInfo/valid-guid",
method: http.MethodGet,
mock: func(m *mocks.MockDeviceManagementFeature) {
m.EXPECT().GetHardwareInfo(context.Background(), "valid-guid").
Return(dto.HardwareInfoResults{}, dtov2.HardwareInfoResults{}, nil)
},
expectedCode: http.StatusOK,
response: dtov2.HardwareInfoResults{},
},
}

for _, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/ws/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Feature interface {
GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error)
CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrenceInput) (dto.AddAlarmOutput, error)
DeleteAlarmOccurrences(ctx context.Context, guid, instanceID string) error
GetHardwareInfo(ctx context.Context, guid string) (interface{}, error)
GetHardwareInfo(ctx context.Context, guid string) (dto.HardwareInfoResults, dtov2.HardwareInfoResults, error)
GetPowerState(ctx context.Context, guid string) (dto.PowerState, error)
GetPowerCapabilities(ctx context.Context, guid string) (dto.PowerCapabilities, error)
GetGeneralSettings(ctx context.Context, guid string) (interface{}, error)
Expand Down
202 changes: 202 additions & 0 deletions internal/entity/dto/v1/hardwareinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package dto

type (
HardwareInfoResults struct {
CIMComputerSystemPackage CIMComputerSystemPackage
CIMSystemPackage CIMSystemPackage
CIMChassis CIMChassis
CIMChip CIMChips `json:"CIMChip" binding:"required"`
CIMCard CIMCard
CIMBIOSElement CIMBIOSElement
CIMProcessor CIMProcessor
CIMPhysicalPackage CIMPhysicalPackage
CIMPhysicalMemory CIMPhysicalMemory
CIMMediaAccessDevice CIMMediaAccessDevice
}

CIMBIOSElement struct {
Response CIMBIOSElementResponse `json:"response"`
Responses []any `json:"responses"`
}

CIMCard struct {
Response CIMCardResponseGet `json:"response"`
Responses []any `json:"responses"`
}

CIMChassis struct {
Response CIMChassisResponse `json:"response"`
Responses []any `json:"responses"`
}

CIMChips struct {
Responses []CIMChipGet `json:"responses"`
}

CIMComputerSystemPackage struct {
// PlatformGUID string
Response string `json:"response"`
Responses string `json:"responses"`
}

CIMMediaAccessDevices struct {
Responses []CIMMediaAccessDevice `json:"responses"`
}

CIMPhysicalMemory struct {
Responses []CIMPhysicalMemoryResponse `json:"responses"`
}

CIMPhysicalPackage struct {
Responses []CIMPhysicalPackageResponses `json:"responses"`
}

CIMProcessor struct {
Responses []CIMProcessorResponse `json:"responses"`
}

CIMSystemPackage struct {
Responses []CIMSystemPackagingResponses `json:"responses"`
}

CIMSystemPackagingResponses struct {
SystemPackageItems any
}

CIMChassisResponse struct {
Version string
SerialNumber string
Model string
Manufacturer string
ElementName string
CreationClassName string
Tag string
OperationalStatus []int
PackageType int
ChassisPackageType int
}

CIMBIOSElementResponse struct {
TargetOperatingSystem TargetOperatingSystem
SoftwareElementID string
SoftwareElementState SoftwareElementState
Name string
OperationalStatus []int
ElementName string
Version string
Manufacturer string
PrimaryBIOS bool
ReleaseDate Time
}

CIMChip struct {
Pull []any
Get CIMChipGet
}

CIMChipGet struct {
CanBeFRUed bool
CreationClassName string
ElementName string
Manufacturer string
OperationalStatus []int
Tag string
Version string
}

CIMProcessorResponse struct {
DeviceID string
CreationClassName string
SystemName string
SystemCreationClassName string
ElementName string
OperationalStatus []int
HealthState int
EnabledState int
RequestedState int
Role string
Family int
OtherFamilyDescription string
UpgradeMethod int
MaxClockSpeed int
CurrentClockSpeed int
Stepping string
CPUStatus int
ExternalBusClockSpeed int
}

CIMMediaAccessDevice struct {
Pull []any
Get struct {
Capabilities []int
CreationClassName string
DeviceID string
ElementName string
EnabledDefault int
EnabledState int
MaxMediaSize int
OperationalStatus []int
RequestedState int
Security int
SystemCreationClassName string
SystemName string
}
}

CIMPhysicalMemoryResponse struct {
PartNumber string
SerialNumber string
Manufacturer string
ElementName string
CreationClassName string
Tag string
OperationalStatus []int
FormFactor int
MemoryType int
Speed int
Capacity int
BankLabel string
ConfiguredMemoryClockSpeed int
IsSpeedInMhz bool
MaxMemorySpeed int
}

CIMPhysicalPackageResponses struct {
PullMemoryItems []any
PullCardItems []any
}

CIMCardResponse struct {
Pull []any
Get CIMCardResponseGet
}

CIMCardResponseGet struct {
CanBeFRUed bool
CreationClassName string
ElementName string
Manufacturer string
Model string
OperationalStatus []int
PackageType int
SerialNumber string
Tag string
Version string
}

Time struct {
DateTime string `xml:"Datetime"`
}

// ChassisPackageType is an enumeration defining the type of the PhysicalPackage.
ChassisPackageType int

// PackageType is the type of the PhysicalPackage.
PackageType int

// TargetOperatingSystem is the element's operating system environment.
TargetOperatingSystem int

// SoftwareElementState is defined in this model to identify various states of a SoftwareElement's life cycle.
SoftwareElementState int
)
Loading

0 comments on commit 85061b6

Please sign in to comment.