Skip to content

Commit

Permalink
feat: adds certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel committed May 3, 2024
1 parent f44527f commit 938298e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/controller/http/v1/devicemanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newAmtRoutes(handler *gin.RouterGroup, d devices.Feature, l logger.Interfac
h.POST("userConsentCode/:guid", r.sendConsentCode)

h.GET("networkSettings/:guid", r.getNetworkSettings)
h.GET("certificates/:guid", r.getCertificates)
}
}

Expand Down Expand Up @@ -350,3 +351,17 @@ func (r *deviceManagementRoutes) getNetworkSettings(c *gin.Context) {

c.JSON(http.StatusOK, network)
}

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

network, err := r.d.GetCertificates(c, guid)
if err != nil {
r.l.Error(err, "http - v1 - getCertificates")
errorResponse(c, http.StatusInternalServerError, "problems")

return
}

Check failure on line 364 in internal/controller/http/v1/devicemanagement.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 too many arguments in call to errorResponse Raw Output: internal/controller/http/v1/devicemanagement.go:364:52: too many arguments in call to errorResponse have (*gin.Context, number, string) want (*gin.Context, error) (typecheck) errorResponse(c, http.StatusInternalServerError, "problems") ^

c.JSON(http.StatusOK, network)
}
23 changes: 23 additions & 0 deletions internal/usecase/devices/certificates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package devices

import (
"context"

"github.com/open-amt-cloud-toolkit/console/internal/usecase/utils"
)

func (uc *UseCase) GetCertificates(c context.Context, guid string) (interface{}, error) {
item, err := uc.repo.GetByID(c, guid, "")
if err != nil || item.GUID == "" {
return nil, utils.ErrNotFound
}

uc.device.SetupWsmanClient(item, false, true)

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient (typecheck) Raw Output: internal/usecase/devices/certificates.go:15:29: cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient (typecheck) package devices

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) Raw Output: internal/usecase/devices/certificates.go:15:29: cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" ^

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) Raw Output: internal/usecase/devices/certificates.go:15:29: cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" ^

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) Raw Output: internal/usecase/devices/certificates.go:15:29: cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient) (typecheck) "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" ^

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.21.x, windows-2019)

cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient

Check failure on line 15 in internal/usecase/devices/certificates.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.21.x, ubuntu-20.04)

cannot use item (variable of type *entity.Device) as entity.Device value in argument to uc.device.SetupWsmanClient

response, err := uc.device.GetCertificates()
if err != nil {
return nil, err
}

return response, nil
}
2 changes: 2 additions & 0 deletions internal/usecase/devices/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type (
GetAuditLog(startIndex int) (auditlog.Response, error)
GetEventLog() (messagelog.GetRecordsResponse, error)
GetNetworkSettings() (interface{}, error)
GetCertificates() (interface{}, error)
}
Redirection interface {
SetupWsmanClient(device entity.Device, isRedirection, logAMTMessages bool) wsman.Messages
Expand Down Expand Up @@ -95,5 +96,6 @@ type (
GetEventLog(ctx context.Context, guid string) (messagelog.GetRecordsResponse, error)
Redirect(ctx context.Context, conn *websocket.Conn, guid, mode string) error
GetNetworkSettings(c context.Context, guid string) (interface{}, error)
GetCertificates(c context.Context, guid string) (interface{}, error)
}
)
30 changes: 30 additions & 0 deletions internal/usecase/devices/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/usecase/devices/wsman/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,18 @@ func (g *GoWSMANMessages) GetNetworkSettings() (interface{}, error) {

return networkResults, nil
}

func (g *GoWSMANMessages) GetCertificates() (interface{}, error) {
// certificates := map[string]interface{}{}
response, err := g.wsmanMessages.AMT.TLSCredentialContext.Enumerate()
if err != nil {
return nil, err
}

response, err = g.wsmanMessages.AMT.TLSCredentialContext.Pull(response.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}

return response, nil
}

0 comments on commit 938298e

Please sign in to comment.