Skip to content

Commit

Permalink
feat: adds certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel authored and rjbrache committed May 14, 2024
1 parent f44527f commit 8664c16
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 2 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 dto.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 dto.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 dto.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 dto.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 dto.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 dto.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 dto.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 dto.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 dto.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 dto.Device value in argument to uc.device.SetupWsmanClient) (typecheck) devices "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 dto.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-22.04)

cannot use item (variable of type *entity.Device) as dto.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 dto.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.22.x, windows-2019)

cannot use item (variable of type *entity.Device) as dto.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.22.x, windows-2022)

cannot use item (variable of type *entity.Device) as dto.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.22.x, ubuntu-22.04)

cannot use item (variable of type *entity.Device) as dto.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.22.x, ubuntu-20.04)

cannot use item (variable of type *entity.Device) as dto.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.

80 changes: 78 additions & 2 deletions internal/usecase/devices/wsman/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wsman
import (
"strings"
"time"
"fmt"

"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman"
amtAlarmClock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock"
Expand Down Expand Up @@ -41,6 +42,7 @@ import (
ipsAlarmClock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/alarmclock"
ipsIEEE8021x "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/ieee8021x"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/optin"
// "github.com/rs/zerolog/log"

"github.com/open-amt-cloud-toolkit/console/internal/entity"
"github.com/open-amt-cloud-toolkit/console/internal/entity/dto"
Expand Down Expand Up @@ -196,9 +198,9 @@ func (g *GoWSMANMessages) SetFeatures(features dto.Features) (dto.Features, erro
}

func configureKVM(features dto.Features, listenerEnabled int, g *GoWSMANMessages) (int, error) {

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.22.x, windows-2022)

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.22.x, ubuntu-22.04)

undefined: kvm.RedirectionSAPDisable

Check failure on line 200 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPDisable
kvmRequestedState := kvm.RedirectionSAP_Disable
kvmRequestedState := kvm.RedirectionSAPDisable
if features.EnableKVM {

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.22.x, windows-2022)

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

GitHub Actions / runner / build and tests (1.22.x, ubuntu-22.04)

undefined: kvm.RedirectionSAPEnable

Check failure on line 202 in internal/usecase/devices/wsman/message.go

View workflow job for this annotation

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

undefined: kvm.RedirectionSAPEnable
kvmRequestedState = kvm.RedirectionSAP_Enable
kvmRequestedState = kvm.RedirectionSAPEnable
listenerEnabled = 1
}

Expand Down Expand Up @@ -902,3 +904,77 @@ func (g *GoWSMANMessages) GetNetworkSettings() (interface{}, error) {

return networkResults, nil
}

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

credCntxtTlsResponse, err := g.wsmanMessages.AMT.TLSCredentialContext.Pull(credCntxtTlsEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(credCntxtTlsResponse)

concreteDepEnumResp, err := g.wsmanMessages.CIM.ConcreteDependency.Enumerate()
if err != nil {
return nil, err
}

concreteDepResponse, err := g.wsmanMessages.CIM.ConcreteDependency.Pull(concreteDepEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(concreteDepResponse)


pubKeyCertEnumResp, err := g.wsmanMessages.AMT.PublicKeyCertificate.Enumerate()
if err != nil {
return nil, err
}

pubKeyCertResponse, err := g.wsmanMessages.AMT.PublicKeyCertificate.Pull(pubKeyCertEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(pubKeyCertResponse)

pubPrivKeyPairEnumResp, err := g.wsmanMessages.AMT.PublicPrivateKeyPair.Enumerate()
if err != nil {
return nil, err
}

pubPrivKeyPairResponse, err := g.wsmanMessages.AMT.PublicPrivateKeyPair.Pull(pubPrivKeyPairEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(pubPrivKeyPairResponse)


credCntxt8021xEnumResp, err := g.wsmanMessages.IPS.IEEE8021xCredentialContext.Enumerate()
if err != nil {
return nil, err
}

credCntxt8021xResponse, err := g.wsmanMessages.IPS.IEEE8021xCredentialContext.Pull(credCntxt8021xEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(credCntxt8021xResponse)


cimCredCntxtEnumResp, err := g.wsmanMessages.CIM.CredentialContext.Enumerate()
if err != nil {
return nil, err
}

cimCredCntxtResponse, err := g.wsmanMessages.CIM.CredentialContext.Pull(cimCredCntxtEnumResp.Body.EnumerateResponse.EnumerationContext)
if err != nil {
return nil, err
}
fmt.Println(cimCredCntxtResponse)

return credCntxtTlsResponse, nil
}

0 comments on commit 8664c16

Please sign in to comment.