From b95e1c6489fbce2857061e7f308b743a5b439caa Mon Sep 17 00:00:00 2001 From: madhavilosetty-intel Date: Tue, 10 Sep 2024 14:46:26 -0700 Subject: [PATCH] feat: use dto in getversion --- .../http/v1/amtexplorer_mocks_test.go | 10 +- internal/controller/http/v1/ciraconfigs.go | 10 +- .../http/v1/ciraconfigs_mocks_test.go | 18 +-- .../controller/http/v1/ciraconfigs_test.go | 32 ++--- .../controller/http/v1/devicemanagement.go | 18 +-- .../http/v1/devicemanagement_mocks_test.go | 86 ++++++------ .../http/v1/devicemanagement_test.go | 55 ++++---- internal/controller/http/v1/devices.go | 20 +-- internal/controller/http/v1/devices_test.go | 28 ++-- internal/controller/http/v1/domains.go | 12 +- .../controller/http/v1/domains_mocks_test.go | 22 +-- internal/controller/http/v1/domains_test.go | 36 ++--- internal/controller/http/v1/error.go | 6 +- .../controller/http/v1/ieee8021xconfigs.go | 14 +- .../http/v1/ieee8021xconfigs_mocks_test.go | 18 +-- .../http/v1/ieee8021xconfigs_test.go | 18 +-- internal/controller/http/v1/profiles.go | 16 +-- .../controller/http/v1/profiles_mocks_test.go | 18 +-- internal/controller/http/v1/profiles_test.go | 18 +-- internal/controller/http/v1/wificonfigs.go | 12 +- .../http/v1/wificonfigs_mocks_test.go | 18 +-- .../controller/http/v1/wificonfigs_test.go | 32 ++--- .../controller/http/v1/wsman_mocks_test.go | 10 +- .../controller/http/v2/devicemanagement.go | 16 +++ .../http/v2/devicemanagement_mocks_test.go | 86 ++++++------ .../http/v2/devicemanagement_test.go | 18 ++- internal/controller/ws/v1/interface.go | 44 +++--- internal/controller/ws/v1/mocks_test.go | 80 +++++------ internal/entity/dto/{ => v1}/alarm.go | 2 +- internal/entity/dto/{ => v1}/auditlog.go | 2 +- internal/entity/dto/{ => v1}/bootsetting.go | 2 +- internal/entity/dto/{ => v1}/ciraconfig.go | 2 +- internal/entity/dto/{ => v1}/device.go | 2 +- internal/entity/dto/{ => v1}/domain.go | 2 +- internal/entity/dto/{ => v1}/eventlog.go | 2 +- internal/entity/dto/{ => v1}/features.go | 2 +- .../entity/dto/{ => v1}/ieee8021xconfig.go | 2 +- internal/entity/dto/{ => v1}/invalid.go | 2 +- internal/entity/dto/{ => v1}/network.go | 2 +- internal/entity/dto/{ => v1}/poweraction.go | 2 +- internal/entity/dto/{ => v1}/profile.go | 2 +- .../entity/dto/{ => v1}/profilewificonfigs.go | 2 +- .../entity/dto/{ => v1}/securitysettings.go | 2 +- .../entity/dto/v1/setupandconfiguration.go | 25 ++++ internal/entity/dto/{ => v1}/tlsconfig.go | 2 +- internal/entity/dto/{ => v1}/userconsent.go | 2 +- internal/entity/dto/v1/version.go | 14 ++ internal/entity/dto/{ => v1}/wificonfigs.go | 2 +- internal/entity/dto/v2/version.go | 17 +++ internal/usecase/amtexplorer/explorer.go | 14 +- internal/usecase/amtexplorer/explorer_test.go | 128 ++++++++--------- internal/usecase/amtexplorer/interfaces.go | 10 +- internal/usecase/amtexplorer/mocks_test.go | 10 +- internal/usecase/amtexplorer/usecase.go | 8 +- internal/usecase/amtexplorer/wsman.go | 6 +- internal/usecase/ciraconfigs/interfaces.go | 10 +- internal/usecase/ciraconfigs/mocks_test.go | 18 +-- internal/usecase/ciraconfigs/usecase.go | 22 +-- internal/usecase/ciraconfigs/usecase_test.go | 28 ++-- internal/usecase/devices/alarms.go | 20 +-- internal/usecase/devices/alarms_test.go | 30 ++-- internal/usecase/devices/certificates.go | 58 ++++---- .../devices/certificates_private_test.go | 40 +++--- internal/usecase/devices/certificates_test.go | 34 ++--- internal/usecase/devices/connections.go | 10 +- internal/usecase/devices/connections_test.go | 8 +- internal/usecase/devices/consent.go | 4 +- internal/usecase/devices/consent_test.go | 4 +- internal/usecase/devices/info.go | 129 ++++++++++++++---- internal/usecase/devices/info_test.go | 80 ++++++----- internal/usecase/devices/interceptor.go | 4 +- internal/usecase/devices/interfaces.go | 47 +++---- internal/usecase/devices/mocks_test.go | 86 ++++++------ internal/usecase/devices/network.go | 26 ++-- internal/usecase/devices/network_test.go | 22 +-- internal/usecase/devices/power.go | 10 +- .../usecase/devices/power_private_test.go | 18 +-- internal/usecase/devices/power_test.go | 4 +- internal/usecase/devices/redirection.go | 4 +- internal/usecase/devices/redirection_test.go | 4 +- internal/usecase/devices/repo.go | 20 +-- internal/usecase/devices/repo_test.go | 20 +-- internal/usecase/devices/usecase.go | 12 +- internal/usecase/devices/wsman/interfaces.go | 6 +- internal/usecase/devices/wsman/message.go | 24 ++-- internal/usecase/devices/wsman_mocks_test.go | 10 +- internal/usecase/domains/interfaces.go | 12 +- internal/usecase/domains/mocks_test.go | 22 +-- internal/usecase/domains/usecase.go | 26 ++-- internal/usecase/domains/usecase_test.go | 30 ++-- .../usecase/ieee8021xconfigs/interfaces.go | 10 +- .../usecase/ieee8021xconfigs/mocks_test.go | 18 +-- internal/usecase/ieee8021xconfigs/usecase.go | 22 +-- .../usecase/ieee8021xconfigs/usecase_test.go | 22 +-- internal/usecase/profiles/ieee_mocks_test.go | 18 +-- internal/usecase/profiles/interfaces.go | 10 +- internal/usecase/profiles/mocks_test.go | 18 +-- .../profileswificonfigs_mocks_test.go | 8 +- internal/usecase/profiles/usecase.go | 32 ++--- internal/usecase/profiles/usecase_test.go | 34 ++--- .../profiles/wificonfigs_mocks_test.go | 18 +-- .../usecase/profilewificonfigs/interfaces.go | 6 +- .../usecase/profilewificonfigs/mocks_test.go | 8 +- .../usecase/profilewificonfigs/usecase.go | 18 +-- .../profilewificonfigs/usecase_test.go | 4 +- internal/usecase/wificonfigs/interfaces.go | 10 +- internal/usecase/wificonfigs/mocks_test.go | 18 +-- .../profileswificonfigs_mocks_test.go | 8 +- internal/usecase/wificonfigs/usecase.go | 24 ++-- internal/usecase/wificonfigs/usecase_test.go | 46 +++---- 110 files changed, 1234 insertions(+), 1059 deletions(-) rename internal/entity/dto/{ => v1}/alarm.go (97%) rename internal/entity/dto/{ => v1}/auditlog.go (98%) rename internal/entity/dto/{ => v1}/bootsetting.go (92%) rename internal/entity/dto/{ => v1}/ciraconfig.go (99%) rename internal/entity/dto/{ => v1}/device.go (99%) rename internal/entity/dto/{ => v1}/domain.go (98%) rename internal/entity/dto/{ => v1}/eventlog.go (97%) rename internal/entity/dto/{ => v1}/features.go (96%) rename internal/entity/dto/{ => v1}/ieee8021xconfig.go (98%) rename internal/entity/dto/{ => v1}/invalid.go (96%) rename internal/entity/dto/{ => v1}/network.go (99%) rename internal/entity/dto/{ => v1}/poweraction.go (86%) rename internal/entity/dto/{ => v1}/profile.go (99%) rename internal/entity/dto/{ => v1}/profilewificonfigs.go (96%) rename internal/entity/dto/{ => v1}/securitysettings.go (99%) create mode 100644 internal/entity/dto/v1/setupandconfiguration.go rename internal/entity/dto/{ => v1}/tlsconfig.go (98%) rename internal/entity/dto/{ => v1}/userconsent.go (88%) create mode 100644 internal/entity/dto/v1/version.go rename internal/entity/dto/{ => v1}/wificonfigs.go (99%) create mode 100644 internal/entity/dto/v2/version.go diff --git a/internal/controller/http/v1/amtexplorer_mocks_test.go b/internal/controller/http/v1/amtexplorer_mocks_test.go index a76469c3..ae783fe1 100644 --- a/internal/controller/http/v1/amtexplorer_mocks_test.go +++ b/internal/controller/http/v1/amtexplorer_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" amtexplorer "github.com/open-amt-cloud-toolkit/console/internal/usecase/amtexplorer" alarmclock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock" auditlog "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/auditlog" @@ -934,10 +934,10 @@ func (m *MockAMTExplorerFeature) EXPECT() *MockAMTExplorerFeatureMockRecorder { } // ExecuteCall mocks base method. -func (m *MockAMTExplorerFeature) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dto.Explorer, error) { +func (m *MockAMTExplorerFeature) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dtov1.Explorer, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExecuteCall", ctx, guid, call, tenantID) - ret0, _ := ret[0].(*dto.Explorer) + ret0, _ := ret[0].(*dtov1.Explorer) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -1024,7 +1024,7 @@ func (m *MockAMTExplorerWSMAN) EXPECT() *MockAMTExplorerWSMANMockRecorder { } // DestroyWsmanClient mocks base method. -func (m *MockAMTExplorerWSMAN) DestroyWsmanClient(device dto.Device) { +func (m *MockAMTExplorerWSMAN) DestroyWsmanClient(device dtov1.Device) { m.ctrl.T.Helper() m.ctrl.Call(m, "DestroyWsmanClient", device) } @@ -1036,7 +1036,7 @@ func (mr *MockAMTExplorerWSMANMockRecorder) DestroyWsmanClient(device any) *gomo } // SetupWsmanClient mocks base method. -func (m *MockAMTExplorerWSMAN) SetupWsmanClient(device dto.Device, logMessages bool) amtexplorer.AMTExplorer { +func (m *MockAMTExplorerWSMAN) SetupWsmanClient(device dtov1.Device, logMessages bool) amtexplorer.AMTExplorer { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, logMessages) ret0, _ := ret[0].(amtexplorer.AMTExplorer) diff --git a/internal/controller/http/v1/ciraconfigs.go b/internal/controller/http/v1/ciraconfigs.go index d35700b5..0f8a1e00 100644 --- a/internal/controller/http/v1/ciraconfigs.go +++ b/internal/controller/http/v1/ciraconfigs.go @@ -5,7 +5,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ciraconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -29,8 +29,8 @@ func NewCIRAConfigRoutes(handler *gin.RouterGroup, t ciraconfigs.Feature, l logg } type CIRAConfigCountResponse struct { - Count int `json:"totalCount"` - Data []dto.CIRAConfig `json:"data"` + Count int `json:"totalCount"` + Data []dtov1.CIRAConfig `json:"data"` } func (r *ciraConfigRoutes) get(c *gin.Context) { @@ -85,7 +85,7 @@ func (r *ciraConfigRoutes) getByName(c *gin.Context) { } func (r *ciraConfigRoutes) insert(c *gin.Context) { - var config dto.CIRAConfig + var config dtov1.CIRAConfig if err := c.ShouldBindJSON(&config); err != nil { r.l.Error(err, "http - CIRA configs - v1 - insert") ErrorResponse(c, err) @@ -105,7 +105,7 @@ func (r *ciraConfigRoutes) insert(c *gin.Context) { } func (r *ciraConfigRoutes) update(c *gin.Context) { - var config dto.CIRAConfig + var config dtov1.CIRAConfig if err := c.ShouldBindJSON(&config); err != nil { r.l.Error(err, "http - CIRA configs - v1 - update") ErrorResponse(c, err) diff --git a/internal/controller/http/v1/ciraconfigs_mocks_test.go b/internal/controller/http/v1/ciraconfigs_mocks_test.go index a59306af..6f4bb88e 100644 --- a/internal/controller/http/v1/ciraconfigs_mocks_test.go +++ b/internal/controller/http/v1/ciraconfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -169,10 +169,10 @@ func (mr *MockCIRAConfigsFeatureMockRecorder) Delete(ctx, profileName, tenantID } // Get mocks base method. -func (m *MockCIRAConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.CIRAConfig, error) { +func (m *MockCIRAConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.CIRAConfig) + ret0, _ := ret[0].([]dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -184,10 +184,10 @@ func (mr *MockCIRAConfigsFeatureMockRecorder) Get(ctx, top, skip, tenantID any) } // GetByName mocks base method. -func (m *MockCIRAConfigsFeature) GetByName(ctx context.Context, configName, tenantID string) (*dto.CIRAConfig, error) { +func (m *MockCIRAConfigsFeature) GetByName(ctx context.Context, configName, tenantID string) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, configName, tenantID) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockCIRAConfigsFeatureMockRecorder) GetCount(ctx, tenantID any) *gomoc } // Insert mocks base method. -func (m *MockCIRAConfigsFeature) Insert(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (m *MockCIRAConfigsFeature) Insert(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockCIRAConfigsFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockCIRAConfigsFeature) Update(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (m *MockCIRAConfigsFeature) Update(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/ciraconfigs_test.go b/internal/controller/http/v1/ciraconfigs_test.go index ba188440..d6228e49 100644 --- a/internal/controller/http/v1/ciraconfigs_test.go +++ b/internal/controller/http/v1/ciraconfigs_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ciraconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -40,13 +40,13 @@ type ciraconfigTest struct { url string mock func(repo *MockCIRAConfigsFeature) response interface{} - requestBody dto.CIRAConfig + requestBody dtov1.CIRAConfig expectedCode int } var ( - requestCIRAConfig = dto.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"} - responseCIRAConfig = dto.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"} + requestCIRAConfig = dtov1.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"} + responseCIRAConfig = dtov1.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"} ) func TestCIRAConfigRoutes(t *testing.T) { @@ -58,11 +58,11 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.CIRAConfig{{ + ciraconfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.CIRAConfig{{ ConfigName: "config", }}, nil) }, - response: []dto.CIRAConfig{{ConfigName: "config"}}, + response: []dtov1.CIRAConfig{{ConfigName: "config"}}, expectedCode: http.StatusOK, }, { @@ -70,12 +70,12 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ciraconfigs?$top=10&$skip=1&$count=true", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.CIRAConfig{{ + ciraconfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.CIRAConfig{{ ConfigName: "config", }}, nil) ciraconfig.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: CIRAConfigCountResponse{Count: 1, Data: []dto.CIRAConfig{{ConfigName: "config"}}}, + response: CIRAConfigCountResponse{Count: 1, Data: []dtov1.CIRAConfig{{ConfigName: "config"}}}, expectedCode: http.StatusOK, }, { @@ -93,11 +93,11 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ciraconfigs/profile", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.CIRAConfig{ + ciraconfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.CIRAConfig{ ConfigName: "config", }, nil) }, - response: dto.CIRAConfig{ConfigName: "config"}, + response: dtov1.CIRAConfig{ConfigName: "config"}, expectedCode: http.StatusOK, }, { @@ -115,7 +115,7 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfigTest := &dto.CIRAConfig{ + ciraconfigTest := &dtov1.CIRAConfig{ ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, @@ -141,7 +141,7 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfigTest := &dto.CIRAConfig{ + ciraconfigTest := &dtov1.CIRAConfig{ ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, @@ -167,7 +167,7 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfig400Test := &dto.CIRAConfig{ + ciraconfig400Test := &dtov1.CIRAConfig{ ConfigName: "ciraconfig", ServerAddressFormat: 201, AuthMethod: 2, @@ -180,7 +180,7 @@ func TestCIRAConfigRoutes(t *testing.T) { ciraconfig.EXPECT().Insert(context.Background(), ciraconfig400Test).Return(nil, ciraconfigs.ErrDatabase) }, response: ciraconfigs.ErrDatabase, - requestBody: dto.CIRAConfig{ConfigName: "ciraconfig", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}, + requestBody: dtov1.CIRAConfig{ConfigName: "ciraconfig", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}, expectedCode: http.StatusBadRequest, }, { @@ -208,7 +208,7 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfigTest := &dto.CIRAConfig{ + ciraconfigTest := &dtov1.CIRAConfig{ ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, @@ -234,7 +234,7 @@ func TestCIRAConfigRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/ciraconfigs", mock: func(ciraconfig *MockCIRAConfigsFeature) { - ciraconfigTest := &dto.CIRAConfig{ + ciraconfigTest := &dtov1.CIRAConfig{ ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, diff --git a/internal/controller/http/v1/devicemanagement.go b/internal/controller/http/v1/devicemanagement.go index b74f6be6..48cbf7bf 100644 --- a/internal/controller/http/v1/devicemanagement.go +++ b/internal/controller/http/v1/devicemanagement.go @@ -6,7 +6,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/amtexplorer" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -60,7 +60,7 @@ func NewAmtRoutes(handler *gin.RouterGroup, d devices.Feature, amt amtexplorer.F func (r *deviceManagementRoutes) getVersion(c *gin.Context) { guid := c.Param("guid") - version, err := r.d.GetVersion(c.Request.Context(), guid) + versionv1, _, err := r.d.GetVersion(c.Request.Context(), guid) if err != nil { r.l.Error(err, "http - v1 - GetVersion") ErrorResponse(c, err) @@ -68,7 +68,7 @@ func (r *deviceManagementRoutes) getVersion(c *gin.Context) { return } - c.JSON(http.StatusOK, version) + c.JSON(http.StatusOK, versionv1) } func (r *deviceManagementRoutes) getFeatures(c *gin.Context) { @@ -97,7 +97,7 @@ func (r *deviceManagementRoutes) getFeatures(c *gin.Context) { func (r *deviceManagementRoutes) setFeatures(c *gin.Context) { guid := c.Param("guid") - var features dto.Features + var features dtov1.Features if err := c.ShouldBindJSON(&features); err != nil { ErrorResponse(c, err) @@ -133,7 +133,7 @@ func (r *deviceManagementRoutes) getAlarmOccurrences(c *gin.Context) { func (r *deviceManagementRoutes) createAlarmOccurrences(c *gin.Context) { guid := c.Param("guid") - alarm := &dto.AlarmClockOccurrence{} + alarm := &dtov1.AlarmClockOccurrence{} if err := c.ShouldBindJSON(alarm); err != nil { ErrorResponse(c, err) @@ -154,7 +154,7 @@ func (r *deviceManagementRoutes) createAlarmOccurrences(c *gin.Context) { func (r *deviceManagementRoutes) deleteAlarmOccurrences(c *gin.Context) { guid := c.Param("guid") - alarm := dto.DeleteAlarmOccurrenceRequest{} + alarm := dtov1.DeleteAlarmOccurrenceRequest{} if err := c.ShouldBindJSON(&alarm); err != nil { ErrorResponse(c, err) @@ -277,7 +277,7 @@ func (r *deviceManagementRoutes) getUserConsentCode(c *gin.Context) { func (r *deviceManagementRoutes) sendConsentCode(c *gin.Context) { guid := c.Param("guid") - var userConsent dto.UserConsent + var userConsent dtov1.UserConsent if err := c.ShouldBindJSON(&userConsent); err != nil { ErrorResponse(c, err) @@ -298,7 +298,7 @@ func (r *deviceManagementRoutes) sendConsentCode(c *gin.Context) { func (r *deviceManagementRoutes) powerAction(c *gin.Context) { guid := c.Param("guid") - var powerAction dto.PowerAction + var powerAction dtov1.PowerAction if err := c.ShouldBindJSON(&powerAction); err != nil { ErrorResponse(c, err) @@ -357,7 +357,7 @@ func (r *deviceManagementRoutes) getEventLog(c *gin.Context) { func (r *deviceManagementRoutes) setBootOptions(c *gin.Context) { guid := c.Param("guid") - var bootSetting dto.BootSetting + var bootSetting dtov1.BootSetting if err := c.ShouldBindJSON(&bootSetting); err != nil { ErrorResponse(c, err) diff --git a/internal/controller/http/v1/devicemanagement_mocks_test.go b/internal/controller/http/v1/devicemanagement_mocks_test.go index 67ae281c..3ae08f3d 100644 --- a/internal/controller/http/v1/devicemanagement_mocks_test.go +++ b/internal/controller/http/v1/devicemanagement_mocks_test.go @@ -15,7 +15,8 @@ import ( websocket "github.com/gorilla/websocket" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" wsman0 "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" @@ -47,7 +48,7 @@ func (m *MockWSMAN) EXPECT() *MockWSMANMockRecorder { } // DestroyWsmanClient mocks base method. -func (m *MockWSMAN) DestroyWsmanClient(device dto.Device) { +func (m *MockWSMAN) DestroyWsmanClient(device dtov1.Device) { m.ctrl.T.Helper() m.ctrl.Call(m, "DestroyWsmanClient", device) } @@ -59,7 +60,7 @@ func (mr *MockWSMANMockRecorder) DestroyWsmanClient(device any) *gomock.Call { } // SetupWsmanClient mocks base method. -func (m *MockWSMAN) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman.Management { +func (m *MockWSMAN) SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsman.Management { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman.Management) @@ -165,7 +166,7 @@ func (mr *MockRedirectionMockRecorder) RedirectSend(ctx, deviceConnection, messa } // SetupWsmanClient mocks base method. -func (m *MockRedirection) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman0.Messages { +func (m *MockRedirection) SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsman0.Messages { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman0.Messages) @@ -375,10 +376,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) CancelUserConsent(ctx, guid a } // CreateAlarmOccurrences mocks base method. -func (m *MockDeviceManagementFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) { +func (m *MockDeviceManagementFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateAlarmOccurrences", ctx, guid, alarm) - ret0, _ := ret[0].(dto.AddAlarmOutput) + ret0, _ := ret[0].(dtov1.AddAlarmOutput) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -418,10 +419,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) DeleteAlarmOccurrences(ctx, g } // Get mocks base method. -func (m *MockDeviceManagementFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -433,10 +434,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) Get(ctx, top, skip, tenantID } // GetAlarmOccurrences mocks base method. -func (m *MockDeviceManagementFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) { +func (m *MockDeviceManagementFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAlarmOccurrences", ctx, guid) - ret0, _ := ret[0].([]dto.AlarmClockOccurrence) + ret0, _ := ret[0].([]dtov1.AlarmClockOccurrence) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -448,10 +449,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetAlarmOccurrences(ctx, guid } // GetAuditLog mocks base method. -func (m *MockDeviceManagementFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) { +func (m *MockDeviceManagementFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dtov1.AuditLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAuditLog", ctx, startIndex, guid) - ret0, _ := ret[0].(dto.AuditLog) + ret0, _ := ret[0].(dtov1.AuditLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -463,10 +464,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetAuditLog(ctx, startIndex, } // GetByColumn mocks base method. -func (m *MockDeviceManagementFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByColumn", ctx, columnName, queryValue, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -478,10 +479,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByColumn(ctx, columnName, } // GetByID mocks base method. -func (m *MockDeviceManagementFeature) GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByID", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -493,10 +494,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByID(ctx, guid, tenantID a } // GetByTags mocks base method. -func (m *MockDeviceManagementFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByTags", ctx, tags, method, limit, offset, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -508,10 +509,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByTags(ctx, tags, method, } // GetCertificates mocks base method. -func (m *MockDeviceManagementFeature) GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) { +func (m *MockDeviceManagementFeature) GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCertificates", c, guid) - ret0, _ := ret[0].(dto.SecuritySettings) + ret0, _ := ret[0].(dtov1.SecuritySettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -538,10 +539,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetCount(arg0, arg1 any) *gom } // GetDeviceCertificate mocks base method. -func (m *MockDeviceManagementFeature) GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) { +func (m *MockDeviceManagementFeature) GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDeviceCertificate", c, guid) - ret0, _ := ret[0].(dto.Certificate) + ret0, _ := ret[0].(dtov1.Certificate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -583,10 +584,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetDistinctTags(ctx, tenantID } // GetEventLog mocks base method. -func (m *MockDeviceManagementFeature) GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) { +func (m *MockDeviceManagementFeature) GetEventLog(ctx context.Context, guid string) ([]dtov1.EventLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEventLog", ctx, guid) - ret0, _ := ret[0].([]dto.EventLog) + ret0, _ := ret[0].([]dtov1.EventLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -598,10 +599,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetEventLog(ctx, guid any) *g } // GetFeatures mocks base method. -func (m *MockDeviceManagementFeature) GetFeatures(ctx context.Context, guid string) (dto.Features, error) { +func (m *MockDeviceManagementFeature) GetFeatures(ctx context.Context, guid string) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures", ctx, guid) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -643,10 +644,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetHardwareInfo(ctx, guid any } // GetNetworkSettings mocks base method. -func (m *MockDeviceManagementFeature) GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) { +func (m *MockDeviceManagementFeature) GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNetworkSettings", c, guid) - ret0, _ := ret[0].(dto.NetworkSettings) + ret0, _ := ret[0].(dtov1.NetworkSettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -688,10 +689,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetPowerState(ctx, guid any) } // GetTLSSettingData mocks base method. -func (m *MockDeviceManagementFeature) GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) { +func (m *MockDeviceManagementFeature) GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTLSSettingData", c, guid) - ret0, _ := ret[0].([]dto.SettingDataResponse) + ret0, _ := ret[0].([]dtov1.SettingDataResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -718,12 +719,13 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetUserConsentCode(ctx, guid } // GetVersion mocks base method. -func (m *MockDeviceManagementFeature) GetVersion(ctx context.Context, guid string) (map[string]any, error) { +func (m *MockDeviceManagementFeature) GetVersion(ctx context.Context, guid string) (dtov1.Version, dtov2.Version, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetVersion", ctx, guid) - ret0, _ := ret[0].(map[string]any) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(dtov1.Version) + ret1, _ := ret[1].(dtov2.Version) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // GetVersion indicates an expected call of GetVersion. @@ -733,10 +735,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetVersion(ctx, guid any) *go } // Insert mocks base method. -func (m *MockDeviceManagementFeature) Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -762,7 +764,7 @@ func (mr *MockDeviceManagementFeatureMockRecorder) Redirect(ctx, conn, guid, mod } // SendConsentCode mocks base method. -func (m *MockDeviceManagementFeature) SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (any, error) { +func (m *MockDeviceManagementFeature) SendConsentCode(ctx context.Context, code dtov1.UserConsent, guid string) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendConsentCode", ctx, code, guid) ret0, _ := ret[0].(any) @@ -792,7 +794,7 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SendPowerAction(ctx, guid, ac } // SetBootOptions mocks base method. -func (m *MockDeviceManagementFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) { +func (m *MockDeviceManagementFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetBootOptions", ctx, guid, bootSetting) ret0, _ := ret[0].(power.PowerActionResponse) @@ -807,10 +809,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SetBootOptions(ctx, guid, boo } // SetFeatures mocks base method. -func (m *MockDeviceManagementFeature) SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) { +func (m *MockDeviceManagementFeature) SetFeatures(ctx context.Context, guid string, features dtov1.Features) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", ctx, guid, features) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -822,10 +824,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SetFeatures(ctx, guid, featur } // Update mocks base method. -func (m *MockDeviceManagementFeature) Update(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/devicemanagement_test.go b/internal/controller/http/v1/devicemanagement_test.go index fdb68430..d07de40f 100644 --- a/internal/controller/http/v1/devicemanagement_test.go +++ b/internal/controller/http/v1/devicemanagement_test.go @@ -15,7 +15,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -58,10 +59,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetVersion(context.Background(), "valid-guid"). - Return(map[string]interface{}{"version": "1.0.0"}, nil) + Return(dtov1.Version{}, dtov2.Version{}, nil) }, expectedCode: http.StatusOK, - response: map[string]interface{}{"version": "1.0.0"}, + response: dtov1.Version{}, }, { name: "getFeatures - successful retrieval", @@ -69,7 +70,7 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetFeatures(context.Background(), "valid-guid"). - Return(dto.Features{}, nil) + Return(dtov1.Features{}, nil) }, expectedCode: http.StatusOK, response: map[string]interface{}{"IDER": false, "KVM": false, "SOL": false, "redirection": false, "optInState": 0, "userConsent": ""}, @@ -78,12 +79,12 @@ func TestDeviceManagement(t *testing.T) { name: "setFeatures - successful setting", url: "/api/v1/amt/features/valid-guid", method: http.MethodPost, - requestBody: dto.Features{}, + requestBody: dtov1.Features{}, mock: func(m *MockDeviceManagementFeature) { - m.EXPECT().SetFeatures(context.Background(), "valid-guid", dto.Features{}).Return(dto.Features{}, nil) + m.EXPECT().SetFeatures(context.Background(), "valid-guid", dtov1.Features{}).Return(dtov1.Features{}, nil) }, expectedCode: http.StatusOK, - response: dto.Features{}, + response: dtov1.Features{}, }, { name: "getAlarmOccurrences - successful retrieval", @@ -91,16 +92,16 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetAlarmOccurrences(context.Background(), "valid-guid"). - Return([]dto.AlarmClockOccurrence{}, nil) + Return([]dtov1.AlarmClockOccurrence{}, nil) }, expectedCode: http.StatusOK, - response: []dto.AlarmClockOccurrence{}, + response: []dtov1.AlarmClockOccurrence{}, }, { name: "deleteAlarmOccurrences - successful deletion", url: "/api/v1/amt/alarmOccurrences/valid-guid", method: http.MethodDelete, - requestBody: dto.AlarmClockOccurrence{ + requestBody: dtov1.AlarmClockOccurrence{ ElementName: "elementName", StartTime: aGoodTime, Interval: 1, @@ -149,7 +150,7 @@ func TestDeviceManagement(t *testing.T) { name: "powerAction - successful action", url: "/api/v1/amt/power/action/valid-guid", method: http.MethodPost, - requestBody: dto.PowerAction{ + requestBody: dtov1.PowerAction{ Action: 4, }, mock: func(m *MockDeviceManagementFeature) { @@ -165,10 +166,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetAuditLog(context.Background(), 0, "valid-guid"). - Return(dto.AuditLog{}, nil) + Return(dtov1.AuditLog{}, nil) }, expectedCode: http.StatusOK, - response: dto.AuditLog{}, + response: dtov1.AuditLog{}, }, { name: "getEventLog - successful retrieval", @@ -176,20 +177,20 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetEventLog(context.Background(), "valid-guid"). - Return([]dto.EventLog{}, nil) + Return([]dtov1.EventLog{}, nil) }, expectedCode: http.StatusOK, - response: []dto.EventLog{}, + response: []dtov1.EventLog{}, }, { name: "setBootOptions - successful setting", url: "/api/v1/amt/power/bootOptions/valid-guid", method: http.MethodPost, - requestBody: dto.BootSetting{ + requestBody: dtov1.BootSetting{ Action: 109, }, mock: func(m *MockDeviceManagementFeature) { - m.EXPECT().SetBootOptions(context.Background(), "valid-guid", dto.BootSetting{ + m.EXPECT().SetBootOptions(context.Background(), "valid-guid", dtov1.BootSetting{ Action: 109, }).Return(power.PowerActionResponse{ReturnValue: 0}, nil) }, @@ -202,10 +203,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetNetworkSettings(context.Background(), "valid-guid"). - Return(dto.NetworkSettings{}, nil) + Return(dtov1.NetworkSettings{}, nil) }, expectedCode: http.StatusOK, - response: dto.NetworkSettings{}, + response: dtov1.NetworkSettings{}, }, { name: "getCertificates - successful retrieval", @@ -213,10 +214,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetCertificates(context.Background(), "valid-guid"). - Return(dto.SecuritySettings{}, nil) + Return(dtov1.SecuritySettings{}, nil) }, expectedCode: http.StatusOK, - response: dto.SecuritySettings{}, + response: dtov1.SecuritySettings{}, }, { name: "getCertificates - failed retrieval", @@ -224,10 +225,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetCertificates(context.Background(), "valid-guid"). - Return(dto.SecuritySettings{}, ErrGeneral) + Return(dtov1.SecuritySettings{}, ErrGeneral) }, expectedCode: http.StatusInternalServerError, - response: dto.SecuritySettings{}, + response: dtov1.SecuritySettings{}, }, { name: "getTLSsettingData - successful retrieval", @@ -235,10 +236,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetTLSSettingData(context.Background(), "valid-guid"). - Return([]dto.SettingDataResponse{}, nil) + Return([]dtov1.SettingDataResponse{}, nil) }, expectedCode: http.StatusOK, - response: []dto.SettingDataResponse{}, + response: []dtov1.SettingDataResponse{}, }, { name: "getTLSsettingData - failed retrieval", @@ -246,10 +247,10 @@ func TestDeviceManagement(t *testing.T) { method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetTLSSettingData(context.Background(), "valid-guid"). - Return([]dto.SettingDataResponse{}, ErrGeneral) + Return([]dtov1.SettingDataResponse{}, ErrGeneral) }, expectedCode: http.StatusInternalServerError, - response: []dto.SettingDataResponse{}, + response: []dtov1.SettingDataResponse{}, }, } diff --git a/internal/controller/http/v1/devices.go b/internal/controller/http/v1/devices.go index c2398921..396c84f5 100644 --- a/internal/controller/http/v1/devices.go +++ b/internal/controller/http/v1/devices.go @@ -5,7 +5,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -16,7 +16,7 @@ type deviceRoutes struct { l logger.Interface } -var ErrValidationDevices = dto.NotValidError{Console: consoleerrors.CreateConsoleError("ProfileAPI")} +var ErrValidationDevices = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("ProfileAPI")} func NewDeviceRoutes(handler *gin.RouterGroup, t devices.Feature, l logger.Interface) { r := &deviceRoutes{t, l} @@ -38,8 +38,8 @@ func NewDeviceRoutes(handler *gin.RouterGroup, t devices.Feature, l logger.Inter } type DeviceCountResponse struct { - Count int `json:"totalCount"` - Data []dto.Device `json:"data"` + Count int `json:"totalCount"` + Data []dtov1.Device `json:"data"` } type DeviceStatResponse struct { TotalCount int `json:"totalCount"` @@ -93,7 +93,7 @@ func (dr *deviceRoutes) get(c *gin.Context) { hostname := c.Query("hostname") friendlyName := c.Query("friendlyName") - var items []dto.Device + var items []dtov1.Device var err error @@ -138,8 +138,8 @@ func (dr *deviceRoutes) get(c *gin.Context) { } } -func (dr *deviceRoutes) getByColumnOrTags(c *gin.Context, column, value string, limit, skip int, tenantID string) ([]dto.Device, error) { - var items []dto.Device +func (dr *deviceRoutes) getByColumnOrTags(c *gin.Context, column, value string, limit, skip int, tenantID string) ([]dtov1.Device, error) { + var items []dtov1.Device var err error @@ -197,7 +197,7 @@ func (dr *deviceRoutes) getByID(c *gin.Context) { // @Failure 500 {object} response // @Router /api/v1/devices [post] func (dr *deviceRoutes) insert(c *gin.Context) { - var device dto.Device + var device dtov1.Device if err := c.ShouldBindJSON(&device); err != nil { validationErr := ErrValidationDevices.Wrap("insert", "ShouldBindJSON", err) ErrorResponse(c, validationErr) @@ -226,7 +226,7 @@ func (dr *deviceRoutes) insert(c *gin.Context) { // @Failure 500 {object} response // @Router /api/v1/devices [patch] func (dr *deviceRoutes) update(c *gin.Context) { - var device dto.Device + var device dtov1.Device if err := c.ShouldBindJSON(&device); err != nil { ErrorResponse(c, err) @@ -347,7 +347,7 @@ func (dr *deviceRoutes) getDeviceCertificate(c *gin.Context) { // @Failure 500 {object} response // @Router /api/v1/devices/cert/:guid [post] func (dr *deviceRoutes) pinDeviceCertificate(c *gin.Context) { - var certToPin dto.PinCertificate + var certToPin dtov1.PinCertificate if err := c.ShouldBindBodyWithJSON(&certToPin); err != nil { ErrorResponse(c, err) diff --git a/internal/controller/http/v1/devices_test.go b/internal/controller/http/v1/devices_test.go index 10bfedcb..f04b46bb 100644 --- a/internal/controller/http/v1/devices_test.go +++ b/internal/controller/http/v1/devices_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -41,14 +41,14 @@ type deviceTest struct { url string mock func(repo *MockDeviceManagementFeature) response interface{} - requestBody dto.Device + requestBody dtov1.Device expectedCode int } var ( timeNow = time.Now().UTC() - requestDevice = dto.Device{ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", GUID: "guid", MPSUsername: "mpsusername", Tags: []string{"tag1", "tag2"}, TenantID: "tenantId", FriendlyName: "friendlyName", DNSSuffix: "dnsSuffix", Username: "admin", Password: "password", UseTLS: true, AllowSelfSigned: true, LastConnected: &timeNow, LastSeen: &timeNow, LastDisconnected: &timeNow} - responseDevice = dto.Device{ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", GUID: "guid", MPSUsername: "mpsusername", Tags: []string{"tag1", "tag2"}, TenantID: "tenantId", FriendlyName: "friendlyName", DNSSuffix: "dnsSuffix", Username: "admin", Password: "password", UseTLS: true, AllowSelfSigned: true, LastConnected: &timeNow, LastSeen: &timeNow, LastDisconnected: &timeNow} + requestDevice = dtov1.Device{ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", GUID: "guid", MPSUsername: "mpsusername", Tags: []string{"tag1", "tag2"}, TenantID: "tenantId", FriendlyName: "friendlyName", DNSSuffix: "dnsSuffix", Username: "admin", Password: "password", UseTLS: true, AllowSelfSigned: true, LastConnected: &timeNow, LastSeen: &timeNow, LastDisconnected: &timeNow} + responseDevice = dtov1.Device{ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", GUID: "guid", MPSUsername: "mpsusername", Tags: []string{"tag1", "tag2"}, TenantID: "tenantId", FriendlyName: "friendlyName", DNSSuffix: "dnsSuffix", Username: "admin", Password: "password", UseTLS: true, AllowSelfSigned: true, LastConnected: &timeNow, LastSeen: &timeNow, LastDisconnected: &timeNow} ) func TestDevicesRoutes(t *testing.T) { @@ -60,11 +60,11 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/devices", mock: func(device *MockDeviceManagementFeature) { - device.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.Device{{ + device.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.Device{{ GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname", }}, nil) }, - response: []dto.Device{{GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}}, + response: []dtov1.Device{{GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}}, expectedCode: http.StatusOK, }, { @@ -72,12 +72,12 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/devices?$top=10&$skip=1&$count=true", mock: func(device *MockDeviceManagementFeature) { - device.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.Device{{ + device.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.Device{{ GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname", }}, nil) device.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: DeviceCountResponse{Count: 1, Data: []dto.Device{{GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}}}, + response: DeviceCountResponse{Count: 1, Data: []dtov1.Device{{GUID: "guid", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}}}, expectedCode: http.StatusOK, }, { @@ -85,11 +85,11 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/devices/123e4567-e89b-12d3-a456-426614174000", mock: func(device *MockDeviceManagementFeature) { - device.EXPECT().GetByID(context.Background(), "123e4567-e89b-12d3-a456-426614174000", "").Return(&dto.Device{ + device.EXPECT().GetByID(context.Background(), "123e4567-e89b-12d3-a456-426614174000", "").Return(&dtov1.Device{ GUID: "123e4567-e89b-12d3-a456-426614174000", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname", }, nil) }, - response: &dto.Device{GUID: "123e4567-e89b-12d3-a456-426614174000", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}, + response: &dtov1.Device{GUID: "123e4567-e89b-12d3-a456-426614174000", MPSUsername: "mpsusername", Username: "admin", Password: "password", ConnectionStatus: true, Hostname: "hostname"}, expectedCode: http.StatusOK, }, { @@ -117,7 +117,7 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/devices", mock: func(device *MockDeviceManagementFeature) { - deviceTest := &dto.Device{ + deviceTest := &dtov1.Device{ ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", @@ -146,7 +146,7 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/devices", mock: func(device *MockDeviceManagementFeature) { - deviceTest := &dto.Device{ + deviceTest := &dtov1.Device{ ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", @@ -195,7 +195,7 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/devices", mock: func(device *MockDeviceManagementFeature) { - deviceTest := &dto.Device{ + deviceTest := &dtov1.Device{ ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", @@ -224,7 +224,7 @@ func TestDevicesRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/devices", mock: func(device *MockDeviceManagementFeature) { - deviceTest := &dto.Device{ + deviceTest := &dtov1.Device{ ConnectionStatus: true, MPSInstance: "mpsInstance", Hostname: "hostname", diff --git a/internal/controller/http/v1/domains.go b/internal/controller/http/v1/domains.go index 7a944f38..077878b8 100644 --- a/internal/controller/http/v1/domains.go +++ b/internal/controller/http/v1/domains.go @@ -5,13 +5,13 @@ import ( "github.com/gin-gonic/gin" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/domains" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) -var ErrValidationDomains = dto.NotValidError{Console: consoleerrors.CreateConsoleError("DomainsAPI")} +var ErrValidationDomains = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("DomainsAPI")} type domainRoutes struct { t domains.Feature @@ -32,8 +32,8 @@ func NewDomainRoutes(handler *gin.RouterGroup, t domains.Feature, l logger.Inter } type DomainCountResponse struct { - Count int `json:"totalCount"` - Data []dto.Domain `json:"data"` + Count int `json:"totalCount"` + Data []dtov1.Domain `json:"data"` } // @Summary Show Domains @@ -113,7 +113,7 @@ func (r *domainRoutes) getByName(c *gin.Context) { // @Failure 500 {object} response // @Router /api/v1/admin/domains [post] func (r *domainRoutes) insert(c *gin.Context) { - var domain dto.Domain + var domain dtov1.Domain if err := c.ShouldBindJSON(&domain); err != nil { validationErr := ErrValidationDomains.Wrap("insert", "ShouldBindJSON", err) ErrorResponse(c, validationErr) @@ -142,7 +142,7 @@ func (r *domainRoutes) insert(c *gin.Context) { // @Failure 500 {object} response // @Router /api/v1/admin/Domains [patch] func (r *domainRoutes) update(c *gin.Context) { - var domain dto.Domain + var domain dtov1.Domain if err := c.ShouldBindJSON(&domain); err != nil { validationErr := ErrValidationDomains.Wrap("update", "ShouldBindJSON", err) ErrorResponse(c, validationErr) diff --git a/internal/controller/http/v1/domains_mocks_test.go b/internal/controller/http/v1/domains_mocks_test.go index 6b36c172..653202ca 100644 --- a/internal/controller/http/v1/domains_mocks_test.go +++ b/internal/controller/http/v1/domains_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -184,10 +184,10 @@ func (mr *MockDomainsFeatureMockRecorder) Delete(ctx, name, tenantID any) *gomoc } // Get mocks base method. -func (m *MockDomainsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Domain, error) { +func (m *MockDomainsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Domain) + ret0, _ := ret[0].([]dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -199,10 +199,10 @@ func (mr *MockDomainsFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gom } // GetByName mocks base method. -func (m *MockDomainsFeature) GetByName(ctx context.Context, name, tenantID string) (*dto.Domain, error) { +func (m *MockDomainsFeature) GetByName(ctx context.Context, name, tenantID string) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, name, tenantID) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockDomainsFeatureMockRecorder) GetCount(arg0, arg1 any) *gomock.Call } // GetDomainByDomainSuffix mocks base method. -func (m *MockDomainsFeature) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dto.Domain, error) { +func (m *MockDomainsFeature) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDomainByDomainSuffix", ctx, domainSuffix, tenantID) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockDomainsFeatureMockRecorder) GetDomainByDomainSuffix(ctx, domainSuf } // Insert mocks base method. -func (m *MockDomainsFeature) Insert(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (m *MockDomainsFeature) Insert(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockDomainsFeatureMockRecorder) Insert(ctx, d any) *gomock.Call { } // Update mocks base method. -func (m *MockDomainsFeature) Update(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (m *MockDomainsFeature) Update(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/domains_test.go b/internal/controller/http/v1/domains_test.go index 32f8e919..951cd727 100644 --- a/internal/controller/http/v1/domains_test.go +++ b/internal/controller/http/v1/domains_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/domains" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -46,13 +46,13 @@ type test struct { url string mock func(repo *MockDomainsFeature) response interface{} - requestBody dto.Domain + requestBody dtov1.Domain expectedCode int } var ( - requestDomain = dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} - responseDomain = dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + requestDomain = dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + responseDomain = dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} ) func TestDomainRoutes(t *testing.T) { @@ -64,11 +64,11 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domain.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.Domain{{ + domain.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.Domain{{ ProfileName: "profile", }}, nil) }, - response: []dto.Domain{{ProfileName: "profile"}}, + response: []dtov1.Domain{{ProfileName: "profile"}}, expectedCode: http.StatusOK, }, { @@ -76,12 +76,12 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/domains?$top=10&$skip=1&$count=true", mock: func(domain *MockDomainsFeature) { - domain.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.Domain{{ + domain.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.Domain{{ ProfileName: "profile", }}, nil) domain.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: DomainCountResponse{Count: 1, Data: []dto.Domain{{ProfileName: "profile"}}}, + response: DomainCountResponse{Count: 1, Data: []dtov1.Domain{{ProfileName: "profile"}}}, expectedCode: http.StatusOK, }, { @@ -99,11 +99,11 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/domains/profile", mock: func(domain *MockDomainsFeature) { - domain.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.Domain{ + domain.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.Domain{ ProfileName: "profile", }, nil) }, - response: dto.Domain{ProfileName: "profile"}, + response: dtov1.Domain{ProfileName: "profile"}, expectedCode: http.StatusOK, }, { @@ -121,7 +121,7 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domainTest := &dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + domainTest := &dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} domain.EXPECT().Insert(context.Background(), domainTest).Return(domainTest, nil) }, response: responseDomain, @@ -133,7 +133,7 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domainTest := &dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + domainTest := &dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} domain.EXPECT().Insert(context.Background(), domainTest).Return(nil, domains.ErrDatabase) }, response: domains.ErrDatabase, @@ -141,15 +141,15 @@ func TestDomainRoutes(t *testing.T) { expectedCode: http.StatusBadRequest, }, { - name: "insert domain validation - failed", + name: "insert domain validation - failed", method: http.MethodPost, - url: "/api/v1/admin/domains", + url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domain400Test := &dto.Domain{ProfileName: "p1", TenantID: "t1", DomainSuffix: "domain1.com", ProvisioningCert: "cert1", ProvisioningCertStorageFormat: "string1"} + domain400Test := &dtov1.Domain{ProfileName: "p1", TenantID: "t1", DomainSuffix: "domain1.com", ProvisioningCert: "cert1", ProvisioningCertStorageFormat: "string1"} domain.EXPECT().Insert(context.Background(), domain400Test).Return(nil, domains.ErrDatabase) }, response: domains.ErrDatabase, - requestBody: dto.Domain{ProfileName: "p1", TenantID: "t1", DomainSuffix: "domain1.com", ProvisioningCert: "cert1", ProvisioningCertStorageFormat: "string1"}, + requestBody: dtov1.Domain{ProfileName: "p1", TenantID: "t1", DomainSuffix: "domain1.com", ProvisioningCert: "cert1", ProvisioningCertStorageFormat: "string1"}, expectedCode: http.StatusBadRequest, }, { @@ -177,7 +177,7 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domainTest := &dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + domainTest := &dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} domain.EXPECT().Update(context.Background(), domainTest).Return(domainTest, nil) }, response: responseDomain, @@ -189,7 +189,7 @@ func TestDomainRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/domains", mock: func(domain *MockDomainsFeature) { - domainTest := &dto.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} + domainTest := &dtov1.Domain{ProfileName: "newProfile", TenantID: "tenant1", DomainSuffix: "domain.com", ProvisioningCert: "cert", ProvisioningCertStorageFormat: "string", ProvisioningCertPassword: "password"} domain.EXPECT().Update(context.Background(), domainTest).Return(nil, domains.ErrDatabase) }, response: domains.ErrDatabase, diff --git a/internal/controller/http/v1/error.go b/internal/controller/http/v1/error.go index ff3d0e65..bcce7ebc 100644 --- a/internal/controller/http/v1/error.go +++ b/internal/controller/http/v1/error.go @@ -8,7 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/internal/usecase/domains" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" @@ -22,7 +22,7 @@ func ErrorResponse(c *gin.Context, err error) { var ( validatorErr validator.ValidationErrors nfErr sqldb.NotFoundError - notValidErr dto.NotValidError + notValidErr dtov1.NotValidError dbErr sqldb.DatabaseError NotUniqueErr sqldb.NotUniqueError amtErr devices.AMTError @@ -52,7 +52,7 @@ func ErrorResponse(c *gin.Context, err error) { } } -func notValidErrorHandle(c *gin.Context, err dto.NotValidError) { +func notValidErrorHandle(c *gin.Context, err dtov1.NotValidError) { c.AbortWithStatusJSON(http.StatusBadRequest, response{err.Console.FriendlyMessage()}) } diff --git a/internal/controller/http/v1/ieee8021xconfigs.go b/internal/controller/http/v1/ieee8021xconfigs.go index 37b0a2d6..6f8abee6 100644 --- a/internal/controller/http/v1/ieee8021xconfigs.go +++ b/internal/controller/http/v1/ieee8021xconfigs.go @@ -7,13 +7,13 @@ import ( "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ieee8021xconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) -var ErrValidation8021xConfig = dto.NotValidError{Console: consoleerrors.CreateConsoleError("8021xConfigAPI")} +var ErrValidation8021xConfig = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("8021xConfigAPI")} type ieee8021xConfigRoutes struct { t ieee8021xconfigs.Feature @@ -25,7 +25,7 @@ func NewIEEE8021xConfigRoutes(handler *gin.RouterGroup, t ieee8021xconfigs.Featu if binding.Validator != nil { if v, ok := binding.Validator.Engine().(*validator.Validate); ok { - err := v.RegisterValidation("authProtocolValidator", dto.AuthProtocolValidator) + err := v.RegisterValidation("authProtocolValidator", dtov1.AuthProtocolValidator) if err != nil { l.Error(err, "failed to register validation") } @@ -43,8 +43,8 @@ func NewIEEE8021xConfigRoutes(handler *gin.RouterGroup, t ieee8021xconfigs.Featu } type IEEE8021xConfigCountResponse struct { - Count int `json:"totalCount"` - Data []dto.IEEE8021xConfig `json:"data"` + Count int `json:"totalCount"` + Data []dtov1.IEEE8021xConfig `json:"data"` } func (r *ieee8021xConfigRoutes) get(c *gin.Context) { @@ -97,7 +97,7 @@ func (r *ieee8021xConfigRoutes) getByName(c *gin.Context) { } func (r *ieee8021xConfigRoutes) insert(c *gin.Context) { - var config dto.IEEE8021xConfig + var config dtov1.IEEE8021xConfig if err := c.ShouldBindJSON(&config); err != nil { validationErr := ErrValidation8021xConfig.Wrap("insert", "ShouldBindJSON", err) ErrorResponse(c, validationErr) @@ -117,7 +117,7 @@ func (r *ieee8021xConfigRoutes) insert(c *gin.Context) { } func (r *ieee8021xConfigRoutes) update(c *gin.Context) { - var config dto.IEEE8021xConfig + var config dtov1.IEEE8021xConfig if err := c.ShouldBindJSON(&config); err != nil { validationErr := ErrValidation8021xConfig.Wrap("update", "ShouldBindJSON", err) ErrorResponse(c, validationErr) diff --git a/internal/controller/http/v1/ieee8021xconfigs_mocks_test.go b/internal/controller/http/v1/ieee8021xconfigs_mocks_test.go index 557aeb36..6547393f 100644 --- a/internal/controller/http/v1/ieee8021xconfigs_mocks_test.go +++ b/internal/controller/http/v1/ieee8021xconfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockIEEE8021xConfigsFeatureMockRecorder) Delete(ctx, profileName, tena } // Get mocks base method. -func (m *MockIEEE8021xConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.IEEE8021xConfig, error) { +func (m *MockIEEE8021xConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.IEEE8021xConfig) + ret0, _ := ret[0].([]dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockIEEE8021xConfigsFeatureMockRecorder) Get(ctx, top, skip, tenantID } // GetByName mocks base method. -func (m *MockIEEE8021xConfigsFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEE8021xConfigsFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, profileName, tenantID) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockIEEE8021xConfigsFeatureMockRecorder) GetCount(ctx, tenantID any) * } // Insert mocks base method. -func (m *MockIEEE8021xConfigsFeature) Insert(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEE8021xConfigsFeature) Insert(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockIEEE8021xConfigsFeatureMockRecorder) Insert(ctx, p any) *gomock.Ca } // Update mocks base method. -func (m *MockIEEE8021xConfigsFeature) Update(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEE8021xConfigsFeature) Update(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/ieee8021xconfigs_test.go b/internal/controller/http/v1/ieee8021xconfigs_test.go index 96cafd39..3b0449fb 100644 --- a/internal/controller/http/v1/ieee8021xconfigs_test.go +++ b/internal/controller/http/v1/ieee8021xconfigs_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ieee8021xconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -40,13 +40,13 @@ type testIEEE8021xConfigs struct { url string mock func(repo *MockIEEE8021xConfigsFeature) response interface{} - requestBody dto.IEEE8021xConfig + requestBody dtov1.IEEE8021xConfig expectedCode int } var pxeTime = 120 -var ieee8021xconfigTest = dto.IEEE8021xConfig{ +var ieee8021xconfigTest = dtov1.IEEE8021xConfig{ ProfileName: "newprofile", AuthenticationProtocol: 2, PXETimeout: &pxeTime, @@ -64,11 +64,11 @@ func TestIEEE8021xConfigsRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ieee8021xconfigs", mock: func(ieeeConfig *MockIEEE8021xConfigsFeature) { - ieeeConfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.IEEE8021xConfig{{ + ieeeConfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.IEEE8021xConfig{{ ProfileName: "profile", }}, nil) }, - response: []dto.IEEE8021xConfig{{ProfileName: "profile"}}, + response: []dtov1.IEEE8021xConfig{{ProfileName: "profile"}}, expectedCode: http.StatusOK, }, { @@ -76,12 +76,12 @@ func TestIEEE8021xConfigsRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ieee8021xconfigs?$top=10&$skip=1&$count=true", mock: func(ieeeConfig *MockIEEE8021xConfigsFeature) { - ieeeConfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.IEEE8021xConfig{{ + ieeeConfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.IEEE8021xConfig{{ ProfileName: "profile", }}, nil) ieeeConfig.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: IEEE8021xConfigCountResponse{Count: 1, Data: []dto.IEEE8021xConfig{{ProfileName: "profile"}}}, + response: IEEE8021xConfigCountResponse{Count: 1, Data: []dtov1.IEEE8021xConfig{{ProfileName: "profile"}}}, expectedCode: http.StatusOK, }, { @@ -99,11 +99,11 @@ func TestIEEE8021xConfigsRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/ieee8021xconfigs/profile", mock: func(ieeeConfig *MockIEEE8021xConfigsFeature) { - ieeeConfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.IEEE8021xConfig{ + ieeeConfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.IEEE8021xConfig{ ProfileName: "profile", }, nil) }, - response: dto.IEEE8021xConfig{ProfileName: "profile"}, + response: dtov1.IEEE8021xConfig{ProfileName: "profile"}, expectedCode: http.StatusOK, }, { diff --git a/internal/controller/http/v1/profiles.go b/internal/controller/http/v1/profiles.go index 330e00b8..517a79ff 100644 --- a/internal/controller/http/v1/profiles.go +++ b/internal/controller/http/v1/profiles.go @@ -7,13 +7,13 @@ import ( "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/profiles" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) -var ErrValidationProfile = dto.NotValidError{Console: consoleerrors.CreateConsoleError("ProfileAPI")} +var ErrValidationProfile = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("ProfileAPI")} type profileRoutes struct { t profiles.Feature @@ -25,8 +25,8 @@ func NewProfileRoutes(handler *gin.RouterGroup, t profiles.Feature, l logger.Int if binding.Validator != nil { if v, ok := binding.Validator.Engine().(*validator.Validate); ok { - _ = v.RegisterValidation("genpasswordwone", dto.ValidateAMTPassOrGenRan) - _ = v.RegisterValidation("ciraortls", dto.ValidateCIRAOrTLS) + _ = v.RegisterValidation("genpasswordwone", dtov1.ValidateAMTPassOrGenRan) + _ = v.RegisterValidation("ciraortls", dtov1.ValidateCIRAOrTLS) } } @@ -41,8 +41,8 @@ func NewProfileRoutes(handler *gin.RouterGroup, t profiles.Feature, l logger.Int } type ProfileCountResponse struct { - Count int `json:"totalCount"` - Data []dto.Profile `json:"data"` + Count int `json:"totalCount"` + Data []dtov1.Profile `json:"data"` } // @Summary Show Profiles @@ -124,7 +124,7 @@ func (r *profileRoutes) getByName(c *gin.Context) { // @Router /api/v1/admin/profiles [post] func (r *profileRoutes) insert(c *gin.Context) { - var profile dto.Profile + var profile dtov1.Profile if err := c.ShouldBindJSON(&profile); err != nil { validationErr := ErrValidationProfile.Wrap("insert", "ShouldBindJSON", err) ErrorResponse(c, validationErr) @@ -154,7 +154,7 @@ func (r *profileRoutes) insert(c *gin.Context) { // @Router /api/v1/admin/Profiles [patch] func (r *profileRoutes) update(c *gin.Context) { - var profile dto.Profile + var profile dtov1.Profile if err := c.ShouldBindJSON(&profile); err != nil { validationErr := ErrValidationProfile.Wrap("update", "ShouldBindJSON", err) ErrorResponse(c, validationErr) diff --git a/internal/controller/http/v1/profiles_mocks_test.go b/internal/controller/http/v1/profiles_mocks_test.go index 0c7dd9e8..5a269296 100644 --- a/internal/controller/http/v1/profiles_mocks_test.go +++ b/internal/controller/http/v1/profiles_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -169,10 +169,10 @@ func (mr *MockProfilesFeatureMockRecorder) Delete(ctx, profileName, tenantID any } // Get mocks base method. -func (m *MockProfilesFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Profile, error) { +func (m *MockProfilesFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Profile) + ret0, _ := ret[0].([]dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -184,10 +184,10 @@ func (mr *MockProfilesFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *go } // GetByName mocks base method. -func (m *MockProfilesFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dto.Profile, error) { +func (m *MockProfilesFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, profileName, tenantID) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockProfilesFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.C } // Insert mocks base method. -func (m *MockProfilesFeature) Insert(ctx context.Context, p *dto.Profile) (*dto.Profile, error) { +func (m *MockProfilesFeature) Insert(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockProfilesFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockProfilesFeature) Update(ctx context.Context, p *dto.Profile) (*dto.Profile, error) { +func (m *MockProfilesFeature) Update(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/profiles_test.go b/internal/controller/http/v1/profiles_test.go index a4a1eb95..10c95005 100644 --- a/internal/controller/http/v1/profiles_test.go +++ b/internal/controller/http/v1/profiles_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" gomock "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/profiles" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -40,11 +40,11 @@ type testProfiles struct { url string mock func(repo *MockProfilesFeature) response interface{} - requestBody dto.Profile + requestBody dtov1.Profile expectedCode int } -var profileTest = dto.Profile{ +var profileTest = dtov1.Profile{ ProfileName: "newprofile", AMTPassword: "P@ssw0rd", GenerateRandomPassword: false, @@ -80,11 +80,11 @@ func TestProfileRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/profiles", mock: func(profile *MockProfilesFeature) { - profile.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.Profile{{ + profile.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.Profile{{ ProfileName: "profile", }}, nil) }, - response: []dto.Profile{{ProfileName: "profile"}}, + response: []dtov1.Profile{{ProfileName: "profile"}}, expectedCode: http.StatusOK, }, { @@ -92,12 +92,12 @@ func TestProfileRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/profiles?$top=10&$skip=1&$count=true", mock: func(domain *MockProfilesFeature) { - domain.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.Profile{{ + domain.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.Profile{{ ProfileName: "profile", }}, nil) domain.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: ProfileCountResponse{Count: 1, Data: []dto.Profile{{ProfileName: "profile"}}}, + response: ProfileCountResponse{Count: 1, Data: []dtov1.Profile{{ProfileName: "profile"}}}, expectedCode: http.StatusOK, }, { @@ -115,11 +115,11 @@ func TestProfileRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/profiles/profile", mock: func(profile *MockProfilesFeature) { - profile.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.Profile{ + profile.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.Profile{ ProfileName: "profile", }, nil) }, - response: dto.Profile{ProfileName: "profile"}, + response: dtov1.Profile{ProfileName: "profile"}, expectedCode: http.StatusOK, }, { diff --git a/internal/controller/http/v1/wificonfigs.go b/internal/controller/http/v1/wificonfigs.go index 2891f91c..049fac38 100644 --- a/internal/controller/http/v1/wificonfigs.go +++ b/internal/controller/http/v1/wificonfigs.go @@ -7,13 +7,13 @@ import ( "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/wificonfigs" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) -var ErrValidationWifiConfig = dto.NotValidError{Console: consoleerrors.CreateConsoleError("WifiConfigsAPI")} +var ErrValidationWifiConfig = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("WifiConfigsAPI")} type WirelessConfigRoutes struct { t wificonfigs.Feature @@ -25,7 +25,7 @@ func NewWirelessConfigRoutes(handler *gin.RouterGroup, t wificonfigs.Feature, l if binding.Validator != nil { if v, ok := binding.Validator.Engine().(*validator.Validate); ok { - err := v.RegisterValidation("authforieee8021x", dto.ValidateAuthandIEEE) + err := v.RegisterValidation("authforieee8021x", dtov1.ValidateAuthandIEEE) if err != nil { l.Error(err, "failed to register validation") } @@ -66,7 +66,7 @@ func (r *WirelessConfigRoutes) get(c *gin.Context) { ErrorResponse(c, err) } - countResponse := dto.WirelessConfigCountResponse{ + countResponse := dtov1.WirelessConfigCountResponse{ Count: count, Data: items, } @@ -92,7 +92,7 @@ func (r *WirelessConfigRoutes) getByName(c *gin.Context) { } func (r *WirelessConfigRoutes) insert(c *gin.Context) { - var config dto.WirelessConfig + var config dtov1.WirelessConfig if err := c.ShouldBindJSON(&config); err != nil { validationErr := ErrValidationWifiConfig.Wrap("insert", "ShouldBindJSON", err) ErrorResponse(c, validationErr) @@ -113,7 +113,7 @@ func (r *WirelessConfigRoutes) insert(c *gin.Context) { } func (r *WirelessConfigRoutes) update(c *gin.Context) { - var config dto.WirelessConfig + var config dtov1.WirelessConfig if err := c.ShouldBindJSON(&config); err != nil { validationErr := ErrValidationWifiConfig.Wrap("update", "ShouldBindJSON", err) ErrorResponse(c, validationErr) diff --git a/internal/controller/http/v1/wificonfigs_mocks_test.go b/internal/controller/http/v1/wificonfigs_mocks_test.go index 3bc96f0b..3b030595 100644 --- a/internal/controller/http/v1/wificonfigs_mocks_test.go +++ b/internal/controller/http/v1/wificonfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockWiFiConfigsFeatureMockRecorder) Delete(ctx, profileName, tenantID } // Get mocks base method. -func (m *MockWiFiConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.WirelessConfig, error) { +func (m *MockWiFiConfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.WirelessConfig) + ret0, _ := ret[0].([]dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockWiFiConfigsFeatureMockRecorder) Get(ctx, top, skip, tenantID any) } // GetByName mocks base method. -func (m *MockWiFiConfigsFeature) GetByName(ctx context.Context, guid, tenantID string) (*dto.WirelessConfig, error) { +func (m *MockWiFiConfigsFeature) GetByName(ctx context.Context, guid, tenantID string) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockWiFiConfigsFeatureMockRecorder) GetCount(ctx, tenantID any) *gomoc } // Insert mocks base method. -func (m *MockWiFiConfigsFeature) Insert(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockWiFiConfigsFeature) Insert(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockWiFiConfigsFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockWiFiConfigsFeature) Update(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockWiFiConfigsFeature) Update(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v1/wificonfigs_test.go b/internal/controller/http/v1/wificonfigs_test.go index e029f400..a1cd5b46 100644 --- a/internal/controller/http/v1/wificonfigs_test.go +++ b/internal/controller/http/v1/wificonfigs_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/wificonfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -40,13 +40,13 @@ type wifiConfigTest struct { url string mock func(repo *MockWiFiConfigsFeature) response interface{} - requestBody dto.WirelessConfig + requestBody dtov1.WirelessConfig expectedCode int } var ( - requestWiFiConfig = dto.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"} - responseWiFiConfig = dto.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"} + requestWiFiConfig = dtov1.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"} + responseWiFiConfig = dtov1.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"} ) func TestWiFiConfigRoutes(t *testing.T) { @@ -58,11 +58,11 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.WirelessConfig{{ + wificonfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.WirelessConfig{{ ProfileName: "profile", }}, nil) }, - response: []dto.WirelessConfig{{ProfileName: "profile"}}, + response: []dtov1.WirelessConfig{{ProfileName: "profile"}}, expectedCode: http.StatusOK, }, { @@ -70,12 +70,12 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/wirelessconfigs?$top=10&$skip=1&$count=true", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.WirelessConfig{{ + wificonfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.WirelessConfig{{ ProfileName: "profile", }}, nil) wificonfig.EXPECT().GetCount(context.Background(), "").Return(1, nil) }, - response: dto.WirelessConfigCountResponse{Count: 1, Data: []dto.WirelessConfig{{ProfileName: "profile"}}}, + response: dtov1.WirelessConfigCountResponse{Count: 1, Data: []dtov1.WirelessConfig{{ProfileName: "profile"}}}, expectedCode: http.StatusOK, }, { @@ -93,11 +93,11 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodGet, url: "/api/v1/admin/wirelessconfigs/profile", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.WirelessConfig{ + wificonfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.WirelessConfig{ ProfileName: "profile", }, nil) }, - response: dto.WirelessConfig{ProfileName: "profile"}, + response: dtov1.WirelessConfig{ProfileName: "profile"}, expectedCode: http.StatusOK, }, { @@ -115,7 +115,7 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfigTest := &dto.WirelessConfig{ + wificonfigTest := &dtov1.WirelessConfig{ AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", @@ -137,7 +137,7 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfigTest := &dto.WirelessConfig{ + wificonfigTest := &dtov1.WirelessConfig{ AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", @@ -159,7 +159,7 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodPost, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfigTest := &dto.WirelessConfig{ + wificonfigTest := &dtov1.WirelessConfig{ AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", @@ -173,7 +173,7 @@ func TestWiFiConfigRoutes(t *testing.T) { wificonfig.EXPECT().Insert(context.Background(), wificonfigTest).Return(nil, wificonfigs.ErrDatabase) }, response: wificonfigs.ErrDatabase, - requestBody: dto.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"}, + requestBody: dtov1.WirelessConfig{AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", PSKValue: 12345, PSKPassphrase: "examplepassphrase", ProfileName: "newprofile", LinkPolicy: []int{1, 2, 3}, TenantID: "tenant1", Version: "1.0"}, expectedCode: http.StatusBadRequest, }, { @@ -201,7 +201,7 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfigTest := &dto.WirelessConfig{ + wificonfigTest := &dtov1.WirelessConfig{ AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", @@ -223,7 +223,7 @@ func TestWiFiConfigRoutes(t *testing.T) { method: http.MethodPatch, url: "/api/v1/admin/wirelessconfigs", mock: func(wificonfig *MockWiFiConfigsFeature) { - wificonfigTest := &dto.WirelessConfig{ + wificonfigTest := &dtov1.WirelessConfig{ AuthenticationMethod: 4, EncryptionMethod: 3, SSID: "exampleSSID", diff --git a/internal/controller/http/v1/wsman_mocks_test.go b/internal/controller/http/v1/wsman_mocks_test.go index efcfd018..572aa25d 100644 --- a/internal/controller/http/v1/wsman_mocks_test.go +++ b/internal/controller/http/v1/wsman_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" time "time" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" alarmclock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock" auditlog "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/auditlog" @@ -266,10 +266,10 @@ func (mr *MockManagementMockRecorder) GetEventLog() *gomock.Call { } // GetFeatures mocks base method. -func (m *MockManagement) GetFeatures() (dto.Features, error) { +func (m *MockManagement) GetFeatures() (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures") - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -461,10 +461,10 @@ func (mr *MockManagementMockRecorder) SetBootData(data any) *gomock.Call { } // SetFeatures mocks base method. -func (m *MockManagement) SetFeatures(arg0 dto.Features) (dto.Features, error) { +func (m *MockManagement) SetFeatures(arg0 dtov1.Features) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", arg0) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v2/devicemanagement.go b/internal/controller/http/v2/devicemanagement.go index 7150b34b..ba6bee18 100644 --- a/internal/controller/http/v2/devicemanagement.go +++ b/internal/controller/http/v2/devicemanagement.go @@ -20,10 +20,26 @@ func NewAmtRoutes(handler *gin.RouterGroup, d devices.Feature, l logger.Interfac h := handler.Group("/amt") { + h.GET("version/:guid", r.getVersion) + h.GET("features/:guid", r.getFeatures) } } +func (r *deviceManagementRoutes) getVersion(c *gin.Context) { + guid := c.Param("guid") + + _, v2, err := r.d.GetVersion(c.Request.Context(), guid) + if err != nil { + r.l.Error(err, "http - v2 - GetVersion") + v1.ErrorResponse(c, err) + + return + } + + c.JSON(http.StatusOK, v2) +} + func (r *deviceManagementRoutes) getFeatures(c *gin.Context) { guid := c.Param("guid") diff --git a/internal/controller/http/v2/devicemanagement_mocks_test.go b/internal/controller/http/v2/devicemanagement_mocks_test.go index b4dee1b4..92bb4161 100644 --- a/internal/controller/http/v2/devicemanagement_mocks_test.go +++ b/internal/controller/http/v2/devicemanagement_mocks_test.go @@ -15,7 +15,8 @@ import ( websocket "github.com/gorilla/websocket" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" wsman0 "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" @@ -47,7 +48,7 @@ func (m *MockWSMAN) EXPECT() *MockWSMANMockRecorder { } // DestroyWsmanClient mocks base method. -func (m *MockWSMAN) DestroyWsmanClient(device dto.Device) { +func (m *MockWSMAN) DestroyWsmanClient(device dtov1.Device) { m.ctrl.T.Helper() m.ctrl.Call(m, "DestroyWsmanClient", device) } @@ -59,7 +60,7 @@ func (mr *MockWSMANMockRecorder) DestroyWsmanClient(device any) *gomock.Call { } // SetupWsmanClient mocks base method. -func (m *MockWSMAN) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman.Management { +func (m *MockWSMAN) SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsman.Management { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman.Management) @@ -165,7 +166,7 @@ func (mr *MockRedirectionMockRecorder) RedirectSend(ctx, deviceConnection, messa } // SetupWsmanClient mocks base method. -func (m *MockRedirection) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman0.Messages { +func (m *MockRedirection) SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsman0.Messages { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman0.Messages) @@ -375,10 +376,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) CancelUserConsent(ctx, guid a } // CreateAlarmOccurrences mocks base method. -func (m *MockDeviceManagementFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) { +func (m *MockDeviceManagementFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateAlarmOccurrences", ctx, guid, alarm) - ret0, _ := ret[0].(dto.AddAlarmOutput) + ret0, _ := ret[0].(dtov1.AddAlarmOutput) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -418,10 +419,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) DeleteAlarmOccurrences(ctx, g } // Get mocks base method. -func (m *MockDeviceManagementFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -433,10 +434,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) Get(ctx, top, skip, tenantID } // GetAlarmOccurrences mocks base method. -func (m *MockDeviceManagementFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) { +func (m *MockDeviceManagementFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAlarmOccurrences", ctx, guid) - ret0, _ := ret[0].([]dto.AlarmClockOccurrence) + ret0, _ := ret[0].([]dtov1.AlarmClockOccurrence) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -448,10 +449,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetAlarmOccurrences(ctx, guid } // GetAuditLog mocks base method. -func (m *MockDeviceManagementFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) { +func (m *MockDeviceManagementFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dtov1.AuditLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAuditLog", ctx, startIndex, guid) - ret0, _ := ret[0].(dto.AuditLog) + ret0, _ := ret[0].(dtov1.AuditLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -463,10 +464,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetAuditLog(ctx, startIndex, } // GetByColumn mocks base method. -func (m *MockDeviceManagementFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByColumn", ctx, columnName, queryValue, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -478,10 +479,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByColumn(ctx, columnName, } // GetByID mocks base method. -func (m *MockDeviceManagementFeature) GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByID", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -493,10 +494,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByID(ctx, guid, tenantID a } // GetByTags mocks base method. -func (m *MockDeviceManagementFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) { +func (m *MockDeviceManagementFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByTags", ctx, tags, method, limit, offset, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -508,10 +509,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetByTags(ctx, tags, method, } // GetCertificates mocks base method. -func (m *MockDeviceManagementFeature) GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) { +func (m *MockDeviceManagementFeature) GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCertificates", c, guid) - ret0, _ := ret[0].(dto.SecuritySettings) + ret0, _ := ret[0].(dtov1.SecuritySettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -538,10 +539,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetCount(arg0, arg1 any) *gom } // GetDeviceCertificate mocks base method. -func (m *MockDeviceManagementFeature) GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) { +func (m *MockDeviceManagementFeature) GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDeviceCertificate", c, guid) - ret0, _ := ret[0].(dto.Certificate) + ret0, _ := ret[0].(dtov1.Certificate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -583,10 +584,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetDistinctTags(ctx, tenantID } // GetEventLog mocks base method. -func (m *MockDeviceManagementFeature) GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) { +func (m *MockDeviceManagementFeature) GetEventLog(ctx context.Context, guid string) ([]dtov1.EventLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEventLog", ctx, guid) - ret0, _ := ret[0].([]dto.EventLog) + ret0, _ := ret[0].([]dtov1.EventLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -598,10 +599,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetEventLog(ctx, guid any) *g } // GetFeatures mocks base method. -func (m *MockDeviceManagementFeature) GetFeatures(ctx context.Context, guid string) (dto.Features, error) { +func (m *MockDeviceManagementFeature) GetFeatures(ctx context.Context, guid string) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures", ctx, guid) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -643,10 +644,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetHardwareInfo(ctx, guid any } // GetNetworkSettings mocks base method. -func (m *MockDeviceManagementFeature) GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) { +func (m *MockDeviceManagementFeature) GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNetworkSettings", c, guid) - ret0, _ := ret[0].(dto.NetworkSettings) + ret0, _ := ret[0].(dtov1.NetworkSettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -688,10 +689,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetPowerState(ctx, guid any) } // GetTLSSettingData mocks base method. -func (m *MockDeviceManagementFeature) GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) { +func (m *MockDeviceManagementFeature) GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTLSSettingData", c, guid) - ret0, _ := ret[0].([]dto.SettingDataResponse) + ret0, _ := ret[0].([]dtov1.SettingDataResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -718,12 +719,13 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetUserConsentCode(ctx, guid } // GetVersion mocks base method. -func (m *MockDeviceManagementFeature) GetVersion(ctx context.Context, guid string) (map[string]any, error) { +func (m *MockDeviceManagementFeature) GetVersion(ctx context.Context, guid string) (dtov1.Version, dtov2.Version, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetVersion", ctx, guid) - ret0, _ := ret[0].(map[string]any) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(dtov1.Version) + ret1, _ := ret[1].(dtov2.Version) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // GetVersion indicates an expected call of GetVersion. @@ -733,10 +735,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) GetVersion(ctx, guid any) *go } // Insert mocks base method. -func (m *MockDeviceManagementFeature) Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -762,7 +764,7 @@ func (mr *MockDeviceManagementFeatureMockRecorder) Redirect(ctx, conn, guid, mod } // SendConsentCode mocks base method. -func (m *MockDeviceManagementFeature) SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (any, error) { +func (m *MockDeviceManagementFeature) SendConsentCode(ctx context.Context, code dtov1.UserConsent, guid string) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendConsentCode", ctx, code, guid) ret0, _ := ret[0].(any) @@ -792,7 +794,7 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SendPowerAction(ctx, guid, ac } // SetBootOptions mocks base method. -func (m *MockDeviceManagementFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) { +func (m *MockDeviceManagementFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetBootOptions", ctx, guid, bootSetting) ret0, _ := ret[0].(power.PowerActionResponse) @@ -807,10 +809,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SetBootOptions(ctx, guid, boo } // SetFeatures mocks base method. -func (m *MockDeviceManagementFeature) SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) { +func (m *MockDeviceManagementFeature) SetFeatures(ctx context.Context, guid string, features dtov1.Features) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", ctx, guid, features) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -822,10 +824,10 @@ func (mr *MockDeviceManagementFeatureMockRecorder) SetFeatures(ctx, guid, featur } // Update mocks base method. -func (m *MockDeviceManagementFeature) Update(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockDeviceManagementFeature) Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/http/v2/devicemanagement_test.go b/internal/controller/http/v2/devicemanagement_test.go index 1a40a9bd..013d586e 100644 --- a/internal/controller/http/v2/devicemanagement_test.go +++ b/internal/controller/http/v2/devicemanagement_test.go @@ -13,7 +13,8 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -48,16 +49,27 @@ func TestGetFeatures(t *testing.T) { expectedCode int response interface{} }{ + { + name: "getVersion - successful retrieval", + url: "/api/v2/amt/version/valid-guid", + method: http.MethodGet, + mock: func(m *MockDeviceManagementFeature) { + m.EXPECT().GetVersion(context.Background(), "valid-guid"). + Return(dtov1.Version{}, dtov2.Version{}, nil) + }, + expectedCode: http.StatusOK, + response: dtov2.Version{}, + }, { name: "getFeatures - successful retrieval", url: "/api/v2/amt/features/valid-guid", method: http.MethodGet, mock: func(m *MockDeviceManagementFeature) { m.EXPECT().GetFeatures(context.Background(), "valid-guid"). - Return(dto.Features{}, nil) + Return(dtov1.Features{}, nil) }, expectedCode: http.StatusOK, - response: dto.Features{}, + response: dtov1.Features{}, }, } diff --git a/internal/controller/ws/v1/interface.go b/internal/controller/ws/v1/interface.go index d0a6b4e2..87652f44 100644 --- a/internal/controller/ws/v1/interface.go +++ b/internal/controller/ws/v1/interface.go @@ -6,8 +6,10 @@ import ( "github.com/gin-gonic/gin" "github.com/gorilla/websocket" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" //nolint:gci // Import order is intentionally not changed due to project-specific requirements. - "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/power" //nolint:gci // Import order is intentionally not changed due to project-specific requirements. + "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/power" + + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" ) // Upgrader defines the interface for upgrading an HTTP connection to a WebSocket connection. @@ -25,20 +27,20 @@ type Redirect interface { type Feature interface { // Repository/Database Calls GetCount(context.Context, string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) - GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) + GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) GetDistinctTags(ctx context.Context, tenantID string) ([]string, error) - GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) + GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) Delete(ctx context.Context, guid, tenantID string) error - Update(ctx context.Context, d *dto.Device) (*dto.Device, error) - Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) - GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) + Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) + Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) + GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) // Management Calls - GetVersion(ctx context.Context, guid string) (map[string]interface{}, error) - GetFeatures(ctx context.Context, guid string) (dto.Features, error) - SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) - GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) - CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) + GetVersion(ctx context.Context, guid string) (dtov1.Version, dtov2.Version, error) + GetFeatures(ctx context.Context, guid string) (dtov1.Features, error) + SetFeatures(ctx context.Context, guid string, features dtov1.Features) (dtov1.Features, error) + GetAlarmOccurrences(ctx context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) + CreateAlarmOccurrences(ctx context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) DeleteAlarmOccurrences(ctx context.Context, guid, instanceID string) error GetHardwareInfo(ctx context.Context, guid string) (interface{}, error) GetPowerState(ctx context.Context, guid string) (map[string]interface{}, error) @@ -46,15 +48,15 @@ type Feature interface { GetGeneralSettings(ctx context.Context, guid string) (interface{}, error) CancelUserConsent(ctx context.Context, guid string) (interface{}, error) GetUserConsentCode(ctx context.Context, guid string) (map[string]interface{}, error) - SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (interface{}, error) + SendConsentCode(ctx context.Context, code dtov1.UserConsent, guid string) (interface{}, error) SendPowerAction(ctx context.Context, guid string, action int) (power.PowerActionResponse, error) - SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) - GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) - GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) + SetBootOptions(ctx context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) + GetAuditLog(ctx context.Context, startIndex int, guid string) (dtov1.AuditLog, error) + GetEventLog(ctx context.Context, guid string) ([]dtov1.EventLog, error) Redirect(ctx context.Context, conn *websocket.Conn, guid, mode string) error - GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) - GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) - GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) + GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) + GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) + GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) GetDiskInfo(c context.Context, guid string) (interface{}, error) - GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) + GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) } diff --git a/internal/controller/ws/v1/mocks_test.go b/internal/controller/ws/v1/mocks_test.go index b71ec43b..d57dd4cd 100644 --- a/internal/controller/ws/v1/mocks_test.go +++ b/internal/controller/ws/v1/mocks_test.go @@ -16,7 +16,8 @@ import ( gin "github.com/gin-gonic/gin" websocket "github.com/gorilla/websocket" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" power "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/power" gomock "go.uber.org/mock/gomock" ) @@ -135,10 +136,10 @@ func (mr *MockFeatureMockRecorder) CancelUserConsent(ctx, guid any) *gomock.Call } // CreateAlarmOccurrences mocks base method. -func (m *MockFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) { +func (m *MockFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateAlarmOccurrences", ctx, guid, alarm) - ret0, _ := ret[0].(dto.AddAlarmOutput) + ret0, _ := ret[0].(dtov1.AddAlarmOutput) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -178,10 +179,10 @@ func (mr *MockFeatureMockRecorder) DeleteAlarmOccurrences(ctx, guid, instanceID } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -193,10 +194,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetAlarmOccurrences mocks base method. -func (m *MockFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) { +func (m *MockFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAlarmOccurrences", ctx, guid) - ret0, _ := ret[0].([]dto.AlarmClockOccurrence) + ret0, _ := ret[0].([]dtov1.AlarmClockOccurrence) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -208,10 +209,10 @@ func (mr *MockFeatureMockRecorder) GetAlarmOccurrences(ctx, guid any) *gomock.Ca } // GetAuditLog mocks base method. -func (m *MockFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) { +func (m *MockFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dtov1.AuditLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAuditLog", ctx, startIndex, guid) - ret0, _ := ret[0].(dto.AuditLog) + ret0, _ := ret[0].(dtov1.AuditLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -223,10 +224,10 @@ func (mr *MockFeatureMockRecorder) GetAuditLog(ctx, startIndex, guid any) *gomoc } // GetByColumn mocks base method. -func (m *MockFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByColumn", ctx, columnName, queryValue, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -238,10 +239,10 @@ func (mr *MockFeatureMockRecorder) GetByColumn(ctx, columnName, queryValue, tena } // GetByID mocks base method. -func (m *MockFeature) GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) { +func (m *MockFeature) GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByID", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -253,10 +254,10 @@ func (mr *MockFeatureMockRecorder) GetByID(ctx, guid, tenantID any) *gomock.Call } // GetByTags mocks base method. -func (m *MockFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByTags", ctx, tags, method, limit, offset, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -268,10 +269,10 @@ func (mr *MockFeatureMockRecorder) GetByTags(ctx, tags, method, limit, offset, t } // GetCertificates mocks base method. -func (m *MockFeature) GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) { +func (m *MockFeature) GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCertificates", c, guid) - ret0, _ := ret[0].(dto.SecuritySettings) + ret0, _ := ret[0].(dtov1.SecuritySettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -298,10 +299,10 @@ func (mr *MockFeatureMockRecorder) GetCount(arg0, arg1 any) *gomock.Call { } // GetDeviceCertificate mocks base method. -func (m *MockFeature) GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) { +func (m *MockFeature) GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDeviceCertificate", c, guid) - ret0, _ := ret[0].(dto.Certificate) + ret0, _ := ret[0].(dtov1.Certificate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -343,10 +344,10 @@ func (mr *MockFeatureMockRecorder) GetDistinctTags(ctx, tenantID any) *gomock.Ca } // GetEventLog mocks base method. -func (m *MockFeature) GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) { +func (m *MockFeature) GetEventLog(ctx context.Context, guid string) ([]dtov1.EventLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEventLog", ctx, guid) - ret0, _ := ret[0].([]dto.EventLog) + ret0, _ := ret[0].([]dtov1.EventLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -358,10 +359,10 @@ func (mr *MockFeatureMockRecorder) GetEventLog(ctx, guid any) *gomock.Call { } // GetFeatures mocks base method. -func (m *MockFeature) GetFeatures(ctx context.Context, guid string) (dto.Features, error) { +func (m *MockFeature) GetFeatures(ctx context.Context, guid string) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures", ctx, guid) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -403,10 +404,10 @@ func (mr *MockFeatureMockRecorder) GetHardwareInfo(ctx, guid any) *gomock.Call { } // GetNetworkSettings mocks base method. -func (m *MockFeature) GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) { +func (m *MockFeature) GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNetworkSettings", c, guid) - ret0, _ := ret[0].(dto.NetworkSettings) + ret0, _ := ret[0].(dtov1.NetworkSettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -448,10 +449,10 @@ func (mr *MockFeatureMockRecorder) GetPowerState(ctx, guid any) *gomock.Call { } // GetTLSSettingData mocks base method. -func (m *MockFeature) GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) { +func (m *MockFeature) GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTLSSettingData", c, guid) - ret0, _ := ret[0].([]dto.SettingDataResponse) + ret0, _ := ret[0].([]dtov1.SettingDataResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -478,12 +479,13 @@ func (mr *MockFeatureMockRecorder) GetUserConsentCode(ctx, guid any) *gomock.Cal } // GetVersion mocks base method. -func (m *MockFeature) GetVersion(ctx context.Context, guid string) (map[string]any, error) { +func (m *MockFeature) GetVersion(ctx context.Context, guid string) (dtov1.Version, dtov2.Version, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetVersion", ctx, guid) - ret0, _ := ret[0].(map[string]any) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(dtov1.Version) + ret1, _ := ret[1].(dtov2.Version) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // GetVersion indicates an expected call of GetVersion. @@ -493,10 +495,10 @@ func (mr *MockFeatureMockRecorder) GetVersion(ctx, guid any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockFeature) Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -522,7 +524,7 @@ func (mr *MockFeatureMockRecorder) Redirect(ctx, conn, guid, mode any) *gomock.C } // SendConsentCode mocks base method. -func (m *MockFeature) SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (any, error) { +func (m *MockFeature) SendConsentCode(ctx context.Context, code dtov1.UserConsent, guid string) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendConsentCode", ctx, code, guid) ret0, _ := ret[0].(any) @@ -552,7 +554,7 @@ func (mr *MockFeatureMockRecorder) SendPowerAction(ctx, guid, action any) *gomoc } // SetBootOptions mocks base method. -func (m *MockFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) { +func (m *MockFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetBootOptions", ctx, guid, bootSetting) ret0, _ := ret[0].(power.PowerActionResponse) @@ -567,10 +569,10 @@ func (mr *MockFeatureMockRecorder) SetBootOptions(ctx, guid, bootSetting any) *g } // SetFeatures mocks base method. -func (m *MockFeature) SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) { +func (m *MockFeature) SetFeatures(ctx context.Context, guid string, features dtov1.Features) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", ctx, guid, features) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -582,10 +584,10 @@ func (mr *MockFeatureMockRecorder) SetFeatures(ctx, guid, features any) *gomock. } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockFeature) Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*dtov1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/entity/dto/alarm.go b/internal/entity/dto/v1/alarm.go similarity index 97% rename from internal/entity/dto/alarm.go rename to internal/entity/dto/v1/alarm.go index e700372f..58769295 100644 --- a/internal/entity/dto/alarm.go +++ b/internal/entity/dto/v1/alarm.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import "time" diff --git a/internal/entity/dto/auditlog.go b/internal/entity/dto/v1/auditlog.go similarity index 98% rename from internal/entity/dto/auditlog.go rename to internal/entity/dto/v1/auditlog.go index afbf8f1f..b6e6a978 100644 --- a/internal/entity/dto/auditlog.go +++ b/internal/entity/dto/v1/auditlog.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/auditlog" diff --git a/internal/entity/dto/bootsetting.go b/internal/entity/dto/v1/bootsetting.go similarity index 92% rename from internal/entity/dto/bootsetting.go rename to internal/entity/dto/v1/bootsetting.go index bd5c4853..333dc8c7 100644 --- a/internal/entity/dto/bootsetting.go +++ b/internal/entity/dto/v1/bootsetting.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type BootSetting struct { Action int `json:"action" binding:"required" example:"8"` diff --git a/internal/entity/dto/ciraconfig.go b/internal/entity/dto/v1/ciraconfig.go similarity index 99% rename from internal/entity/dto/ciraconfig.go rename to internal/entity/dto/v1/ciraconfig.go index d73eb6ca..4e4dd8b9 100644 --- a/internal/entity/dto/ciraconfig.go +++ b/internal/entity/dto/v1/ciraconfig.go @@ -1,4 +1,4 @@ -package dto +package dtov1 const ( ServerAddressFormatIPv4 = 3 diff --git a/internal/entity/dto/device.go b/internal/entity/dto/v1/device.go similarity index 99% rename from internal/entity/dto/device.go rename to internal/entity/dto/v1/device.go index 98b088f4..14348a1a 100644 --- a/internal/entity/dto/device.go +++ b/internal/entity/dto/v1/device.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import ( "time" diff --git a/internal/entity/dto/domain.go b/internal/entity/dto/v1/domain.go similarity index 98% rename from internal/entity/dto/domain.go rename to internal/entity/dto/v1/domain.go index 623731a5..9db51d14 100644 --- a/internal/entity/dto/domain.go +++ b/internal/entity/dto/v1/domain.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import "time" diff --git a/internal/entity/dto/eventlog.go b/internal/entity/dto/v1/eventlog.go similarity index 97% rename from internal/entity/dto/eventlog.go rename to internal/entity/dto/v1/eventlog.go index f6af359b..ed06212d 100644 --- a/internal/entity/dto/eventlog.go +++ b/internal/entity/dto/v1/eventlog.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type EventLog struct { DeviceAddress int `json:"DeviceAddress"` diff --git a/internal/entity/dto/features.go b/internal/entity/dto/v1/features.go similarity index 96% rename from internal/entity/dto/features.go rename to internal/entity/dto/v1/features.go index b3b60046..5b373dbc 100644 --- a/internal/entity/dto/features.go +++ b/internal/entity/dto/v1/features.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type Features struct { UserConsent string `json:"userConsent" example:"kvm"` diff --git a/internal/entity/dto/ieee8021xconfig.go b/internal/entity/dto/v1/ieee8021xconfig.go similarity index 98% rename from internal/entity/dto/ieee8021xconfig.go rename to internal/entity/dto/v1/ieee8021xconfig.go index 24781eed..b80a7d5d 100644 --- a/internal/entity/dto/ieee8021xconfig.go +++ b/internal/entity/dto/v1/ieee8021xconfig.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import "github.com/go-playground/validator/v10" diff --git a/internal/entity/dto/invalid.go b/internal/entity/dto/v1/invalid.go similarity index 96% rename from internal/entity/dto/invalid.go rename to internal/entity/dto/v1/invalid.go index d4c73dbe..cf1d68c3 100644 --- a/internal/entity/dto/invalid.go +++ b/internal/entity/dto/v1/invalid.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import ( "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" diff --git a/internal/entity/dto/network.go b/internal/entity/dto/v1/network.go similarity index 99% rename from internal/entity/dto/network.go rename to internal/entity/dto/v1/network.go index 8c5dd3cb..855e614e 100644 --- a/internal/entity/dto/network.go +++ b/internal/entity/dto/v1/network.go @@ -1,4 +1,4 @@ -package dto +package dtov1 // NetworkSettings defines the network settings for a device. type NetworkSettings struct { diff --git a/internal/entity/dto/poweraction.go b/internal/entity/dto/v1/poweraction.go similarity index 86% rename from internal/entity/dto/poweraction.go rename to internal/entity/dto/v1/poweraction.go index 0e2c6e1c..86218d1a 100644 --- a/internal/entity/dto/poweraction.go +++ b/internal/entity/dto/v1/poweraction.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type PowerAction struct { Action int `json:"action" binding:"required" example:"8"` diff --git a/internal/entity/dto/profile.go b/internal/entity/dto/v1/profile.go similarity index 99% rename from internal/entity/dto/profile.go rename to internal/entity/dto/v1/profile.go index d764922f..717e15c3 100644 --- a/internal/entity/dto/profile.go +++ b/internal/entity/dto/v1/profile.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import ( "strings" diff --git a/internal/entity/dto/profilewificonfigs.go b/internal/entity/dto/v1/profilewificonfigs.go similarity index 96% rename from internal/entity/dto/profilewificonfigs.go rename to internal/entity/dto/v1/profilewificonfigs.go index 914845d2..9c8c4e0a 100644 --- a/internal/entity/dto/profilewificonfigs.go +++ b/internal/entity/dto/v1/profilewificonfigs.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type ProfileWiFiConfigs struct { Priority int `json:"priority,omitempty" binding:"min=1,max=255" example:"1"` diff --git a/internal/entity/dto/securitysettings.go b/internal/entity/dto/v1/securitysettings.go similarity index 99% rename from internal/entity/dto/securitysettings.go rename to internal/entity/dto/v1/securitysettings.go index d7f702e7..2f2af3d3 100644 --- a/internal/entity/dto/securitysettings.go +++ b/internal/entity/dto/v1/securitysettings.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type ( SecuritySettings struct { diff --git a/internal/entity/dto/v1/setupandconfiguration.go b/internal/entity/dto/v1/setupandconfiguration.go new file mode 100644 index 00000000..54eefc21 --- /dev/null +++ b/internal/entity/dto/v1/setupandconfiguration.go @@ -0,0 +1,25 @@ +package dtov1 + +import ( + "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/setupandconfiguration" +) + +type ( + SetupAndConfigurationServiceResponse struct { + RequestedState setupandconfiguration.RequestedState `xml:"RequestedState,omitempty"` // RequestedState is an integer enumeration that indicates the last requested or desired state for the element, irrespective of the mechanism through which it was requested. + EnabledState setupandconfiguration.EnabledState `xml:"EnabledState,omitempty"` // EnabledState is an integer enumeration that indicates the enabled and disabled states of an element. + ElementName string `xml:"ElementName,omitempty"` // A user-friendly name for the object. This property allows each instance to define a user-friendly name in addition to its key properties, identity data, and description information. Note that the Name property of ManagedSystemElement is also defined as a user-friendly name. But, it is often subclassed to be a Key. It is not reasonable that the same property can convey both identity and a user-friendly name, without inconsistencies. Where Name exists and is not a Key (such as for instances of LogicalDevice), the same information can be present in both the Name and ElementName properties. Note that if there is an associated instance of CIM_EnabledLogicalElementCapabilities, restrictions on this properties may exist as defined in ElementNameMask and MaxElementNameLen properties defined in that class. + SystemCreationClassName string `xml:"SystemCreationClassName,omitempty"` // The CreationClassName of the scoping System. + SystemName string `xml:"SystemName,omitempty"` // The Name of the scoping System. + CreationClassName string `xml:"CreationClassName,omitempty"` // CreationClassName indicates the name of the class or the subclass that is used in the creation of an instance. When used with the other key properties of this class, this property allows all instances of this class and its subclasses to be uniquely identified. + Name string `xml:"Name,omitempty"` // The Name property uniquely identifies the Service and provides an indication of the functionality that is managed. This functionality is described in more detail in the Description property of the object. + ProvisioningMode setupandconfiguration.ProvisioningModeValue `xml:"ProvisioningMode,omitempty"` // A Read-Only enumeration value that determines the behavior of Intel® AMT when it is deployed. + ProvisioningState setupandconfiguration.ProvisioningStateValue `xml:"ProvisioningState,omitempty"` // An enumeration value that indicates the state of the Intel® AMT subsystem in the provisioning process"Pre" - the setup operation has not started."In" - the setup operation is in progress."Post" - Intel® AMT is configured. + ZeroTouchConfigurationEnabled bool `xml:"ZeroTouchConfigurationEnabled,omitempty"` // Indicates if Zero Touch Configuration (Remote Configuration) is enabled or disabled. This property affects only enterprise mode. It can be modified while in SMB mode + ProvisioningServerOTP string `xml:"ProvisioningServerOTP,omitempty"` // A optional binary data value containing 8-32 characters,that represents a one-time password (OTP), used to authenticate the Intel® AMT to the configuration server. This property can be retrieved only in IN Provisioning state, nevertheless, it is settable also in POST provisioning state. + ConfigurationServerFQDN string `xml:"ConfigurationServerFQDN,omitempty"` // The FQDN of the configuration server. + PasswordModel setupandconfiguration.PasswordModelValue `xml:"PasswordModel,omitempty"` // An enumeration value that determines the password model of Intel® AMT. + DhcpDNSSuffix string `xml:"DhcpDNSSuffix,omitempty"` // Domain name received from DHCP + TrustedDNSSuffix string `xml:"TrustedDNSSuffix,omitempty"` // Trusted domain name configured in MEBX + } +) diff --git a/internal/entity/dto/tlsconfig.go b/internal/entity/dto/v1/tlsconfig.go similarity index 98% rename from internal/entity/dto/tlsconfig.go rename to internal/entity/dto/v1/tlsconfig.go index 59c79ccc..499d2812 100644 --- a/internal/entity/dto/tlsconfig.go +++ b/internal/entity/dto/v1/tlsconfig.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type TLSCerts struct { RootCertificate CertCreationResult `json:"rootCertificate"` diff --git a/internal/entity/dto/userconsent.go b/internal/entity/dto/v1/userconsent.go similarity index 88% rename from internal/entity/dto/userconsent.go rename to internal/entity/dto/v1/userconsent.go index a47fdb7e..25e952b8 100644 --- a/internal/entity/dto/userconsent.go +++ b/internal/entity/dto/v1/userconsent.go @@ -1,4 +1,4 @@ -package dto +package dtov1 type UserConsent struct { ConsentCode string `json:"consentCode" binding:"required" example:"123456"` diff --git a/internal/entity/dto/v1/version.go b/internal/entity/dto/v1/version.go new file mode 100644 index 00000000..09465e12 --- /dev/null +++ b/internal/entity/dto/v1/version.go @@ -0,0 +1,14 @@ +package dtov1 + +type ( + SoftwareIdentity struct { + InstanceID string `json:"instanceID"` + VersionString string `json:"VersionString" example:"..."` + IsEntity bool `json:"isEntity" example:"true"` + } + + Version struct { + CIMSoftwareIdentity []SoftwareIdentity `json:"cimSoftwareIdentity"` + AMTSetupAndConfigurationService SetupAndConfigurationServiceResponse `json:"amtSetupAndConfigurationService"` + } +) diff --git a/internal/entity/dto/wificonfigs.go b/internal/entity/dto/v1/wificonfigs.go similarity index 99% rename from internal/entity/dto/wificonfigs.go rename to internal/entity/dto/v1/wificonfigs.go index 7233c9ab..953b8f6d 100644 --- a/internal/entity/dto/wificonfigs.go +++ b/internal/entity/dto/v1/wificonfigs.go @@ -1,4 +1,4 @@ -package dto +package dtov1 import "github.com/go-playground/validator/v10" diff --git a/internal/entity/dto/v2/version.go b/internal/entity/dto/v2/version.go new file mode 100644 index 00000000..ad3f653c --- /dev/null +++ b/internal/entity/dto/v2/version.go @@ -0,0 +1,17 @@ +package dtov2 + +type ( + Version struct { + Flash string `json:"FLash" example:"..."` + Netstack string `json:"Netstack" example:"..."` + AMTApps string `json:"AmtApps" example:"..."` + AMT string `json:"Amt" example:"..."` + Sku string `json:"Sku" example:"..."` + VendorID string `json:"VendorID" example:"..."` + BuildNumber string `json:"BuildNumber" example:"..."` + RecoveryVersion string `json:"Recovery" example:"..."` + RecoveryBuildNumber string `json:"RecoveryBuildNumber" example:"..."` + LegacyMode *bool `json:"LegacyMode" example:"false"` + AmtFWCoreVersion string `json:"AmtFWCore" example:"..."` + } +) diff --git a/internal/usecase/amtexplorer/explorer.go b/internal/usecase/amtexplorer/explorer.go index fcc4ae55..616a8351 100644 --- a/internal/usecase/amtexplorer/explorer.go +++ b/internal/usecase/amtexplorer/explorer.go @@ -7,7 +7,7 @@ import ( "github.com/go-xmlfmt/xmlfmt" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" ) @@ -36,10 +36,10 @@ func (uc *UseCase) GetExplorerSupportedCalls() []string { return methods } -func (uc *UseCase) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dto.Explorer, error) { +func (uc *UseCase) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dtov1.Explorer, error) { item, err := uc.repo.GetByID(ctx, guid, tenantID) if err != nil { - return &dto.Explorer{}, ErrDatabase.Wrap("ExecuteCall", "uc.repo.GetByID", err) + return &dtov1.Explorer{}, ErrDatabase.Wrap("ExecuteCall", "uc.repo.GetByID", err) } device := uc.device.SetupWsmanClient(*uc.entityToDTO(item), true) @@ -53,17 +53,17 @@ func (uc *UseCase) ExecuteCall(ctx context.Context, guid, call, tenantID string) if !method.IsValid() { uc.log.Warn("Method %s not found\n", call) - return &dto.Explorer{}, ErrExplorerUseCase.Wrap("ExecuteCall", "uc.amt.Get"+call, nil) + return &dtov1.Explorer{}, ErrExplorerUseCase.Wrap("ExecuteCall", "uc.amt.Get"+call, nil) } input := make([]reflect.Value, 0) // invoke the method resultType, err := invokeMethod(input, method) if err != nil { - return &dto.Explorer{}, ErrExplorerAMT.Wrap("ExecuteCall", "uc.amt.Get"+call, err) + return &dtov1.Explorer{}, ErrExplorerAMT.Wrap("ExecuteCall", "uc.amt.Get"+call, err) } - explorer := &dto.Explorer{} + explorer := &dtov1.Explorer{} // Iterate over the fields readResult(resultType, explorer) @@ -102,7 +102,7 @@ func invokeMethod(input []reflect.Value, method reflect.Value) (reflect.Value, e return resultType, nil } -func readResult(resultType reflect.Value, explorer *dto.Explorer) { +func readResult(resultType reflect.Value, explorer *dtov1.Explorer) { // Iterate over the fields for i := 0; i < resultType.NumField(); i++ { field := resultType.Field(i) diff --git a/internal/usecase/amtexplorer/explorer_test.go b/internal/usecase/amtexplorer/explorer_test.go index 31fd74b0..18aac8c4 100644 --- a/internal/usecase/amtexplorer/explorer_test.go +++ b/internal/usecase/amtexplorer/explorer_test.go @@ -56,14 +56,14 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/amtexplorer" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) var ( ErrExplorerGeneral = errors.New("general error") - executeResponse = dto.Explorer{ + executeResponse = dtov1.Explorer{ XMLInput: `
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull/wsmanhttp://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext1http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymousPT60S
4F020000-0000-0000-0000-00000000000099999999
`, XMLOutput: `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous1http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponseuuid:00000000-8086-8086-8086-0000000009F5http://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext`, } @@ -84,7 +84,7 @@ func initSupportedCallList(m *MockAMTExplorer) []string { return methods } -func initExplorerTest(t *testing.T) (*amtexplorer.UseCase, *MockRepository, *MockWSMAN, *MockAMTExplorer, dto.Explorer) { +func initExplorerTest(t *testing.T) (*amtexplorer.UseCase, *MockRepository, *MockWSMAN, *MockAMTExplorer, dtov1.Explorer) { t.Helper() mockCtl := gomock.NewController(t) @@ -163,7 +163,7 @@ func TestExecuteCall(t *testing.T) { SetupWsmanClient(context.Background(), true). Return(amt) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrDatabase, }, { @@ -179,7 +179,7 @@ func TestExecuteCall(t *testing.T) { SetupWsmanClient(gomock.Any(), true). Return(amt) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerUseCase, }, { @@ -219,7 +219,7 @@ func TestExecuteCall(t *testing.T) { GetAMT8021xCredentialContext(). Return(ieee8021x.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -258,7 +258,7 @@ func TestExecuteCall(t *testing.T) { GetAMT8021xProfile(). Return(ieee8021x.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -277,7 +277,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAlarmClockService(). Return(alarmclock.Response{Message: &client.Message{XMLInput: executeResponse.XMLInput, XMLOutput: executeResponse.XMLOutput}}, nil) }, - res: dto.Explorer{ + res: dtov1.Explorer{ XMLInput: `
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull/wsmanhttp://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext1http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymousPT60S
4F020000-0000-0000-0000-00000000000099999999
`, XMLOutput: `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous1http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponseuuid:00000000-8086-8086-8086-0000000009F5http://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext`, }, @@ -299,7 +299,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAlarmClockService(). Return(alarmclock.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -318,7 +318,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAuditLog(). Return(auditlog.Response{Message: &client.Message{XMLInput: executeResponse.XMLInput, XMLOutput: executeResponse.XMLOutput}}, nil) }, - res: dto.Explorer{ + res: dtov1.Explorer{ XMLInput: `
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull/wsmanhttp://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext1http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymousPT60S
4F020000-0000-0000-0000-00000000000099999999
`, XMLOutput: `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous1http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponseuuid:00000000-8086-8086-8086-0000000009F5http://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext`, }, @@ -340,7 +340,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAuditLog(). Return(auditlog.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -359,7 +359,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAuthorizationService(). Return(authorization.Response{Message: &client.Message{XMLInput: executeResponse.XMLInput, XMLOutput: executeResponse.XMLOutput}}, nil) }, - res: dto.Explorer{ + res: dtov1.Explorer{ XMLInput: `
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull/wsmanhttp://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext1http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymousPT60S
4F020000-0000-0000-0000-00000000000099999999
`, XMLOutput: `http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous1http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponseuuid:00000000-8086-8086-8086-0000000009F5http://intel.com/wbem/wscim/1/amt-schema/1/AMT_8021xCredentialContext`, }, @@ -381,7 +381,7 @@ func TestExecuteCall(t *testing.T) { GetAMTAuthorizationService(). Return(authorization.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -419,7 +419,7 @@ func TestExecuteCall(t *testing.T) { GetAMTBootCapabilities(). Return(boot.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -457,7 +457,7 @@ func TestExecuteCall(t *testing.T) { GetAMTBootSettingData(). Return(boot.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -495,7 +495,7 @@ func TestExecuteCall(t *testing.T) { GetAMTEnvironmentDetectionSettingData(). Return(environmentdetection.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -533,7 +533,7 @@ func TestExecuteCall(t *testing.T) { GetAMTEthernetPortSettings(). Return(ethernetport.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -571,7 +571,7 @@ func TestExecuteCall(t *testing.T) { GetAMTGeneralSettings(). Return(general.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -609,7 +609,7 @@ func TestExecuteCall(t *testing.T) { GetAMTKerberosSettingData(). Return(kerberos.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -647,7 +647,7 @@ func TestExecuteCall(t *testing.T) { GetAMTManagementPresenceRemoteSAP(). Return(managementpresence.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -685,7 +685,7 @@ func TestExecuteCall(t *testing.T) { GetAMTMessageLog(). Return(messagelog.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -723,7 +723,7 @@ func TestExecuteCall(t *testing.T) { GetAMTMPSUsernamePassword(). Return(mps.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -761,7 +761,7 @@ func TestExecuteCall(t *testing.T) { GetAMTPublicKeyCertificate(). Return(publickey.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -799,7 +799,7 @@ func TestExecuteCall(t *testing.T) { GetAMTPublicKeyManagementService(). Return(publickey.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -837,7 +837,7 @@ func TestExecuteCall(t *testing.T) { GetAMTPublicPrivateKeyPair(). Return(publicprivate.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -875,7 +875,7 @@ func TestExecuteCall(t *testing.T) { GetAMTRedirectionService(). Return(redirection.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -913,7 +913,7 @@ func TestExecuteCall(t *testing.T) { GetAMTRemoteAccessPolicyAppliesToMPS(). Return(remoteaccess.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -951,7 +951,7 @@ func TestExecuteCall(t *testing.T) { GetAMTRemoteAccessPolicyRule(). Return(remoteaccess.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -989,7 +989,7 @@ func TestExecuteCall(t *testing.T) { GetAMTRemoteAccessService(). Return(remoteaccess.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1027,7 +1027,7 @@ func TestExecuteCall(t *testing.T) { GetAMTSetupAndConfigurationService(). Return(setupandconfiguration.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1065,7 +1065,7 @@ func TestExecuteCall(t *testing.T) { GetAMTTimeSynchronizationService(). Return(timesynchronization.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1103,7 +1103,7 @@ func TestExecuteCall(t *testing.T) { GetAMTTLSCredentialContext(). Return(tls.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1141,7 +1141,7 @@ func TestExecuteCall(t *testing.T) { GetAMTTLSProtocolEndpointCollection(). Return(tls.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1179,7 +1179,7 @@ func TestExecuteCall(t *testing.T) { GetAMTTLSSettingData(). Return(tls.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1217,7 +1217,7 @@ func TestExecuteCall(t *testing.T) { GetAMTUserInitiatedConnectionService(). Return(userinitiatedconnection.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1256,7 +1256,7 @@ func TestExecuteCall(t *testing.T) { GetAMTWiFiPortConfigurationService(). Return(wifiportconfiguration.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1294,7 +1294,7 @@ func TestExecuteCall(t *testing.T) { GetCIMBIOSElement(). Return(bios.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1332,7 +1332,7 @@ func TestExecuteCall(t *testing.T) { GetCIMBootConfigSetting(). Return(cimboot.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1370,7 +1370,7 @@ func TestExecuteCall(t *testing.T) { GetCIMBootService(). Return(cimboot.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1408,7 +1408,7 @@ func TestExecuteCall(t *testing.T) { GetCIMBootSourceSetting(). Return(cimboot.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1446,7 +1446,7 @@ func TestExecuteCall(t *testing.T) { GetCIMCard(). Return(card.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1484,7 +1484,7 @@ func TestExecuteCall(t *testing.T) { GetCIMChassis(). Return(chassis.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1522,7 +1522,7 @@ func TestExecuteCall(t *testing.T) { GetCIMChip(). Return(chip.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1560,7 +1560,7 @@ func TestExecuteCall(t *testing.T) { GetCIMComputerSystemPackage(). Return(computer.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1598,7 +1598,7 @@ func TestExecuteCall(t *testing.T) { GetCIMConcreteDependency(). Return(concrete.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1636,7 +1636,7 @@ func TestExecuteCall(t *testing.T) { GetCIMCredentialContext(). Return(credential.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1674,7 +1674,7 @@ func TestExecuteCall(t *testing.T) { GetCIMIEEE8021xSettings(). Return(cimieee8021x.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1712,7 +1712,7 @@ func TestExecuteCall(t *testing.T) { GetCIMKVMRedirectionSAP(). Return(kvm.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1750,7 +1750,7 @@ func TestExecuteCall(t *testing.T) { GetCIMMediaAccessDevice(). Return(mediaaccess.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1788,7 +1788,7 @@ func TestExecuteCall(t *testing.T) { GetCIMPhysicalMemory(). Return(physical.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1826,7 +1826,7 @@ func TestExecuteCall(t *testing.T) { GetCIMPhysicalPackage(). Return(physical.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1864,7 +1864,7 @@ func TestExecuteCall(t *testing.T) { GetCIMPowerManagementService(). Return(power.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1902,7 +1902,7 @@ func TestExecuteCall(t *testing.T) { GetCIMProcessor(). Return(processor.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1940,7 +1940,7 @@ func TestExecuteCall(t *testing.T) { GetCIMServiceAvailableToElement(). Return(service.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -1978,7 +1978,7 @@ func TestExecuteCall(t *testing.T) { GetCIMSoftwareIdentity(). Return(software.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2016,7 +2016,7 @@ func TestExecuteCall(t *testing.T) { GetCIMSystemPackaging(). Return(system.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2054,7 +2054,7 @@ func TestExecuteCall(t *testing.T) { GetCIMWiFiEndpointSettings(). Return(wifi.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2092,7 +2092,7 @@ func TestExecuteCall(t *testing.T) { GetCIMWiFiPort(). Return(wifi.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2130,7 +2130,7 @@ func TestExecuteCall(t *testing.T) { GetIPS8021xCredentialContext(). Return(ipsieee8021x.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2168,7 +2168,7 @@ func TestExecuteCall(t *testing.T) { GetIPSAlarmClockOccurrence(). Return(ipsalarmclock.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2206,7 +2206,7 @@ func TestExecuteCall(t *testing.T) { GetIPSHostBasedSetupService(). Return(hostbasedsetup.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2244,7 +2244,7 @@ func TestExecuteCall(t *testing.T) { GetIPSIEEE8021xSettings(). Return(ipsieee8021x.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, { @@ -2282,7 +2282,7 @@ func TestExecuteCall(t *testing.T) { GetIPSOptInService(). Return(optin.Response{}, ErrExplorerGeneral) }, - res: &dto.Explorer{}, + res: &dtov1.Explorer{}, err: amtexplorer.ErrExplorerAMT, }, } @@ -2302,7 +2302,7 @@ func TestExecuteCall(t *testing.T) { formattedXMLInput := formatXML(executeResponse.XMLInput) formattedXMLOutput := formatXML(executeResponse.XMLOutput) - tc.res = &dto.Explorer{ + tc.res = &dtov1.Explorer{ XMLInput: formattedXMLInput, XMLOutput: formattedXMLOutput, } diff --git a/internal/usecase/amtexplorer/interfaces.go b/internal/usecase/amtexplorer/interfaces.go index d5f2be97..5627bacd 100644 --- a/internal/usecase/amtexplorer/interfaces.go +++ b/internal/usecase/amtexplorer/interfaces.go @@ -48,12 +48,12 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/optin" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( AMTExplorer interface { - // SetupWsmanClient(device dto.Device, isRedirection, logAMTMessages bool) *wsmanAPI.ConnectionEntry + // SetupWsmanClient(device dtov1.Device, isRedirection, logAMTMessages bool) *wsmanAPI.ConnectionEntry GetAMT8021xCredentialContext() (ieee8021x.Response, error) GetAMT8021xProfile() (ieee8021x.Response, error) GetAMTAlarmClockService() (alarmclock.Response, error) @@ -112,13 +112,13 @@ type ( } Feature interface { GetExplorerSupportedCalls() []string - ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dto.Explorer, error) + ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dtov1.Explorer, error) } Repository interface { GetByID(ctx context.Context, guid, tenantID string) (*entity.Device, error) } WSMAN interface { - SetupWsmanClient(device dto.Device, logMessages bool) AMTExplorer - DestroyWsmanClient(device dto.Device) + SetupWsmanClient(device dtov1.Device, logMessages bool) AMTExplorer + DestroyWsmanClient(device dtov1.Device) } ) diff --git a/internal/usecase/amtexplorer/mocks_test.go b/internal/usecase/amtexplorer/mocks_test.go index 0612a532..d364fe69 100644 --- a/internal/usecase/amtexplorer/mocks_test.go +++ b/internal/usecase/amtexplorer/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + v1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" amtexplorer "github.com/open-amt-cloud-toolkit/console/internal/usecase/amtexplorer" alarmclock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock" auditlog "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/auditlog" @@ -934,10 +934,10 @@ func (m *MockFeature) EXPECT() *MockFeatureMockRecorder { } // ExecuteCall mocks base method. -func (m *MockFeature) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*dto.Explorer, error) { +func (m *MockFeature) ExecuteCall(ctx context.Context, guid, call, tenantID string) (*v1.Explorer, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExecuteCall", ctx, guid, call, tenantID) - ret0, _ := ret[0].(*dto.Explorer) + ret0, _ := ret[0].(*v1.Explorer) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -1024,7 +1024,7 @@ func (m *MockWSMAN) EXPECT() *MockWSMANMockRecorder { } // DestroyWsmanClient mocks base method. -func (m *MockWSMAN) DestroyWsmanClient(device dto.Device) { +func (m *MockWSMAN) DestroyWsmanClient(device v1.Device) { m.ctrl.T.Helper() m.ctrl.Call(m, "DestroyWsmanClient", device) } @@ -1036,7 +1036,7 @@ func (mr *MockWSMANMockRecorder) DestroyWsmanClient(device any) *gomock.Call { } // SetupWsmanClient mocks base method. -func (m *MockWSMAN) SetupWsmanClient(device dto.Device, logMessages bool) amtexplorer.AMTExplorer { +func (m *MockWSMAN) SetupWsmanClient(device v1.Device, logMessages bool) amtexplorer.AMTExplorer { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, logMessages) ret0, _ := ret[0].(amtexplorer.AMTExplorer) diff --git a/internal/usecase/amtexplorer/usecase.go b/internal/usecase/amtexplorer/usecase.go index f1f82f4a..3b9d1882 100644 --- a/internal/usecase/amtexplorer/usecase.go +++ b/internal/usecase/amtexplorer/usecase.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -30,12 +30,12 @@ func New(r Repository, d WSMAN, log logger.Interface) *UseCase { } } -// convert entity.Device to dto.Device. -func (uc *UseCase) entityToDTO(d *entity.Device) *dto.Device { +// convert entity.Device to dtov1.Device. +func (uc *UseCase) entityToDTO(d *entity.Device) *dtov1.Device { // convert comma separated string to []string tags := strings.Split(d.Tags, ",") - d1 := &dto.Device{ + d1 := &dtov1.Device{ ConnectionStatus: d.ConnectionStatus, MPSInstance: d.MPSInstance, Hostname: d.Hostname, diff --git a/internal/usecase/amtexplorer/wsman.go b/internal/usecase/amtexplorer/wsman.go index 3517723e..9b94212a 100644 --- a/internal/usecase/amtexplorer/wsman.go +++ b/internal/usecase/amtexplorer/wsman.go @@ -7,7 +7,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" wsmanAPI "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -28,14 +28,14 @@ func NewGoWSMANMessages(log logger.Interface) *GoWSMANMessages { } } -func (g GoWSMANMessages) DestroyWsmanClient(device dto.Device) { +func (g GoWSMANMessages) DestroyWsmanClient(device dtov1.Device) { if entry, ok := connections[device.GUID]; ok { entry.Timer.Stop() removeConnection(device.GUID) } } -func (g GoWSMANMessages) SetupWsmanClient(device dto.Device, logAMTMessages bool) AMTExplorer { +func (g GoWSMANMessages) SetupWsmanClient(device dtov1.Device, logAMTMessages bool) AMTExplorer { clientParams := client.Parameters{ Target: device.Hostname, Username: device.Username, diff --git a/internal/usecase/ciraconfigs/interfaces.go b/internal/usecase/ciraconfigs/interfaces.go index 1b78fa42..965ea995 100644 --- a/internal/usecase/ciraconfigs/interfaces.go +++ b/internal/usecase/ciraconfigs/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -18,10 +18,10 @@ type ( } Feature interface { GetCount(ctx context.Context, tenantID string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.CIRAConfig, error) - GetByName(ctx context.Context, configName, tenantID string) (*dto.CIRAConfig, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.CIRAConfig, error) + GetByName(ctx context.Context, configName, tenantID string) (*dtov1.CIRAConfig, error) Delete(ctx context.Context, profileName, tenantID string) error - Update(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) - Insert(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) + Update(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) + Insert(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) } ) diff --git a/internal/usecase/ciraconfigs/mocks_test.go b/internal/usecase/ciraconfigs/mocks_test.go index f7bb6b6b..7df6cf21 100644 --- a/internal/usecase/ciraconfigs/mocks_test.go +++ b/internal/usecase/ciraconfigs/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -169,10 +169,10 @@ func (mr *MockFeatureMockRecorder) Delete(ctx, profileName, tenantID any) *gomoc } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.CIRAConfig, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.CIRAConfig) + ret0, _ := ret[0].([]dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -184,10 +184,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetByName mocks base method. -func (m *MockFeature) GetByName(ctx context.Context, configName, tenantID string) (*dto.CIRAConfig, error) { +func (m *MockFeature) GetByName(ctx context.Context, configName, tenantID string) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, configName, tenantID) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (m *MockFeature) Insert(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, p *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (m *MockFeature) Update(ctx context.Context, p *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.CIRAConfig) + ret0, _ := ret[0].(*dtov1.CIRAConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/ciraconfigs/usecase.go b/internal/usecase/ciraconfigs/usecase.go index 0f916af1..ee882d04 100644 --- a/internal/usecase/ciraconfigs/usecase.go +++ b/internal/usecase/ciraconfigs/usecase.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -40,13 +40,13 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.CIRAConfig, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.CIRAConfig, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) } // iterate over the data and convert each entity to dto - d1 := make([]dto.CIRAConfig, len(data)) + d1 := make([]dtov1.CIRAConfig, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -56,7 +56,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetByName(ctx context.Context, configName, tenantID string) (*dto.CIRAConfig, error) { +func (uc *UseCase) GetByName(ctx context.Context, configName, tenantID string) (*dtov1.CIRAConfig, error) { data, err := uc.repo.GetByName(ctx, configName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByName", "uc.repo.GetByName", err) @@ -84,7 +84,7 @@ func (uc *UseCase) Delete(ctx context.Context, configName, tenantID string) erro return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { d1 := uc.dtoToEntity(d) updated, err := uc.repo.Update(ctx, d1) @@ -106,7 +106,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.CIRAConfig) (*dto.CIRAConf return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.CIRAConfig) (*dto.CIRAConfig, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.CIRAConfig) (*dtov1.CIRAConfig, error) { d1 := uc.dtoToEntity(d) _, err := uc.repo.Insert(ctx, d1) @@ -124,8 +124,8 @@ func (uc *UseCase) Insert(ctx context.Context, d *dto.CIRAConfig) (*dto.CIRAConf return d2, nil } -// convert dto.CIRAConfig to entity.CIRAConfig. -func (uc *UseCase) dtoToEntity(d *dto.CIRAConfig) *entity.CIRAConfig { +// convert dtov1.CIRAConfig to entity.CIRAConfig. +func (uc *UseCase) dtoToEntity(d *dtov1.CIRAConfig) *entity.CIRAConfig { d1 := &entity.CIRAConfig{ ConfigName: d.ConfigName, MPSAddress: d.MPSAddress, @@ -145,9 +145,9 @@ func (uc *UseCase) dtoToEntity(d *dto.CIRAConfig) *entity.CIRAConfig { return d1 } -// convert entity.CIRAConfig to dto.CIRAConfig. -func (uc *UseCase) entityToDTO(d *entity.CIRAConfig) *dto.CIRAConfig { - d1 := &dto.CIRAConfig{ +// convert entity.CIRAConfig to dtov1.CIRAConfig. +func (uc *UseCase) entityToDTO(d *entity.CIRAConfig) *dtov1.CIRAConfig { + d1 := &dtov1.CIRAConfig{ ConfigName: d.ConfigName, MPSAddress: d.MPSAddress, MPSPort: d.MPSPort, diff --git a/internal/usecase/ciraconfigs/usecase_test.go b/internal/usecase/ciraconfigs/usecase_test.go index e4ab3477..e9bcd0d7 100644 --- a/internal/usecase/ciraconfigs/usecase_test.go +++ b/internal/usecase/ciraconfigs/usecase_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ciraconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -19,7 +19,7 @@ type test struct { skip int configName string tenantID string - input dto.CIRAConfig + input dtov1.CIRAConfig mock func(*MockRepository) res interface{} err error @@ -92,7 +92,7 @@ func TestGet(t *testing.T) { }, } - testCIRAConfigDTOs := []dto.CIRAConfig{ + testCIRAConfigDTOs := []dtov1.CIRAConfig{ { ConfigName: "test-config-1", TenantID: "tenant-id-456", @@ -127,7 +127,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 5, 0, "tenant-id-456"). Return(nil, ciraconfigs.ErrDatabase) }, - res: []dto.CIRAConfig(nil), + res: []dtov1.CIRAConfig(nil), err: ciraconfigs.ErrDatabase, }, { @@ -140,7 +140,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 10, 20, "tenant-id-456"). Return([]entity.CIRAConfig{}, nil) }, - res: []dto.CIRAConfig{}, + res: []dtov1.CIRAConfig{}, err: nil, }, } @@ -177,7 +177,7 @@ func TestGetByName(t *testing.T) { Version: "1.0.0", } - ciraconfigDTO := &dto.CIRAConfig{ + ciraconfigDTO := &dtov1.CIRAConfig{ ConfigName: "test-config", TenantID: "tenant-id-456", Version: "1.0.0", @@ -186,7 +186,7 @@ func TestGetByName(t *testing.T) { tests := []test{ { name: "successful retrieval", - input: dto.CIRAConfig{ + input: dtov1.CIRAConfig{ ConfigName: "test-config", TenantID: "tenant-id-456", }, @@ -200,7 +200,7 @@ func TestGetByName(t *testing.T) { }, { name: "ciraconfig not found", - input: dto.CIRAConfig{ + input: dtov1.CIRAConfig{ ConfigName: "unknown-ciraconfig", TenantID: "tenant-id-456", }, @@ -209,7 +209,7 @@ func TestGetByName(t *testing.T) { GetByName(context.Background(), "unknown-ciraconfig", "tenant-id-456"). Return(nil, nil) }, - res: (*dto.CIRAConfig)(nil), + res: (*dtov1.CIRAConfig)(nil), err: ciraconfigs.ErrNotFound, }, } @@ -295,7 +295,7 @@ func TestUpdate(t *testing.T) { Version: "1.0.0", } - ciraconfigDTO := &dto.CIRAConfig{ + ciraconfigDTO := &dtov1.CIRAConfig{ ConfigName: "test-config", TenantID: "tenant-id-456", Version: "1.0.0", @@ -322,7 +322,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), ciraconfig). Return(false, nil) }, - res: (*dto.CIRAConfig)(nil), + res: (*dtov1.CIRAConfig)(nil), err: ciraconfigs.ErrNotFound, }, { @@ -332,7 +332,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), ciraconfig). Return(false, ciraconfigs.ErrDatabase) }, - res: (*dto.CIRAConfig)(nil), + res: (*dtov1.CIRAConfig)(nil), err: ciraconfigs.ErrDatabase, }, } @@ -363,7 +363,7 @@ func TestInsert(t *testing.T) { Version: "1.0.0", } - ciraconfigDTO := &dto.CIRAConfig{ + ciraconfigDTO := &dtov1.CIRAConfig{ ConfigName: "test-config", TenantID: "tenant-id-456", Version: "1.0.0", @@ -390,7 +390,7 @@ func TestInsert(t *testing.T) { Insert(context.Background(), ciraconfig). Return("", ciraconfigs.ErrDatabase) }, - res: (*dto.CIRAConfig)(nil), + res: (*dtov1.CIRAConfig)(nil), err: ciraconfigs.ErrDatabase, }, } diff --git a/internal/usecase/devices/alarms.go b/internal/usecase/devices/alarms.go index 14d55291..049e4da7 100644 --- a/internal/usecase/devices/alarms.go +++ b/internal/usecase/devices/alarms.go @@ -8,10 +8,10 @@ import ( amtAlarmClock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/alarmclock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) -func (uc *UseCase) GetAlarmOccurrences(c context.Context, guid string) ([]dto.AlarmClockOccurrence, error) { +func (uc *UseCase) GetAlarmOccurrences(c context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return nil, err @@ -29,7 +29,7 @@ func (uc *UseCase) GetAlarmOccurrences(c context.Context, guid string) ([]dto.Al } // iterate over the data and convert each entity to dto - d1 := make([]dto.AlarmClockOccurrence, len(alarms)) + d1 := make([]dtov1.AlarmClockOccurrence, len(alarms)) for i := range alarms { tmpEntity := alarms[i] // create a new variable to avoid memory aliasing @@ -39,10 +39,10 @@ func (uc *UseCase) GetAlarmOccurrences(c context.Context, guid string) ([]dto.Al return d1, nil } -func (uc *UseCase) CreateAlarmOccurrences(c context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) { +func (uc *UseCase) CreateAlarmOccurrences(c context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.AddAlarmOutput{}, err + return dtov1.AddAlarmOutput{}, err } alarm.InstanceID = alarm.ElementName @@ -51,7 +51,7 @@ func (uc *UseCase) CreateAlarmOccurrences(c context.Context, guid string, alarm alarmReference, err := device.CreateAlarmOccurrences(alarm.InstanceID, alarm.StartTime, alarm.Interval, alarm.DeleteOnCompletion) if err != nil { - return dto.AddAlarmOutput{}, ErrAMT.Wrap("CreateAlarmOccurrences", "device.CreateAlarmOccurrences", err) + return dtov1.AddAlarmOutput{}, ErrAMT.Wrap("CreateAlarmOccurrences", "device.CreateAlarmOccurrences", err) } d1 := *uc.addAlarmOutputEntityToDTO(&alarmReference) @@ -75,18 +75,18 @@ func (uc *UseCase) DeleteAlarmOccurrences(c context.Context, guid, instanceID st return nil } -func (uc *UseCase) addAlarmOutputEntityToDTO(d *amtAlarmClock.AddAlarmOutput) *dto.AddAlarmOutput { - d1 := &dto.AddAlarmOutput{ +func (uc *UseCase) addAlarmOutputEntityToDTO(d *amtAlarmClock.AddAlarmOutput) *dtov1.AddAlarmOutput { + d1 := &dtov1.AddAlarmOutput{ ReturnValue: int(d.ReturnValue), } return d1 } -func (uc *UseCase) alarmOccurenceEntityToDTO(d *alarmclock.AlarmClockOccurrence) *dto.AlarmClockOccurrence { +func (uc *UseCase) alarmOccurenceEntityToDTO(d *alarmclock.AlarmClockOccurrence) *dtov1.AlarmClockOccurrence { startTime, _ := time.Parse(time.RFC3339, d.StartTime) interval, _ := strconv.Atoi(d.Interval) - d1 := &dto.AlarmClockOccurrence{ + d1 := &dtov1.AlarmClockOccurrence{ ElementName: d.ElementName, InstanceID: d.InstanceID, StartTime: startTime, diff --git a/internal/usecase/devices/alarms_test.go b/internal/usecase/devices/alarms_test.go index 729ba017..69d23c37 100644 --- a/internal/usecase/devices/alarms_test.go +++ b/internal/usecase/devices/alarms_test.go @@ -11,7 +11,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -40,7 +40,7 @@ func initAlarmsTest(t *testing.T) (*devices.UseCase, *MockWSMAN, *MockManagement func TestGetAlarmOccurrences(t *testing.T) { t.Parallel() - dtoDevice := &dto.Device{ + dtoDevice := &dtov1.Device{ GUID: "device-guid-123", Tags: nil, TenantID: "tenant-id-456", @@ -68,7 +68,8 @@ func TestGetAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.AlarmClockOccurrence{}, + + res: []dtov1.AlarmClockOccurrence{}, err: nil, }, { @@ -79,7 +80,8 @@ func TestGetAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: []dto.AlarmClockOccurrence(nil), + + res: []dtov1.AlarmClockOccurrence(nil), err: devices.ErrDatabase, }, { @@ -98,7 +100,8 @@ func TestGetAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.AlarmClockOccurrence(nil), + + res: []dtov1.AlarmClockOccurrence(nil), err: ErrGeneral, }, { @@ -117,7 +120,8 @@ func TestGetAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.AlarmClockOccurrence{}, + + res: []dtov1.AlarmClockOccurrence{}, err: nil, }, } @@ -152,12 +156,12 @@ func TestCreateAlarmOccurrences(t *testing.T) { GUID: "device-guid-123", TenantID: "tenant-id-456", } - dtoDevice := &dto.Device{ + dtoDevice := &dtov1.Device{ GUID: "device-guid-123", Tags: nil, TenantID: "tenant-id-456", } - occ := dto.AlarmClockOccurrence{ + occ := dtov1.AlarmClockOccurrence{ ElementName: "test", InstanceID: "test", StartTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), @@ -174,7 +178,7 @@ func TestCreateAlarmOccurrences(t *testing.T) { repoMock func(repo *MockRepository) - res dto.AddAlarmOutput + res dtov1.AddAlarmOutput err error }{ @@ -194,7 +198,7 @@ func TestCreateAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.AddAlarmOutput{}, + res: dtov1.AddAlarmOutput{}, err: nil, }, { @@ -205,7 +209,7 @@ func TestCreateAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: dto.AddAlarmOutput{}, + res: dtov1.AddAlarmOutput{}, err: devices.ErrDatabase, }, { @@ -224,7 +228,7 @@ func TestCreateAlarmOccurrences(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.AddAlarmOutput{}, + res: dtov1.AddAlarmOutput{}, err: devices.ErrAMT, }, } @@ -260,7 +264,7 @@ func TestDeleteAlarmOccurrences(t *testing.T) { TenantID: "tenant-id-456", } - dtoDevice := &dto.Device{ + dtoDevice := &dtov1.Device{ GUID: "device-guid-123", Tags: nil, TenantID: "tenant-id-456", diff --git a/internal/usecase/devices/certificates.go b/internal/usecase/devices/certificates.go index 6aebdf23..00617794 100644 --- a/internal/usecase/devices/certificates.go +++ b/internal/usecase/devices/certificates.go @@ -18,7 +18,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/concrete" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/credential" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" ) @@ -28,7 +28,7 @@ const ( TypeWired string = "Wired" ) -func processConcreteDependencies(certificateHandle string, profileAssociation *dto.ProfileAssociation, dependencyItems []concrete.ConcreteDependency, securitySettings dto.SecuritySettings) { +func processConcreteDependencies(certificateHandle string, profileAssociation *dtov1.ProfileAssociation, dependencyItems []concrete.ConcreteDependency, securitySettings dtov1.SecuritySettings) { for i := range dependencyItems { di := dependencyItems[i] if di.Antecedent.ReferenceParameters.SelectorSet.Selectors[0].Text == certificateHandle { @@ -38,7 +38,7 @@ func processConcreteDependencies(certificateHandle string, profileAssociation *d } // Helper function to update profile association key if matching key is found. -func updateProfileAssociationKey(keyHandle string, profileAssociation *dto.ProfileAssociation, securitySettings dto.SecuritySettings) { +func updateProfileAssociationKey(keyHandle string, profileAssociation *dtov1.ProfileAssociation, securitySettings dtov1.SecuritySettings) { for _, key := range securitySettings.KeyResponse.Keys { if key.InstanceID == keyHandle { keyCopy := key @@ -49,7 +49,7 @@ func updateProfileAssociationKey(keyHandle string, profileAssociation *dto.Profi } } -func buildCertificateAssociations(profileAssociation dto.ProfileAssociation, securitySettings *dto.SecuritySettings) { +func buildCertificateAssociations(profileAssociation dtov1.ProfileAssociation, securitySettings *dtov1.SecuritySettings) { var publicKeyHandle string if profileAssociation.ClientCertificate != nil { @@ -81,7 +81,7 @@ func buildCertificateAssociations(profileAssociation dto.ProfileAssociation, sec } } -func getProfileAssociationText(profileAssociation dto.ProfileAssociation) string { +func getProfileAssociationText(profileAssociation dtov1.ProfileAssociation) string { value := profileAssociation.Type if profileAssociation.Type == TypeWireless { value += " - " + profileAssociation.ProfileID @@ -90,7 +90,7 @@ func getProfileAssociationText(profileAssociation dto.ProfileAssociation) string return value } -func buildProfileAssociations(certificateHandle string, profileAssociation *dto.ProfileAssociation, response wsman.Certificates, securitySettings *dto.SecuritySettings) { +func buildProfileAssociations(certificateHandle string, profileAssociation *dtov1.ProfileAssociation, response wsman.Certificates, securitySettings *dtov1.SecuritySettings) { isNewProfileAssociation := true for i := range securitySettings.CertificateResponse.Certificates { @@ -122,7 +122,7 @@ func buildProfileAssociations(certificateHandle string, profileAssociation *dto. } // Helper function to update certificates if they are not nil. -func updateCertificate(existingAssoc, newAssoc *dto.ProfileAssociation) { +func updateCertificate(existingAssoc, newAssoc *dtov1.ProfileAssociation) { if newAssoc.RootCertificate != nil { existingAssoc.RootCertificate = newAssoc.RootCertificate } @@ -136,9 +136,9 @@ func updateCertificate(existingAssoc, newAssoc *dto.ProfileAssociation) { } } -func processCertificates(contextItems []credential.CredentialContext, response wsman.Certificates, profileType string, securitySettings *dto.SecuritySettings) { +func processCertificates(contextItems []credential.CredentialContext, response wsman.Certificates, profileType string, securitySettings *dtov1.SecuritySettings) { for idx := range contextItems { - var profileAssociation dto.ProfileAssociation + var profileAssociation dtov1.ProfileAssociation profileAssociation.Type = profileType profileAssociation.ProfileID = strings.TrimPrefix(contextItems[idx].ElementProvidingContext.ReferenceParameters.SelectorSet.Selectors[0].Text, "Intel(r) AMT:IEEE 802.1x Settings ") @@ -149,20 +149,20 @@ func processCertificates(contextItems []credential.CredentialContext, response w } } -func (uc *UseCase) GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) { +func (uc *UseCase) GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.SecuritySettings{}, err + return dtov1.SecuritySettings{}, err } device := uc.device.SetupWsmanClient(*item, false, true) response, err := device.GetCertificates() if err != nil { - return dto.SecuritySettings{}, err + return dtov1.SecuritySettings{}, err } - securitySettings := dto.SecuritySettings{ + securitySettings := dtov1.SecuritySettings{ CertificateResponse: CertificatesToDTO(&response.PublicKeyCertificateResponse), KeyResponse: KeysToDTO(&response.PublicPrivateKeyPairResponse), } @@ -176,12 +176,12 @@ func (uc *UseCase) GetCertificates(c context.Context, guid string) (dto.Security return securitySettings, nil } -func CertificatesToDTO(r *publickey.RefinedPullResponse) dto.CertificatePullResponse { +func CertificatesToDTO(r *publickey.RefinedPullResponse) dtov1.CertificatePullResponse { regex := regexp.MustCompile(`CN=[^,]+`) - keyManagementItems := make([]dto.RefinedKeyManagementResponse, len(r.KeyManagementItems)) + keyManagementItems := make([]dtov1.RefinedKeyManagementResponse, len(r.KeyManagementItems)) for i := range r.KeyManagementItems { - keyManagementItems[i] = dto.RefinedKeyManagementResponse{ + keyManagementItems[i] = dtov1.RefinedKeyManagementResponse{ CreationClassName: keyManagementItems[i].CreationClassName, ElementName: keyManagementItems[i].ElementName, EnabledDefault: keyManagementItems[i].EnabledDefault, @@ -193,7 +193,7 @@ func CertificatesToDTO(r *publickey.RefinedPullResponse) dto.CertificatePullResp } } - certItems := make([]dto.RefinedCertificate, len(r.PublicKeyCertificateItems)) + certItems := make([]dtov1.RefinedCertificate, len(r.PublicKeyCertificateItems)) for i := range r.PublicKeyCertificateItems { displayName := regex.FindString(r.PublicKeyCertificateItems[i].Subject) @@ -203,7 +203,7 @@ func CertificatesToDTO(r *publickey.RefinedPullResponse) dto.CertificatePullResp displayName = r.PublicKeyCertificateItems[i].InstanceID } - certItems[i] = dto.RefinedCertificate{ + certItems[i] = dtov1.RefinedCertificate{ ElementName: r.PublicKeyCertificateItems[i].ElementName, InstanceID: r.PublicKeyCertificateItems[i].InstanceID, X509Certificate: r.PublicKeyCertificateItems[i].X509Certificate, @@ -217,16 +217,16 @@ func CertificatesToDTO(r *publickey.RefinedPullResponse) dto.CertificatePullResp } } - return dto.CertificatePullResponse{ + return dtov1.CertificatePullResponse{ KeyManagementItems: keyManagementItems, Certificates: certItems, } } -func KeysToDTO(r *publicprivate.RefinedPullResponse) dto.KeyPullResponse { - keyItems := make([]dto.Key, len(r.PublicPrivateKeyPairItems)) +func KeysToDTO(r *publicprivate.RefinedPullResponse) dtov1.KeyPullResponse { + keyItems := make([]dtov1.Key, len(r.PublicPrivateKeyPairItems)) for i, item := range r.PublicPrivateKeyPairItems { - keyItems[i] = dto.Key{ + keyItems[i] = dtov1.Key{ ElementName: item.ElementName, InstanceID: item.InstanceID, DERKey: item.DERKey, @@ -234,25 +234,25 @@ func KeysToDTO(r *publicprivate.RefinedPullResponse) dto.KeyPullResponse { } } - return dto.KeyPullResponse{ + return dtov1.KeyPullResponse{ Keys: keyItems, } } -func (uc *UseCase) GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) { +func (uc *UseCase) GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.Certificate{}, err + return dtov1.Certificate{}, err } device := uc.device.SetupWsmanClient(*item, false, true) cert1, err := device.GetDeviceCertificate() if err != nil { - return dto.Certificate{}, err + return dtov1.Certificate{}, err } - var certDTOs []dto.Certificate + var certDTOs []dtov1.Certificate for _, certBytes := range cert1.Certificate { // Parse each certificate byte slice into an x509.Certificate @@ -271,7 +271,7 @@ func (uc *UseCase) GetDeviceCertificate(c context.Context, guid string) (dto.Cer return certDTOs[0], nil } -func populateCertificateDTO(cert *x509.Certificate) dto.Certificate { +func populateCertificateDTO(cert *x509.Certificate) dtov1.Certificate { // Compute the SHA-1 and SHA-256 fingerprints sha1Fingerprint := sha1.Sum(cert.Raw) //nolint:gosec // SHA-1 is used for thumbprint not signature sha256Fingerprint := sha256.Sum256(cert.Raw) @@ -288,7 +288,7 @@ func populateCertificateDTO(cert *x509.Certificate) dto.Certificate { } // Populate the dto.Certificate struct - return dto.Certificate{ + return dtov1.Certificate{ CommonName: cert.Subject.CommonName, IssuerName: cert.Issuer.CommonName, SerialNumber: cert.SerialNumber.String(), diff --git a/internal/usecase/devices/certificates_private_test.go b/internal/usecase/devices/certificates_private_test.go index 269a220b..37fef7d6 100644 --- a/internal/usecase/devices/certificates_private_test.go +++ b/internal/usecase/devices/certificates_private_test.go @@ -11,13 +11,13 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/models" "github.com/stretchr/testify/require" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" ) type certificateTest struct { name string - res dto.SecuritySettings + res dtov1.SecuritySettings err error profileType string @@ -674,8 +674,8 @@ var getResponse wsman.Certificates = wsman.Certificates{ }, } -var parsedCerts = dto.CertificatePullResponse{ - KeyManagementItems: []dto.RefinedKeyManagementResponse{ +var parsedCerts = dtov1.CertificatePullResponse{ + KeyManagementItems: []dtov1.RefinedKeyManagementResponse{ { CreationClassName: "", ElementName: "", @@ -687,7 +687,7 @@ var parsedCerts = dto.CertificatePullResponse{ SystemName: "", }, }, - Certificates: []dto.RefinedCertificate{ + Certificates: []dtov1.RefinedCertificate{ { ElementName: "Intel(r) AMT Certificate", InstanceID: "Intel(r) AMT Certificate: Handle: 2", @@ -736,8 +736,8 @@ var parsedCerts = dto.CertificatePullResponse{ }, } -var parsedKeys = dto.KeyPullResponse{ - Keys: []dto.Key{ +var parsedKeys = dtov1.KeyPullResponse{ + Keys: []dtov1.Key{ { ElementName: "Intel(r) AMT Key", InstanceID: "Intel(r) AMT Key: Handle: 0", @@ -776,7 +776,7 @@ func TestKeysToDTO(t *testing.T) { func TestProcessCertificates(t *testing.T) { t.Parallel() - securitySettings := dto.SecuritySettings{ + securitySettings := dtov1.SecuritySettings{ CertificateResponse: parsedCerts, KeyResponse: parsedKeys, } @@ -784,12 +784,12 @@ func TestProcessCertificates(t *testing.T) { tests := []certificateTest{ { name: "success", - res: dto.SecuritySettings{ - ProfileAssociation: []dto.ProfileAssociation{ + res: dtov1.SecuritySettings{ + ProfileAssociation: []dtov1.ProfileAssociation{ { Type: "Wireless", ProfileID: "TestWifi8021xTLS", - RootCertificate: &dto.RefinedCertificate{ + RootCertificate: &dtov1.RefinedCertificate{ ElementName: "Intel(r) AMT Certificate", InstanceID: "Intel(r) AMT Certificate: Handle: 2", X509Certificate: "TestCertRoot", @@ -798,7 +798,7 @@ func TestProcessCertificates(t *testing.T) { PublicKeyHandle: "", AssociatedProfiles: nil, }, - ClientCertificate: &dto.RefinedCertificate{ + ClientCertificate: &dtov1.RefinedCertificate{ ElementName: "Intel(r) AMT Certificate", InstanceID: "Intel(r) AMT Certificate: Handle: 3", X509Certificate: "TestCert3", @@ -807,7 +807,7 @@ func TestProcessCertificates(t *testing.T) { PublicKeyHandle: "", AssociatedProfiles: nil, }, - Key: &dto.Key{ + Key: &dtov1.Key{ ElementName: "Intel(r) AMT Key", InstanceID: "Intel(r) AMT Key: Handle: 2", DERKey: "Key2", @@ -817,7 +817,7 @@ func TestProcessCertificates(t *testing.T) { { Type: "Wireless", ProfileID: "TestWifi8021xTLS2", - RootCertificate: &dto.RefinedCertificate{ + RootCertificate: &dtov1.RefinedCertificate{ ElementName: "Intel(r) AMT Certificate", InstanceID: "Intel(r) AMT Certificate: Handle: 2", X509Certificate: "TestCertRoot", @@ -829,13 +829,13 @@ func TestProcessCertificates(t *testing.T) { "Wireless - TestWifi8021xTLS2", }, }, - ClientCertificate: &dto.RefinedCertificate{}, - Key: &dto.Key{}, + ClientCertificate: &dtov1.RefinedCertificate{}, + Key: &dtov1.Key{}, }, }, - CertificateResponse: dto.CertificatePullResponse{ + CertificateResponse: dtov1.CertificatePullResponse{ KeyManagementItems: nil, - Certificates: []dto.RefinedCertificate{ + Certificates: []dtov1.RefinedCertificate{ { ElementName: "Intel(r) AMT Certificate", InstanceID: "Intel(r) AMT Certificate: Handle: 2", @@ -879,8 +879,8 @@ func TestProcessCertificates(t *testing.T) { }, }, }, - KeyResponse: dto.KeyPullResponse{ - Keys: []dto.Key{ + KeyResponse: dtov1.KeyPullResponse{ + Keys: []dtov1.Key{ { ElementName: "Intel(r) AMT Key", InstanceID: "Intel(r) AMT Key: Handle: 0", diff --git a/internal/usecase/devices/certificates_test.go b/internal/usecase/devices/certificates_test.go index be7f6a56..30985513 100644 --- a/internal/usecase/devices/certificates_test.go +++ b/internal/usecase/devices/certificates_test.go @@ -11,7 +11,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -59,14 +59,14 @@ func TestGetCertificates(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.SecuritySettings{ - ProfileAssociation: []dto.ProfileAssociation(nil), - CertificateResponse: dto.CertificatePullResponse{ - KeyManagementItems: []dto.RefinedKeyManagementResponse{}, - Certificates: []dto.RefinedCertificate{}, + res: dtov1.SecuritySettings{ + ProfileAssociation: []dtov1.ProfileAssociation(nil), + CertificateResponse: dtov1.CertificatePullResponse{ + KeyManagementItems: []dtov1.RefinedKeyManagementResponse{}, + Certificates: []dtov1.RefinedCertificate{}, }, - KeyResponse: dto.KeyPullResponse{ - Keys: []dto.Key{}, + KeyResponse: dtov1.KeyPullResponse{ + Keys: []dtov1.Key{}, }, }, err: nil, @@ -156,8 +156,8 @@ func TestGetCertificates(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.SecuritySettings{ - ProfileAssociation: []dto.ProfileAssociation{ + res: dtov1.SecuritySettings{ + ProfileAssociation: []dtov1.ProfileAssociation{ { Type: "TLS", ProfileID: "TLSProtocolEndpoint Instances Collection", @@ -166,12 +166,12 @@ func TestGetCertificates(t *testing.T) { Key: nil, }, }, - CertificateResponse: dto.CertificatePullResponse{ - KeyManagementItems: []dto.RefinedKeyManagementResponse{}, - Certificates: []dto.RefinedCertificate{}, + CertificateResponse: dtov1.CertificatePullResponse{ + KeyManagementItems: []dtov1.RefinedKeyManagementResponse{}, + Certificates: []dtov1.RefinedCertificate{}, }, - KeyResponse: dto.KeyPullResponse{ - Keys: []dto.Key{}, + KeyResponse: dtov1.KeyPullResponse{ + Keys: []dtov1.Key{}, }, }, err: nil, @@ -184,7 +184,7 @@ func TestGetCertificates(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: dto.SecuritySettings{}, + res: dtov1.SecuritySettings{}, err: devices.ErrDatabase, }, { @@ -203,7 +203,7 @@ func TestGetCertificates(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.SecuritySettings{}, + res: dtov1.SecuritySettings{}, err: ErrGeneral, }, } diff --git a/internal/usecase/devices/connections.go b/internal/usecase/devices/connections.go index 1e1e2efb..5f0d9ddd 100644 --- a/internal/usecase/devices/connections.go +++ b/internal/usecase/devices/connections.go @@ -5,10 +5,10 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/tls" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) -func (uc *UseCase) GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) { +func (uc *UseCase) GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return nil, err @@ -22,7 +22,7 @@ func (uc *UseCase) GetTLSSettingData(c context.Context, guid string) ([]dto.Sett } // iterate over the data and convert each entity to dto - d1 := make([]dto.SettingDataResponse, len(response)) + d1 := make([]dtov1.SettingDataResponse, len(response)) for i := range response { tmpEntity := response[i] // create a new variable to avoid memory aliasing @@ -32,8 +32,8 @@ func (uc *UseCase) GetTLSSettingData(c context.Context, guid string) ([]dto.Sett return d1, nil } -func (uc *UseCase) tlsSettingDataEntityToDTO(d *tls.SettingDataResponse) *dto.SettingDataResponse { - d1 := &dto.SettingDataResponse{ +func (uc *UseCase) tlsSettingDataEntityToDTO(d *tls.SettingDataResponse) *dtov1.SettingDataResponse { + d1 := &dtov1.SettingDataResponse{ ElementName: d.ElementName, InstanceID: d.InstanceID, MutualAuthentication: d.MutualAuthentication, diff --git a/internal/usecase/devices/connections_test.go b/internal/usecase/devices/connections_test.go index 88abc0a9..5218f14d 100644 --- a/internal/usecase/devices/connections_test.go +++ b/internal/usecase/devices/connections_test.go @@ -9,7 +9,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -67,7 +67,7 @@ func TestGetTLSSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.SettingDataResponse{ + res: []dtov1.SettingDataResponse{ { ElementName: "", InstanceID: "", @@ -88,7 +88,7 @@ func TestGetTLSSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: []dto.SettingDataResponse(nil), + res: []dtov1.SettingDataResponse(nil), err: devices.ErrDatabase, }, { @@ -107,7 +107,7 @@ func TestGetTLSSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.SettingDataResponse(nil), + res: []dtov1.SettingDataResponse(nil), err: ErrGeneral, }, } diff --git a/internal/usecase/devices/consent.go b/internal/usecase/devices/consent.go index 5158b546..1b572601 100644 --- a/internal/usecase/devices/consent.go +++ b/internal/usecase/devices/consent.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) func (uc *UseCase) CancelUserConsent(c context.Context, guid string) (interface{}, error) { @@ -43,7 +43,7 @@ func (uc *UseCase) GetUserConsentCode(c context.Context, guid string) (map[strin return response, nil } -func (uc *UseCase) SendConsentCode(c context.Context, userConsent dto.UserConsent, guid string) (interface{}, error) { +func (uc *UseCase) SendConsentCode(c context.Context, userConsent dtov1.UserConsent, guid string) (interface{}, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return nil, err diff --git a/internal/usecase/devices/consent_test.go b/internal/usecase/devices/consent_test.go index b771c784..41297fae 100644 --- a/internal/usecase/devices/consent_test.go +++ b/internal/usecase/devices/consent_test.go @@ -10,7 +10,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -257,7 +257,7 @@ func TestSendConsentCode(t *testing.T) { TenantID: "tenant-id-456", } - consent := dto.UserConsent{ + consent := dtov1.UserConsent{ ConsentCode: "123456", } diff --git a/internal/usecase/devices/info.go b/internal/usecase/devices/info.go index a2001968..fd5b2012 100644 --- a/internal/usecase/devices/info.go +++ b/internal/usecase/devices/info.go @@ -2,57 +2,76 @@ package devices import ( "context" + "strconv" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/setupandconfiguration" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/software" + + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" ) -func (uc *UseCase) GetVersion(c context.Context, guid string) (map[string]interface{}, error) { +func (uc *UseCase) GetVersion(c context.Context, guid string) (dtov1.Version, dtov2.Version, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return nil, err + return dtov1.Version{}, dtov2.Version{}, err } device := uc.device.SetupWsmanClient(*item, false, true) - version, err := device.GetAMTVersion() + softwareIdentity, err := device.GetAMTVersion() if err != nil { - return nil, err + return dtov1.Version{}, dtov2.Version{}, err } data, err := device.GetSetupAndConfiguration() if err != nil { - return nil, err + return dtov1.Version{}, dtov2.Version{}, err } - response := map[string]interface{}{ - "CIM_SoftwareIdentity": map[string]interface{}{ - "responses": version, - }, - "AMT_SetupAndConfigurationService": map[string]interface{}{ - "response": data[0], - }, + // iterate over the data and convert each entity to dto + d1 := make([]dtov1.SoftwareIdentity, len(softwareIdentity)) + + for i := range softwareIdentity { + tmpEntity := softwareIdentity[i] // create a new variable to avoid memory aliasing + d1[i] = *uc.softwareIdentityEntityToDTOv1(&tmpEntity) } - return response, nil + // iterate over the data and convert each entity to dto + d3 := make([]dtov1.SetupAndConfigurationServiceResponse, len(data)) + + for i := range data { + tmpEntity := data[i] // create a new variable to avoid memory aliasing + d3[i] = *uc.setupAndConfigurationServiceResponseEntityToDTO(&tmpEntity) + } + + v1Version := dtov1.Version{ + CIMSoftwareIdentity: d1, + AMTSetupAndConfigurationService: d3[0], + } + + v2Version := *uc.softwareIdentityEntityToDTOv2(softwareIdentity) + + return v1Version, v2Version, nil } -func (uc *UseCase) GetFeatures(c context.Context, guid string) (dto.Features, error) { +func (uc *UseCase) GetFeatures(c context.Context, guid string) (dtov1.Features, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.Features{}, err + return dtov1.Features{}, err } device := uc.device.SetupWsmanClient(*item, false, true) features, err := device.GetFeatures() if err != nil { - return dto.Features{}, err + return dtov1.Features{}, err } return features, nil } -func (uc *UseCase) SetFeatures(c context.Context, guid string, features dto.Features) (dto.Features, error) { +func (uc *UseCase) SetFeatures(c context.Context, guid string, features dtov1.Features) (dtov1.Features, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return features, err @@ -100,27 +119,27 @@ func (uc *UseCase) GetDiskInfo(c context.Context, guid string) (interface{}, err return diskInfo, nil } -func (uc *UseCase) GetAuditLog(c context.Context, startIndex int, guid string) (dto.AuditLog, error) { +func (uc *UseCase) GetAuditLog(c context.Context, startIndex int, guid string) (dtov1.AuditLog, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.AuditLog{}, err + return dtov1.AuditLog{}, err } device := uc.device.SetupWsmanClient(*item, false, true) response, err := device.GetAuditLog(startIndex) if err != nil { - return dto.AuditLog{}, err + return dtov1.AuditLog{}, err } - auditLogResponse := dto.AuditLog{} + auditLogResponse := dtov1.AuditLog{} auditLogResponse.TotalCount = response.Body.ReadRecordsResponse.TotalRecordCount auditLogResponse.Records = response.Body.DecodedRecordsResponse return auditLogResponse, nil } -func (uc *UseCase) GetEventLog(c context.Context, guid string) ([]dto.EventLog, error) { +func (uc *UseCase) GetEventLog(c context.Context, guid string) ([]dtov1.EventLog, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return nil, err @@ -133,11 +152,11 @@ func (uc *UseCase) GetEventLog(c context.Context, guid string) ([]dto.EventLog, return nil, err } - events := make([]dto.EventLog, len(eventLogs.RefinedEventData)) + events := make([]dtov1.EventLog, len(eventLogs.RefinedEventData)) for idx := range eventLogs.RefinedEventData { event := &eventLogs.RefinedEventData[idx] - dtoEvent := dto.EventLog{ + dtoEvent := dtov1.EventLog{ // DeviceAddress: event.DeviceAddress, // EventSensorType: event.EventSensorType, // EventType: event.EventType, @@ -179,3 +198,63 @@ func (uc *UseCase) GetGeneralSettings(c context.Context, guid string) (interface return response, nil } + +func (uc *UseCase) softwareIdentityEntityToDTOv1(d *software.SoftwareIdentity) *dtov1.SoftwareIdentity { + d1 := &dtov1.SoftwareIdentity{ + InstanceID: d.InstanceID, + VersionString: d.VersionString, + IsEntity: d.IsEntity, + } + + return d1 +} + +func (uc *UseCase) softwareIdentityEntityToDTOv2(d []software.SoftwareIdentity) *dtov2.Version { + data := make(map[string]string) + for i := range d { + data[d[i].InstanceID] = d[i].VersionString + } + + var legacyModePointer *bool + + legacyMode, err := strconv.ParseBool(data["Legacy Mode"]) + if err == nil { + legacyModePointer = &legacyMode + } + + return &dtov2.Version{ + Flash: data["Flash"], + Netstack: data["Netstack"], + AMTApps: data["AMTApps"], + AMT: data["AMT"], + Sku: data["Sku"], + VendorID: data["VendorID"], + BuildNumber: data["Build Number"], + RecoveryVersion: data["Recovery Version"], + RecoveryBuildNumber: data["Recovery Build Num"], + LegacyMode: legacyModePointer, + AmtFWCoreVersion: data["AMT FW Core Version"], + } +} + +func (uc *UseCase) setupAndConfigurationServiceResponseEntityToDTO(d *setupandconfiguration.SetupAndConfigurationServiceResponse) *dtov1.SetupAndConfigurationServiceResponse { + d1 := &dtov1.SetupAndConfigurationServiceResponse{ + RequestedState: d.RequestedState, + EnabledState: d.EnabledState, + ElementName: d.ElementName, + SystemCreationClassName: d.SystemCreationClassName, + SystemName: d.SystemName, + CreationClassName: d.CreationClassName, + Name: d.Name, + ProvisioningMode: d.ProvisioningMode, + ProvisioningState: d.ProvisioningState, + ZeroTouchConfigurationEnabled: d.ZeroTouchConfigurationEnabled, + ProvisioningServerOTP: d.ProvisioningServerOTP, + ConfigurationServerFQDN: d.ConfigurationServerFQDN, + PasswordModel: d.PasswordModel, + DhcpDNSSuffix: d.DhcpDNSSuffix, + TrustedDNSSuffix: d.TrustedDNSSuffix, + } + + return d1 +} diff --git a/internal/usecase/devices/info_test.go b/internal/usecase/devices/info_test.go index 51a9b7dc..f42f714f 100644 --- a/internal/usecase/devices/info_test.go +++ b/internal/usecase/devices/info_test.go @@ -13,7 +13,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -47,7 +47,13 @@ func TestGetVersion(t *testing.T) { TenantID: "tenant-id-456", } - softwares := []software.SoftwareIdentity{} + softwares := []software.SoftwareIdentity{ + { + InstanceID: "Flash", + VersionString: "0.0.0", + IsEntity: true, + }, + } responses := []setupandconfiguration.SetupAndConfigurationServiceResponse{} @@ -93,31 +99,15 @@ func TestGetVersion(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: map[string]interface{}{ - "AMT_SetupAndConfigurationService": map[string]interface{}{ - "response": setupandconfiguration.SetupAndConfigurationServiceResponse{ - XMLName: xml.Name{Space: "", Local: "AMT_SetupAndConfigurationService"}, - RequestedState: 1, - EnabledState: 1, - ElementName: "SampleElementName", - SystemCreationClassName: "SampleSystemCreationClassName", - SystemName: "SampleSystemName", - CreationClassName: "SampleCreationClassName", - Name: "SampleName", - ProvisioningMode: 1, - ProvisioningState: 1, - ZeroTouchConfigurationEnabled: true, - ProvisioningServerOTP: "SampleProvisioningServerOTP", - ConfigurationServerFQDN: "SampleConfigurationServerFQDN", - PasswordModel: 1, - DhcpDNSSuffix: "SampleDhcpDNSSuffix", - TrustedDNSSuffix: "SampleTrustedDNSSuffix", - }, - }, - "CIM_SoftwareIdentity": map[string]interface{}{ - "responses": []software.SoftwareIdentity{}, + + res: dtov1.Version{CIMSoftwareIdentity: []dtov1.SoftwareIdentity{ + { + InstanceID: "Flash", + VersionString: "0.0.0", + IsEntity: true, }, - }, + }, AMTSetupAndConfigurationService: dtov1.SetupAndConfigurationServiceResponse{RequestedState: 1, EnabledState: 1, ElementName: "SampleElementName", SystemCreationClassName: "SampleSystemCreationClassName", SystemName: "SampleSystemName", CreationClassName: "SampleCreationClassName", Name: "SampleName", ProvisioningMode: 1, ProvisioningState: 1, ZeroTouchConfigurationEnabled: true, ProvisioningServerOTP: "SampleProvisioningServerOTP", ConfigurationServerFQDN: "SampleConfigurationServerFQDN", PasswordModel: 1, DhcpDNSSuffix: "SampleDhcpDNSSuffix", TrustedDNSSuffix: "SampleTrustedDNSSuffix"}}, + err: nil, }, { @@ -129,7 +119,9 @@ func TestGetVersion(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: map[string]interface{}(nil), + + res: dtov1.Version{CIMSoftwareIdentity: []dtov1.SoftwareIdentity(nil), AMTSetupAndConfigurationService: dtov1.SetupAndConfigurationServiceResponse{RequestedState: 0, EnabledState: 0, ElementName: "", SystemCreationClassName: "", SystemName: "", CreationClassName: "", Name: "", ProvisioningMode: 0, ProvisioningState: 0, ZeroTouchConfigurationEnabled: false, ProvisioningServerOTP: "", ConfigurationServerFQDN: "", PasswordModel: 0, DhcpDNSSuffix: "", TrustedDNSSuffix: ""}}, + err: devices.ErrDatabase, }, { @@ -148,7 +140,9 @@ func TestGetVersion(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: map[string]interface{}(nil), + + res: dtov1.Version{}, + err: ErrGeneral, }, { @@ -171,7 +165,9 @@ func TestGetVersion(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: map[string]interface{}(nil), + + res: dtov1.Version{CIMSoftwareIdentity: []dtov1.SoftwareIdentity(nil), AMTSetupAndConfigurationService: dtov1.SetupAndConfigurationServiceResponse{RequestedState: 0, EnabledState: 0, ElementName: "", SystemCreationClassName: "", SystemName: "", CreationClassName: "", Name: "", ProvisioningMode: 0, ProvisioningState: 0, ZeroTouchConfigurationEnabled: false, ProvisioningServerOTP: "", ConfigurationServerFQDN: "", PasswordModel: 0, DhcpDNSSuffix: "", TrustedDNSSuffix: ""}}, + err: ErrGeneral, }, } @@ -188,7 +184,7 @@ func TestGetVersion(t *testing.T) { tc.repoMock(repo) - res, err := useCase.GetVersion(context.Background(), device.GUID) + res, _, err := useCase.GetVersion(context.Background(), device.GUID) require.Equal(t, tc.res, res) @@ -215,14 +211,14 @@ func TestGetFeatures(t *testing.T) { Return(man2) man2.EXPECT(). GetFeatures(). - Return(dto.Features{}, nil) + Return(dtov1.Features{}, nil) }, repoMock: func(repo *MockRepository) { repo.EXPECT(). GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.Features{}, + res: dtov1.Features{}, err: nil, }, { @@ -234,7 +230,7 @@ func TestGetFeatures(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: dto.Features{}, + res: dtov1.Features{}, err: devices.ErrDatabase, }, { @@ -246,14 +242,14 @@ func TestGetFeatures(t *testing.T) { Return(man2) man2.EXPECT(). GetFeatures(). - Return(dto.Features{}, ErrGeneral) + Return(dtov1.Features{}, ErrGeneral) }, repoMock: func(repo *MockRepository) { repo.EXPECT(). GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.Features{}, + res: dtov1.Features{}, err: ErrGeneral, }, } @@ -287,7 +283,7 @@ func TestSetFeatures(t *testing.T) { TenantID: "tenant-id-456", } - featureSet := dto.Features{ + featureSet := dtov1.Features{ UserConsent: "kvm", EnableSOL: true, EnableIDER: true, @@ -473,7 +469,7 @@ func TestGetAuditLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.AuditLog{}, + res: dtov1.AuditLog{}, err: nil, }, { @@ -485,7 +481,7 @@ func TestGetAuditLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: dto.AuditLog{ + res: dtov1.AuditLog{ TotalCount: 0, Records: nil, }, @@ -507,7 +503,7 @@ func TestGetAuditLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.AuditLog{TotalCount: 0, Records: nil}, + res: dtov1.AuditLog{TotalCount: 0, Records: nil}, err: ErrGeneral, }, } @@ -556,7 +552,7 @@ func TestGetEventLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.EventLog{}, + res: []dtov1.EventLog{}, err: nil, }, { @@ -568,7 +564,7 @@ func TestGetEventLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: []dto.EventLog(nil), + res: []dtov1.EventLog(nil), err: devices.ErrDatabase, }, { @@ -587,7 +583,7 @@ func TestGetEventLog(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: []dto.EventLog(nil), + res: []dtov1.EventLog(nil), err: ErrGeneral, }, } diff --git a/internal/usecase/devices/interceptor.go b/internal/usecase/devices/interceptor.go index 766a476c..311fafd8 100644 --- a/internal/usecase/devices/interceptor.go +++ b/internal/usecase/devices/interceptor.go @@ -13,7 +13,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) const ( @@ -26,7 +26,7 @@ const ( type DeviceConnection struct { Conn *websocket.Conn wsmanMessages wsman.Messages - Device dto.Device + Device dtov1.Device Direct bool Mode string Challenge client.AuthChallenge diff --git a/internal/usecase/devices/interfaces.go b/internal/usecase/devices/interfaces.go index bad886a4..305b8337 100644 --- a/internal/usecase/devices/interfaces.go +++ b/internal/usecase/devices/interfaces.go @@ -8,19 +8,20 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/power" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + dtov2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" wsmanAPI "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" ) type ( WSMAN interface { - SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsmanAPI.Management - DestroyWsmanClient(device dto.Device) + SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsmanAPI.Management + DestroyWsmanClient(device dtov1.Device) Worker() } Redirection interface { - SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman.Messages + SetupWsmanClient(device dtov1.Device, isRedirection, logMessages bool) wsman.Messages RedirectConnect(ctx context.Context, deviceConnection *DeviceConnection) error RedirectClose(ctx context.Context, deviceConnection *DeviceConnection) error RedirectListen(ctx context.Context, deviceConnection *DeviceConnection) ([]byte, error) @@ -40,20 +41,20 @@ type ( Feature interface { // Repository/Database Calls GetCount(context.Context, string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) - GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) + GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) GetDistinctTags(ctx context.Context, tenantID string) ([]string, error) - GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) + GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) Delete(ctx context.Context, guid, tenantID string) error - Update(ctx context.Context, d *dto.Device) (*dto.Device, error) - Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) - GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) + Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) + Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) + GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) // Management Calls - GetVersion(ctx context.Context, guid string) (map[string]interface{}, error) - GetFeatures(ctx context.Context, guid string) (dto.Features, error) - SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) - GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) - CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) + GetVersion(ctx context.Context, guid string) (dtov1.Version, dtov2.Version, error) + GetFeatures(ctx context.Context, guid string) (dtov1.Features, error) + SetFeatures(ctx context.Context, guid string, features dtov1.Features) (dtov1.Features, error) + GetAlarmOccurrences(ctx context.Context, guid string) ([]dtov1.AlarmClockOccurrence, error) + CreateAlarmOccurrences(ctx context.Context, guid string, alarm dtov1.AlarmClockOccurrence) (dtov1.AddAlarmOutput, error) DeleteAlarmOccurrences(ctx context.Context, guid, instanceID string) error GetHardwareInfo(ctx context.Context, guid string) (interface{}, error) GetPowerState(ctx context.Context, guid string) (map[string]interface{}, error) @@ -61,16 +62,16 @@ type ( GetGeneralSettings(ctx context.Context, guid string) (interface{}, error) CancelUserConsent(ctx context.Context, guid string) (interface{}, error) GetUserConsentCode(ctx context.Context, guid string) (map[string]interface{}, error) - SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (interface{}, error) + SendConsentCode(ctx context.Context, code dtov1.UserConsent, guid string) (interface{}, error) SendPowerAction(ctx context.Context, guid string, action int) (power.PowerActionResponse, error) - SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) - GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) - GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) + SetBootOptions(ctx context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) + GetAuditLog(ctx context.Context, startIndex int, guid string) (dtov1.AuditLog, error) + GetEventLog(ctx context.Context, guid string) ([]dtov1.EventLog, error) Redirect(ctx context.Context, conn *websocket.Conn, guid, mode string) error - GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) - GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) - GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) + GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) + GetCertificates(c context.Context, guid string) (dtov1.SecuritySettings, error) + GetTLSSettingData(c context.Context, guid string) ([]dtov1.SettingDataResponse, error) GetDiskInfo(c context.Context, guid string) (interface{}, error) - GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) + GetDeviceCertificate(c context.Context, guid string) (dtov1.Certificate, error) } ) diff --git a/internal/usecase/devices/mocks_test.go b/internal/usecase/devices/mocks_test.go index 357f3ebd..b603713e 100644 --- a/internal/usecase/devices/mocks_test.go +++ b/internal/usecase/devices/mocks_test.go @@ -15,7 +15,8 @@ import ( websocket "github.com/gorilla/websocket" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + v1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" + v2 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v2" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" wsman0 "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" @@ -47,7 +48,7 @@ func (m *MockWSMAN) EXPECT() *MockWSMANMockRecorder { } // DestroyWsmanClient mocks base method. -func (m *MockWSMAN) DestroyWsmanClient(device dto.Device) { +func (m *MockWSMAN) DestroyWsmanClient(device v1.Device) { m.ctrl.T.Helper() m.ctrl.Call(m, "DestroyWsmanClient", device) } @@ -59,7 +60,7 @@ func (mr *MockWSMANMockRecorder) DestroyWsmanClient(device any) *gomock.Call { } // SetupWsmanClient mocks base method. -func (m *MockWSMAN) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman.Management { +func (m *MockWSMAN) SetupWsmanClient(device v1.Device, isRedirection, logMessages bool) wsman.Management { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman.Management) @@ -165,7 +166,7 @@ func (mr *MockRedirectionMockRecorder) RedirectSend(ctx, deviceConnection, messa } // SetupWsmanClient mocks base method. -func (m *MockRedirection) SetupWsmanClient(device dto.Device, isRedirection, logMessages bool) wsman0.Messages { +func (m *MockRedirection) SetupWsmanClient(device v1.Device, isRedirection, logMessages bool) wsman0.Messages { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetupWsmanClient", device, isRedirection, logMessages) ret0, _ := ret[0].(wsman0.Messages) @@ -375,10 +376,10 @@ func (mr *MockFeatureMockRecorder) CancelUserConsent(ctx, guid any) *gomock.Call } // CreateAlarmOccurrences mocks base method. -func (m *MockFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm dto.AlarmClockOccurrence) (dto.AddAlarmOutput, error) { +func (m *MockFeature) CreateAlarmOccurrences(ctx context.Context, guid string, alarm v1.AlarmClockOccurrence) (v1.AddAlarmOutput, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateAlarmOccurrences", ctx, guid, alarm) - ret0, _ := ret[0].(dto.AddAlarmOutput) + ret0, _ := ret[0].(v1.AddAlarmOutput) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -418,10 +419,10 @@ func (mr *MockFeatureMockRecorder) DeleteAlarmOccurrences(ctx, guid, instanceID } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -433,10 +434,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetAlarmOccurrences mocks base method. -func (m *MockFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]dto.AlarmClockOccurrence, error) { +func (m *MockFeature) GetAlarmOccurrences(ctx context.Context, guid string) ([]v1.AlarmClockOccurrence, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAlarmOccurrences", ctx, guid) - ret0, _ := ret[0].([]dto.AlarmClockOccurrence) + ret0, _ := ret[0].([]v1.AlarmClockOccurrence) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -448,10 +449,10 @@ func (mr *MockFeatureMockRecorder) GetAlarmOccurrences(ctx, guid any) *gomock.Ca } // GetAuditLog mocks base method. -func (m *MockFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (dto.AuditLog, error) { +func (m *MockFeature) GetAuditLog(ctx context.Context, startIndex int, guid string) (v1.AuditLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAuditLog", ctx, startIndex, guid) - ret0, _ := ret[0].(dto.AuditLog) + ret0, _ := ret[0].(v1.AuditLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -463,10 +464,10 @@ func (mr *MockFeatureMockRecorder) GetAuditLog(ctx, startIndex, guid any) *gomoc } // GetByColumn mocks base method. -func (m *MockFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByColumn", ctx, columnName, queryValue, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -478,10 +479,10 @@ func (mr *MockFeatureMockRecorder) GetByColumn(ctx, columnName, queryValue, tena } // GetByID mocks base method. -func (m *MockFeature) GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) { +func (m *MockFeature) GetByID(ctx context.Context, guid, tenantID string) (*v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByID", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -493,10 +494,10 @@ func (mr *MockFeatureMockRecorder) GetByID(ctx, guid, tenantID any) *gomock.Call } // GetByTags mocks base method. -func (m *MockFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) { +func (m *MockFeature) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByTags", ctx, tags, method, limit, offset, tenantID) - ret0, _ := ret[0].([]dto.Device) + ret0, _ := ret[0].([]v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -508,10 +509,10 @@ func (mr *MockFeatureMockRecorder) GetByTags(ctx, tags, method, limit, offset, t } // GetCertificates mocks base method. -func (m *MockFeature) GetCertificates(c context.Context, guid string) (dto.SecuritySettings, error) { +func (m *MockFeature) GetCertificates(c context.Context, guid string) (v1.SecuritySettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCertificates", c, guid) - ret0, _ := ret[0].(dto.SecuritySettings) + ret0, _ := ret[0].(v1.SecuritySettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -538,10 +539,10 @@ func (mr *MockFeatureMockRecorder) GetCount(arg0, arg1 any) *gomock.Call { } // GetDeviceCertificate mocks base method. -func (m *MockFeature) GetDeviceCertificate(c context.Context, guid string) (dto.Certificate, error) { +func (m *MockFeature) GetDeviceCertificate(c context.Context, guid string) (v1.Certificate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDeviceCertificate", c, guid) - ret0, _ := ret[0].(dto.Certificate) + ret0, _ := ret[0].(v1.Certificate) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -583,10 +584,10 @@ func (mr *MockFeatureMockRecorder) GetDistinctTags(ctx, tenantID any) *gomock.Ca } // GetEventLog mocks base method. -func (m *MockFeature) GetEventLog(ctx context.Context, guid string) ([]dto.EventLog, error) { +func (m *MockFeature) GetEventLog(ctx context.Context, guid string) ([]v1.EventLog, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetEventLog", ctx, guid) - ret0, _ := ret[0].([]dto.EventLog) + ret0, _ := ret[0].([]v1.EventLog) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -598,10 +599,10 @@ func (mr *MockFeatureMockRecorder) GetEventLog(ctx, guid any) *gomock.Call { } // GetFeatures mocks base method. -func (m *MockFeature) GetFeatures(ctx context.Context, guid string) (dto.Features, error) { +func (m *MockFeature) GetFeatures(ctx context.Context, guid string) (v1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures", ctx, guid) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(v1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -643,10 +644,10 @@ func (mr *MockFeatureMockRecorder) GetHardwareInfo(ctx, guid any) *gomock.Call { } // GetNetworkSettings mocks base method. -func (m *MockFeature) GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) { +func (m *MockFeature) GetNetworkSettings(c context.Context, guid string) (v1.NetworkSettings, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNetworkSettings", c, guid) - ret0, _ := ret[0].(dto.NetworkSettings) + ret0, _ := ret[0].(v1.NetworkSettings) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -688,10 +689,10 @@ func (mr *MockFeatureMockRecorder) GetPowerState(ctx, guid any) *gomock.Call { } // GetTLSSettingData mocks base method. -func (m *MockFeature) GetTLSSettingData(c context.Context, guid string) ([]dto.SettingDataResponse, error) { +func (m *MockFeature) GetTLSSettingData(c context.Context, guid string) ([]v1.SettingDataResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTLSSettingData", c, guid) - ret0, _ := ret[0].([]dto.SettingDataResponse) + ret0, _ := ret[0].([]v1.SettingDataResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -718,12 +719,13 @@ func (mr *MockFeatureMockRecorder) GetUserConsentCode(ctx, guid any) *gomock.Cal } // GetVersion mocks base method. -func (m *MockFeature) GetVersion(ctx context.Context, guid string) (map[string]any, error) { +func (m *MockFeature) GetVersion(ctx context.Context, guid string) (v1.Version, v2.Version, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetVersion", ctx, guid) - ret0, _ := ret[0].(map[string]any) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(v1.Version) + ret1, _ := ret[1].(v2.Version) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // GetVersion indicates an expected call of GetVersion. @@ -733,10 +735,10 @@ func (mr *MockFeatureMockRecorder) GetVersion(ctx, guid any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockFeature) Insert(ctx context.Context, d *v1.Device) (*v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -762,7 +764,7 @@ func (mr *MockFeatureMockRecorder) Redirect(ctx, conn, guid, mode any) *gomock.C } // SendConsentCode mocks base method. -func (m *MockFeature) SendConsentCode(ctx context.Context, code dto.UserConsent, guid string) (any, error) { +func (m *MockFeature) SendConsentCode(ctx context.Context, code v1.UserConsent, guid string) (any, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SendConsentCode", ctx, code, guid) ret0, _ := ret[0].(any) @@ -792,7 +794,7 @@ func (mr *MockFeatureMockRecorder) SendPowerAction(ctx, guid, action any) *gomoc } // SetBootOptions mocks base method. -func (m *MockFeature) SetBootOptions(ctx context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) { +func (m *MockFeature) SetBootOptions(ctx context.Context, guid string, bootSetting v1.BootSetting) (power.PowerActionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetBootOptions", ctx, guid, bootSetting) ret0, _ := ret[0].(power.PowerActionResponse) @@ -807,10 +809,10 @@ func (mr *MockFeatureMockRecorder) SetBootOptions(ctx, guid, bootSetting any) *g } // SetFeatures mocks base method. -func (m *MockFeature) SetFeatures(ctx context.Context, guid string, features dto.Features) (dto.Features, error) { +func (m *MockFeature) SetFeatures(ctx context.Context, guid string, features v1.Features) (v1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", ctx, guid, features) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(v1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -822,10 +824,10 @@ func (mr *MockFeatureMockRecorder) SetFeatures(ctx, guid, features any) *gomock. } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (m *MockFeature) Update(ctx context.Context, d *v1.Device) (*v1.Device, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Device) + ret0, _ := ret[0].(*v1.Device) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/devices/network.go b/internal/usecase/devices/network.go index 13f7787e..e536767e 100644 --- a/internal/usecase/devices/network.go +++ b/internal/usecase/devices/network.go @@ -3,31 +3,31 @@ package devices import ( "context" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" ) -func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dto.NetworkSettings, error) { +func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dtov1.NetworkSettings, error) { item, err := uc.GetByID(c, guid, "") if err != nil { - return dto.NetworkSettings{}, err + return dtov1.NetworkSettings{}, err } device := uc.device.SetupWsmanClient(*item, false, true) response, err := device.GetNetworkSettings() if err != nil { - return dto.NetworkSettings{}, err + return dtov1.NetworkSettings{}, err } - ns := dto.NetworkSettings{ - Wired: dto.WiredNetworkInfo{ - IEEE8021x: dto.IEEE8021x{ + ns := dtov1.NetworkSettings{ + Wired: dtov1.WiredNetworkInfo{ + IEEE8021x: dtov1.IEEE8021x{ Enabled: int(response.IPSIEEE8021xSettingsResult.Enabled), AvailableInS0: response.IPSIEEE8021xSettingsResult.AvailableInS0, PxeTimeout: response.IPSIEEE8021xSettingsResult.PxeTimeout, }, - NetworkInfo: dto.NetworkInfo{ + NetworkInfo: dtov1.NetworkInfo{ ElementName: response.EthernetPortSettingsResult[0].ElementName, InstanceID: response.EthernetPortSettingsResult[0].InstanceID, VLANTag: response.EthernetPortSettingsResult[0].VLANTag, @@ -51,8 +51,8 @@ func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dto.Netwo PhysicalNicMedium: int(response.EthernetPortSettingsResult[0].PhysicalNicMedium), }, }, - Wireless: dto.WirelessNetworkInfo{ - NetworkInfo: dto.NetworkInfo{ + Wireless: dtov1.WirelessNetworkInfo{ + NetworkInfo: dtov1.NetworkInfo{ ElementName: response.EthernetPortSettingsResult[1].ElementName, InstanceID: response.EthernetPortSettingsResult[1].InstanceID, VLANTag: response.EthernetPortSettingsResult[1].VLANTag, @@ -81,7 +81,7 @@ func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dto.Netwo convertLinkPolicy(response, &ns) for _, v := range response.WiFiSettingsResult { - ns.Wireless.WiFiNetworks = append(ns.Wireless.WiFiNetworks, dto.WiFiNetwork{ + ns.Wireless.WiFiNetworks = append(ns.Wireless.WiFiNetworks, dtov1.WiFiNetwork{ SSID: v.SSID, AuthenticationMethod: int(v.AuthenticationMethod), EncryptionMethod: int(v.EncryptionMethod), @@ -92,7 +92,7 @@ func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dto.Netwo for i := range response.CIMIEEE8021xSettingsResult.IEEE8021xSettingsItems { v := &response.CIMIEEE8021xSettingsResult.IEEE8021xSettingsItems[i] - ns.Wireless.IEEE8021xSettings = append(ns.Wireless.IEEE8021xSettings, dto.IEEE8021xSettings{ + ns.Wireless.IEEE8021xSettings = append(ns.Wireless.IEEE8021xSettings, dtov1.IEEE8021xSettings{ AuthenticationProtocol: v.AuthenticationProtocol, RoamingIdentity: v.RoamingIdentity, ServerCertificateName: v.ServerCertificateName, @@ -107,7 +107,7 @@ func (uc *UseCase) GetNetworkSettings(c context.Context, guid string) (dto.Netwo return ns, nil } -func convertLinkPolicy(response wsman.NetworkResults, ns *dto.NetworkSettings) { +func convertLinkPolicy(response wsman.NetworkResults, ns *dtov1.NetworkSettings) { for _, v := range response.EthernetPortSettingsResult[0].LinkPolicy { ns.Wired.NetworkInfo.LinkPolicy = append(ns.Wired.NetworkInfo.LinkPolicy, int(v)) } diff --git a/internal/usecase/devices/network_test.go b/internal/usecase/devices/network_test.go index 42f4c9f0..38ae2eaf 100644 --- a/internal/usecase/devices/network_test.go +++ b/internal/usecase/devices/network_test.go @@ -12,7 +12,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -73,17 +73,17 @@ func TestGetNetworkSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.NetworkSettings{ - Wired: dto.WiredNetworkInfo{ - IEEE8021x: dto.IEEE8021x{}, - NetworkInfo: dto.NetworkInfo{ + res: dtov1.NetworkSettings{ + Wired: dtov1.WiredNetworkInfo{ + IEEE8021x: dtov1.IEEE8021x{}, + NetworkInfo: dtov1.NetworkInfo{ LinkPolicy: []int{1, 2}, }, }, - Wireless: dto.WirelessNetworkInfo{ - WiFiNetworks: []dto.WiFiNetwork{{}}, - IEEE8021xSettings: []dto.IEEE8021xSettings{{}}, - NetworkInfo: dto.NetworkInfo{ + Wireless: dtov1.WirelessNetworkInfo{ + WiFiNetworks: []dtov1.WiFiNetwork{{}}, + IEEE8021xSettings: []dtov1.IEEE8021xSettings{{}}, + NetworkInfo: dtov1.NetworkInfo{ LinkPolicy: []int{1, 2}, }, }, @@ -98,7 +98,7 @@ func TestGetNetworkSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: dto.NetworkSettings{}, + res: dtov1.NetworkSettings{}, err: devices.ErrDatabase, }, { @@ -117,7 +117,7 @@ func TestGetNetworkSettings(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: dto.NetworkSettings{}, + res: dtov1.NetworkSettings{}, err: ErrGeneral, }, } diff --git a/internal/usecase/devices/power.go b/internal/usecase/devices/power.go index cbb1aea1..8a72c9fd 100644 --- a/internal/usecase/devices/power.go +++ b/internal/usecase/devices/power.go @@ -10,7 +10,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/power" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/software" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) func (uc *UseCase) SendPowerAction(c context.Context, guid string, action int) (power.PowerActionResponse, error) { @@ -115,7 +115,7 @@ func determinePowerCapabilities(amtversion int, capabilities boot.BootCapabiliti return response } -func (uc *UseCase) SetBootOptions(c context.Context, guid string, bootSetting dto.BootSetting) (power.PowerActionResponse, error) { +func (uc *UseCase) SetBootOptions(c context.Context, guid string, bootSetting dtov1.BootSetting) (power.PowerActionResponse, error) { item, err := uc.GetByID(c, guid, "") if err != nil { return power.PowerActionResponse{}, err @@ -188,7 +188,7 @@ func (uc *UseCase) SetBootOptions(c context.Context, guid string, bootSetting dt return powerActionResult, nil } -func determineIDERBootDevice(bootSetting dto.BootSetting, newData *boot.BootSettingDataRequest) { +func determineIDERBootDevice(bootSetting dtov1.BootSetting, newData *boot.BootSettingDataRequest) { if bootSetting.Action == 202 || bootSetting.Action == 203 { newData.IDERBootDevice = 1 } else { @@ -198,7 +198,7 @@ func determineIDERBootDevice(bootSetting dto.BootSetting, newData *boot.BootSett // "Intel(r) AMT: Force PXE Boot". // "Intel(r) AMT: Force CD/DVD Boot". -func getBootSource(bootSetting dto.BootSetting) string { +func getBootSource(bootSetting dtov1.BootSetting) string { if bootSetting.Action == 400 || bootSetting.Action == 401 { return string(cimBoot.PXE) } else if bootSetting.Action == 202 || bootSetting.Action == 203 { @@ -208,7 +208,7 @@ func getBootSource(bootSetting dto.BootSetting) string { return "" } -func determineBootAction(bootSetting *dto.BootSetting) { +func determineBootAction(bootSetting *dtov1.BootSetting) { if bootSetting.Action == 101 || bootSetting.Action == 200 || bootSetting.Action == 202 || bootSetting.Action == 301 || bootSetting.Action == 400 { bootSetting.Action = int(power.MasterBusReset) } else { diff --git a/internal/usecase/devices/power_private_test.go b/internal/usecase/devices/power_private_test.go index 106b1bd1..ad708e26 100644 --- a/internal/usecase/devices/power_private_test.go +++ b/internal/usecase/devices/power_private_test.go @@ -8,7 +8,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/software" "github.com/stretchr/testify/require" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type powerTest struct { @@ -18,7 +18,7 @@ type powerTest struct { amtVersion int capabilities boot.BootCapabilitiesResponse - bootSettings dto.BootSetting + bootSettings dtov1.BootSetting version []software.SoftwareIdentity } @@ -102,7 +102,7 @@ func TestDetermineIDERBootDevice(t *testing.T) { res: boot.BootSettingDataRequest{ IDERBootDevice: 1, }, - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 202, }, }, @@ -111,7 +111,7 @@ func TestDetermineIDERBootDevice(t *testing.T) { res: boot.BootSettingDataRequest{ IDERBootDevice: 0, }, - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 999, }, }, @@ -140,21 +140,21 @@ func TestGetBootSource(t *testing.T) { { name: "Action 400", res: string(cimBoot.PXE), - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 400, }, }, { name: "Action 202", res: string(cimBoot.CD), - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 202, }, }, { name: "Action 999", res: "", - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 999, }, }, @@ -179,14 +179,14 @@ func TestDetermineBootAction(t *testing.T) { { name: "Master Bus Reset", res: 10, - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 200, }, }, { name: "Power On", res: 2, - bootSettings: dto.BootSetting{ + bootSettings: dtov1.BootSetting{ Action: 999, }, }, diff --git a/internal/usecase/devices/power_test.go b/internal/usecase/devices/power_test.go index e8502e1d..8c945dab 100644 --- a/internal/usecase/devices/power_test.go +++ b/internal/usecase/devices/power_test.go @@ -14,7 +14,7 @@ import ( gomock "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -344,7 +344,7 @@ func TestSetBootOptions(t *testing.T) { TenantID: "tenant-id-456", } - bootSetting := dto.BootSetting{ + bootSetting := dtov1.BootSetting{ Action: 400, UseSOL: true, } diff --git a/internal/usecase/devices/redirection.go b/internal/usecase/devices/redirection.go index bb606091..f81fde4f 100644 --- a/internal/usecase/devices/redirection.go +++ b/internal/usecase/devices/redirection.go @@ -6,12 +6,12 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type Redirector struct{} -func (g *Redirector) SetupWsmanClient(device dto.Device, isRedirection, logAMTMessages bool) wsman.Messages { +func (g *Redirector) SetupWsmanClient(device dtov1.Device, isRedirection, logAMTMessages bool) wsman.Messages { clientParams := client.Parameters{ Target: device.Hostname, Username: device.Username, diff --git a/internal/usecase/devices/redirection_test.go b/internal/usecase/devices/redirection_test.go index 1bbaa2bd..bcc63cc5 100644 --- a/internal/usecase/devices/redirection_test.go +++ b/internal/usecase/devices/redirection_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" gomock "go.uber.org/mock/gomock" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" ) @@ -33,7 +33,7 @@ type redTest struct { func TestSetupWsmanClient(t *testing.T) { t.Parallel() - device := &dto.Device{ + device := &dtov1.Device{ GUID: "device-guid-123", TenantID: "tenant-id-456", } diff --git a/internal/usecase/devices/repo.go b/internal/usecase/devices/repo.go index ec7c8cac..508fe213 100644 --- a/internal/usecase/devices/repo.go +++ b/internal/usecase/devices/repo.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" ) @@ -28,14 +28,14 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Device, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Device, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) } // iterate over the data and convert each entity to dto - d1 := make([]dto.Device, len(data)) + d1 := make([]dtov1.Device, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -45,14 +45,14 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dto.Device, error) { +func (uc *UseCase) GetByColumn(ctx context.Context, columnName, queryValue, tenantID string) ([]dtov1.Device, error) { data, err := uc.repo.GetByColumn(ctx, columnName, queryValue, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByColumn", "uc.repo.GetByColumn", err) } // iterate over the data and convert each entity to dto - d1 := make([]dto.Device, len(data)) + d1 := make([]dtov1.Device, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -62,7 +62,7 @@ func (uc *UseCase) GetByColumn(ctx context.Context, columnName, queryValue, tena return d1, nil } -func (uc *UseCase) GetByID(ctx context.Context, guid, tenantID string) (*dto.Device, error) { +func (uc *UseCase) GetByID(ctx context.Context, guid, tenantID string) (*dtov1.Device, error) { data, err := uc.repo.GetByID(ctx, guid, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByID", "uc.repo.GetByID", err) @@ -94,7 +94,7 @@ func (uc *UseCase) GetDistinctTags(ctx context.Context, tenantID string) ([]stri return allTags, nil } -func (uc *UseCase) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dto.Device, error) { +func (uc *UseCase) GetByTags(ctx context.Context, tags, method string, limit, offset int, tenantID string) ([]dtov1.Device, error) { splitTags := strings.Split(tags, ",") data, err := uc.repo.GetByTags(ctx, splitTags, method, limit, offset, tenantID) @@ -103,7 +103,7 @@ func (uc *UseCase) GetByTags(ctx context.Context, tags, method string, limit, of } // iterate over the data and convert each entity to dto - d1 := make([]dto.Device, len(data)) + d1 := make([]dtov1.Device, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -126,7 +126,7 @@ func (uc *UseCase) Delete(ctx context.Context, guid, tenantID string) error { return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { d1 := uc.dtoToEntity(d) updated, err := uc.repo.Update(ctx, d1) @@ -151,7 +151,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.Device) (*dto.Device, erro return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.Device) (*dto.Device, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.Device) (*dtov1.Device, error) { d1 := uc.dtoToEntity(d) if d1.GUID == "" { diff --git a/internal/usecase/devices/repo_test.go b/internal/usecase/devices/repo_test.go index 9a4475d5..c1db2d42 100644 --- a/internal/usecase/devices/repo_test.go +++ b/internal/usecase/devices/repo_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -94,7 +94,7 @@ func TestGet(t *testing.T) { }, } - testDeviceDTOs := []dto.Device{ + testDeviceDTOs := []dtov1.Device{ { GUID: "guid-123", TenantID: "tenant-id-456", @@ -131,7 +131,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 5, 0, "tenant-id-456"). Return(nil, devices.ErrDatabase) }, - res: []dto.Device(nil), + res: []dtov1.Device(nil), err: devices.ErrDatabase, }, { @@ -144,7 +144,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 10, 20, "tenant-id-456"). Return([]entity.Device{}, nil) }, - res: []dto.Device{}, + res: []dtov1.Device{}, err: nil, }, } @@ -179,7 +179,7 @@ func TestGetByID(t *testing.T) { GUID: "device-guid-123", TenantID: "tenant-id-456", } - deviceDTO := &dto.Device{ + deviceDTO := &dtov1.Device{ GUID: "device-guid-123", TenantID: "tenant-id-456", Tags: nil, @@ -292,7 +292,7 @@ func TestUpdate(t *testing.T) { Tags: "hello,test", } - deviceDTO := &dto.Device{ + deviceDTO := &dtov1.Device{ GUID: "device-guid-123", TenantID: "tenant-id-456", Tags: []string{"hello", "test"}, @@ -321,7 +321,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), device). Return(false, nil) }, - res: (*dto.Device)(nil), + res: (*dtov1.Device)(nil), err: devices.ErrNotFound, }, { @@ -331,7 +331,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), device). Return(false, devices.ErrDatabase) }, - res: (*dto.Device)(nil), + res: (*dtov1.Device)(nil), err: devices.ErrDatabase, }, } @@ -387,7 +387,7 @@ func TestInsert(t *testing.T) { Insert(context.Background(), device). Return("", devices.ErrDatabase) }, - res: (*dto.Device)(nil), + res: (*dtov1.Device)(nil), err: devices.ErrDatabase, }, } @@ -401,7 +401,7 @@ func TestInsert(t *testing.T) { tc.mock(repo, management) - deviceDTO := &dto.Device{ + deviceDTO := &dtov1.Device{ GUID: "device-guid-123", TenantID: "tenant-id-456", Tags: []string{""}, diff --git a/internal/usecase/devices/usecase.go b/internal/usecase/devices/usecase.go index 2cc5fca2..9443aecb 100644 --- a/internal/usecase/devices/usecase.go +++ b/internal/usecase/devices/usecase.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -59,8 +59,8 @@ func New(r Repository, d WSMAN, redirection Redirection, log logger.Interface) * return uc } -// convert dto.Device to entity.Device. -func (uc *UseCase) dtoToEntity(d *dto.Device) *entity.Device { +// convert dtov1.Device to entity.Device. +func (uc *UseCase) dtoToEntity(d *dtov1.Device) *entity.Device { // convert []string to comma separated string if d.Tags == nil { d.Tags = []string{} @@ -97,15 +97,15 @@ func (uc *UseCase) dtoToEntity(d *dto.Device) *entity.Device { return d1 } -// convert entity.Device to dto.Device. -func (uc *UseCase) entityToDTO(d *entity.Device) *dto.Device { +// convert entity.Device to dtov1.Device. +func (uc *UseCase) entityToDTO(d *entity.Device) *dtov1.Device { // convert comma separated string to []string var tags []string if d.Tags != "" { tags = strings.Split(d.Tags, ",") } - d1 := &dto.Device{ + d1 := &dtov1.Device{ ConnectionStatus: d.ConnectionStatus, MPSInstance: d.MPSInstance, Hostname: d.Hostname, diff --git a/internal/usecase/devices/wsman/interfaces.go b/internal/usecase/devices/wsman/interfaces.go index 46489dda..6baa80e1 100644 --- a/internal/usecase/devices/wsman/interfaces.go +++ b/internal/usecase/devices/wsman/interfaces.go @@ -19,14 +19,14 @@ import ( ipsAlarmClock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/alarmclock" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/optin" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type Management interface { GetAMTVersion() ([]software.SoftwareIdentity, error) GetSetupAndConfiguration() ([]setupandconfiguration.SetupAndConfigurationServiceResponse, error) - GetFeatures() (dto.Features, error) - SetFeatures(dto.Features) (dto.Features, error) + GetFeatures() (dtov1.Features, error) + SetFeatures(dtov1.Features) (dtov1.Features, error) GetAlarmOccurrences() ([]ipsAlarmClock.AlarmClockOccurrence, error) CreateAlarmOccurrences(name string, startTime time.Time, interval int, deleteOnCompletion bool) (alarmclock.AddAlarmOutput, error) DeleteAlarmOccurrences(instanceID string) error diff --git a/internal/usecase/devices/wsman/message.go b/internal/usecase/devices/wsman/message.go index 8b744e7d..d16976d2 100644 --- a/internal/usecase/devices/wsman/message.go +++ b/internal/usecase/devices/wsman/message.go @@ -53,7 +53,7 @@ import ( 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/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -85,7 +85,7 @@ func NewGoWSMANMessages(log logger.Interface) *GoWSMANMessages { } } -func (g GoWSMANMessages) DestroyWsmanClient(device dto.Device) { +func (g GoWSMANMessages) DestroyWsmanClient(device dtov1.Device) { if entry, ok := connections[device.GUID]; ok { entry.Timer.Stop() removeConnection(device.GUID) @@ -104,7 +104,7 @@ func (g GoWSMANMessages) Worker() { } } -func (g GoWSMANMessages) SetupWsmanClient(device dto.Device, isRedirection, logAMTMessages bool) Management { +func (g GoWSMANMessages) SetupWsmanClient(device dtov1.Device, isRedirection, logAMTMessages bool) Management { resultChan := make(chan *ConnectionEntry) // Queue the request @@ -115,7 +115,7 @@ func (g GoWSMANMessages) SetupWsmanClient(device dto.Device, isRedirection, logA return <-resultChan } -func (g GoWSMANMessages) setupWsmanClientInternal(device dto.Device, isRedirection, logAMTMessages bool) *ConnectionEntry { +func (g GoWSMANMessages) setupWsmanClientInternal(device dtov1.Device, isRedirection, logAMTMessages bool) *ConnectionEntry { clientParams := client.Parameters{ Target: device.Hostname, Username: device.Username, @@ -228,23 +228,23 @@ var UserConsentOptions = map[int]string{ 4294967295: "all", } -func (g *ConnectionEntry) GetFeatures() (dto.Features, error) { +func (g *ConnectionEntry) GetFeatures() (dtov1.Features, error) { redirectionResult, err := g.WsmanMessages.AMT.RedirectionService.Get() if err != nil { - return dto.Features{}, err + return dtov1.Features{}, err } optServiceResult, err := g.WsmanMessages.IPS.OptInService.Get() if err != nil { - return dto.Features{}, err + return dtov1.Features{}, err } kvmResult, err := g.WsmanMessages.CIM.KVMRedirectionSAP.Get() if err != nil { - return dto.Features{}, err + return dtov1.Features{}, err } - settingsResults := dto.Features{ + settingsResults := dtov1.Features{ UserConsent: UserConsentOptions[int(optServiceResult.Body.GetAndPutResponse.OptInRequired)], EnableSOL: (redirectionResult.Body.GetAndPutResponse.EnabledState & redirection.Enabled) != 0, EnableIDER: (redirectionResult.Body.GetAndPutResponse.EnabledState & redirection.Enabled) != 0, @@ -256,7 +256,7 @@ func (g *ConnectionEntry) GetFeatures() (dto.Features, error) { return settingsResults, nil } -func (g *ConnectionEntry) SetFeatures(features dto.Features) (dto.Features, error) { +func (g *ConnectionEntry) SetFeatures(features dtov1.Features) (dtov1.Features, error) { // redirection requestedState, listenerEnabled, err := configureRedirection(features, g) if err != nil { @@ -315,7 +315,7 @@ func (g *ConnectionEntry) SetFeatures(features dto.Features) (dto.Features, erro return features, nil } -func configureKVM(features dto.Features, listenerEnabled int, g *ConnectionEntry) (int, error) { +func configureKVM(features dtov1.Features, listenerEnabled int, g *ConnectionEntry) (int, error) { kvmRequestedState := kvm.RedirectionSAPDisable if features.EnableKVM { kvmRequestedState = kvm.RedirectionSAPEnable @@ -330,7 +330,7 @@ func configureKVM(features dto.Features, listenerEnabled int, g *ConnectionEntry return listenerEnabled, nil } -func configureRedirection(features dto.Features, g *ConnectionEntry) (redirection.RequestedState, int, error) { +func configureRedirection(features dtov1.Features, g *ConnectionEntry) (redirection.RequestedState, int, error) { requestedState := redirection.DisableIDERAndSOL listenerEnabled := 0 diff --git a/internal/usecase/devices/wsman_mocks_test.go b/internal/usecase/devices/wsman_mocks_test.go index c05fa523..96ac3019 100644 --- a/internal/usecase/devices/wsman_mocks_test.go +++ b/internal/usecase/devices/wsman_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" time "time" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" wsman "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" alarmclock "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/alarmclock" auditlog "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/auditlog" @@ -266,10 +266,10 @@ func (mr *MockManagementMockRecorder) GetEventLog() *gomock.Call { } // GetFeatures mocks base method. -func (m *MockManagement) GetFeatures() (dto.Features, error) { +func (m *MockManagement) GetFeatures() (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFeatures") - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -461,10 +461,10 @@ func (mr *MockManagementMockRecorder) SetBootData(data any) *gomock.Call { } // SetFeatures mocks base method. -func (m *MockManagement) SetFeatures(arg0 dto.Features) (dto.Features, error) { +func (m *MockManagement) SetFeatures(arg0 dtov1.Features) (dtov1.Features, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SetFeatures", arg0) - ret0, _ := ret[0].(dto.Features) + ret0, _ := ret[0].(dtov1.Features) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/domains/interfaces.go b/internal/usecase/domains/interfaces.go index 522cd323..34065494 100644 --- a/internal/usecase/domains/interfaces.go +++ b/internal/usecase/domains/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -19,11 +19,11 @@ type ( } Feature interface { GetCount(context.Context, string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Domain, error) - GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dto.Domain, error) - GetByName(ctx context.Context, name, tenantID string) (*dto.Domain, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Domain, error) + GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dtov1.Domain, error) + GetByName(ctx context.Context, name, tenantID string) (*dtov1.Domain, error) Delete(ctx context.Context, name, tenantID string) error - Update(ctx context.Context, d *dto.Domain) (*dto.Domain, error) - Insert(ctx context.Context, d *dto.Domain) (*dto.Domain, error) + Update(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) + Insert(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) } ) diff --git a/internal/usecase/domains/mocks_test.go b/internal/usecase/domains/mocks_test.go index a2d47e30..90571003 100644 --- a/internal/usecase/domains/mocks_test.go +++ b/internal/usecase/domains/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -184,10 +184,10 @@ func (mr *MockFeatureMockRecorder) Delete(ctx, name, tenantID any) *gomock.Call } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Domain, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Domain) + ret0, _ := ret[0].([]dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -199,10 +199,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetByName mocks base method. -func (m *MockFeature) GetByName(ctx context.Context, name, tenantID string) (*dto.Domain, error) { +func (m *MockFeature) GetByName(ctx context.Context, name, tenantID string) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, name, tenantID) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockFeatureMockRecorder) GetCount(arg0, arg1 any) *gomock.Call { } // GetDomainByDomainSuffix mocks base method. -func (m *MockFeature) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dto.Domain, error) { +func (m *MockFeature) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetDomainByDomainSuffix", ctx, domainSuffix, tenantID) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockFeatureMockRecorder) GetDomainByDomainSuffix(ctx, domainSuffix, te } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (m *MockFeature) Insert(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, d) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockFeatureMockRecorder) Insert(ctx, d any) *gomock.Call { } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (m *MockFeature) Update(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, d) - ret0, _ := ret[0].(*dto.Domain) + ret0, _ := ret[0].(*dtov1.Domain) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/domains/usecase.go b/internal/usecase/domains/usecase.go index 3973a4c1..0a7c55b8 100644 --- a/internal/usecase/domains/usecase.go +++ b/internal/usecase/domains/usecase.go @@ -9,7 +9,7 @@ import ( "software.sslmate.com/src/go-pkcs12" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -47,14 +47,14 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Domain, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Domain, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) } // iterate over the data and convert each entity to dto - d1 := make([]dto.Domain, len(data)) + d1 := make([]dtov1.Domain, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -64,7 +64,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dto.Domain, error) { +func (uc *UseCase) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, tenantID string) (*dtov1.Domain, error) { data, err := uc.repo.GetDomainByDomainSuffix(ctx, domainSuffix, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetDomainByDomainSuffix", "uc.repo.GetDomainByDomainSuffix", err) @@ -79,7 +79,7 @@ func (uc *UseCase) GetDomainByDomainSuffix(ctx context.Context, domainSuffix, te return d2, nil } -func (uc *UseCase) GetByName(ctx context.Context, domainName, tenantID string) (*dto.Domain, error) { +func (uc *UseCase) GetByName(ctx context.Context, domainName, tenantID string) (*dtov1.Domain, error) { data, err := uc.repo.GetByName(ctx, domainName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByName", "uc.repo.GetByName", err) @@ -107,7 +107,7 @@ func (uc *UseCase) Delete(ctx context.Context, domainName, tenantID string) erro return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { d1 := uc.dtoToEntity(d) updated, err := uc.repo.Update(ctx, d1) @@ -129,7 +129,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.Domain) (*dto.Domain, erro return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.Domain) (*dto.Domain, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.Domain) (*dtov1.Domain, error) { d1 := uc.dtoToEntity(d) cert, err := DecryptAndCheckCertExpiration(*d) @@ -154,7 +154,7 @@ func (uc *UseCase) Insert(ctx context.Context, d *dto.Domain) (*dto.Domain, erro return d2, nil } -func DecryptAndCheckCertExpiration(domain dto.Domain) (*x509.Certificate, error) { +func DecryptAndCheckCertExpiration(domain dtov1.Domain) (*x509.Certificate, error) { // Decode the base64 encoded PFX certificate pfxData, err := base64.StdEncoding.DecodeString(domain.ProvisioningCert) if err != nil { @@ -175,8 +175,8 @@ func DecryptAndCheckCertExpiration(domain dto.Domain) (*x509.Certificate, error) return cert, nil } -// convert dto.Domain to entity.Domain. -func (uc *UseCase) dtoToEntity(d *dto.Domain) *entity.Domain { +// convert dtov1.Domain to entity.Domain. +func (uc *UseCase) dtoToEntity(d *dtov1.Domain) *entity.Domain { d1 := &entity.Domain{ ProfileName: d.ProfileName, DomainSuffix: d.DomainSuffix, @@ -190,8 +190,8 @@ func (uc *UseCase) dtoToEntity(d *dto.Domain) *entity.Domain { return d1 } -// convert entity.Domain to dto.Domain. -func (uc *UseCase) entityToDTO(d *entity.Domain) *dto.Domain { +// convert entity.Domain to dtov1.Domain. +func (uc *UseCase) entityToDTO(d *entity.Domain) *dtov1.Domain { // parse expiration date var expirationDate time.Time @@ -204,7 +204,7 @@ func (uc *UseCase) entityToDTO(d *entity.Domain) *dto.Domain { } } - d1 := &dto.Domain{ + d1 := &dtov1.Domain{ ProfileName: d.ProfileName, DomainSuffix: d.DomainSuffix, ProvisioningCert: d.ProvisioningCert, diff --git a/internal/usecase/domains/usecase_test.go b/internal/usecase/domains/usecase_test.go index 7ca1a541..b1d7d8ad 100644 --- a/internal/usecase/domains/usecase_test.go +++ b/internal/usecase/domains/usecase_test.go @@ -10,7 +10,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/domains" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -95,7 +95,7 @@ func TestGet(t *testing.T) { }, } - testDomainDTOs := []dto.Domain{ + testDomainDTOs := []dtov1.Domain{ { ProfileName: "test-domain-1", TenantID: "tenant-id-456", @@ -130,7 +130,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 5, 0, "tenant-id-456"). Return(nil, domains.ErrDatabase) }, - res: []dto.Domain(nil), + res: []dtov1.Domain(nil), err: domains.ErrDatabase, }, { @@ -143,7 +143,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 10, 20, "tenant-id-456"). Return([]entity.Domain{}, nil) }, - res: []dto.Domain{}, + res: []dtov1.Domain{}, err: nil, }, } @@ -184,7 +184,7 @@ func TestGetDomainByDomainSuffix(t *testing.T) { Version: "1.0.0", } - domainDTO := dto.Domain{ + domainDTO := dtov1.Domain{ ProfileName: "test-domain", DomainSuffix: "test.com", ProvisioningCert: "test-cert", @@ -262,7 +262,7 @@ func TestGetByName(t *testing.T) { Version: "1.0.0", } - domainDTO := &dto.Domain{ + domainDTO := &dtov1.Domain{ ProfileName: "test-domain", DomainSuffix: "test-domain", ProvisioningCert: "test-cert", @@ -298,7 +298,7 @@ func TestGetByName(t *testing.T) { GetByName(context.Background(), "unknown-domain", "tenant-id-456"). Return(nil, nil) }, - res: (*dto.Domain)(nil), + res: (*dtov1.Domain)(nil), err: domains.ErrNotFound, }, } @@ -382,7 +382,7 @@ func TestUpdate(t *testing.T) { TenantID: "tenant-id-456", Version: "1.0.0", } - domainDTO := &dto.Domain{ + domainDTO := &dtov1.Domain{ ProfileName: "example-domain", TenantID: "tenant-id-456", Version: "1.0.0", @@ -409,7 +409,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), domain). Return(false, nil) }, - res: (*dto.Domain)(nil), + res: (*dtov1.Domain)(nil), err: domains.ErrNotFound, }, { @@ -419,7 +419,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), domain). Return(false, domains.ErrDatabase) }, - res: (*dto.Domain)(nil), + res: (*dtov1.Domain)(nil), err: domains.ErrDatabase, }, } @@ -454,7 +454,7 @@ func TestInsert(t *testing.T) { ExpirationDate: "2033-08-01T07:12:09Z", Version: "1.0.0", } - domainDTO := &dto.Domain{ + domainDTO := &dtov1.Domain{ ProfileName: "new-domain", DomainSuffix: "newdomain.com", ProvisioningCert: generateTestPFX(), @@ -486,7 +486,7 @@ func TestInsert(t *testing.T) { Insert(context.Background(), domain). Return("", domains.ErrDatabase) }, - res: (*dto.Domain)(nil), + res: (*dtov1.Domain)(nil), err: domains.ErrDatabase, }, } @@ -520,7 +520,7 @@ func generateTestPFX() string { func TestDecryptAndCheckCertExpiration_Valid(t *testing.T) { t.Parallel() - domain := dto.Domain{ + domain := dtov1.Domain{ ProvisioningCert: generateTestPFX(), ProvisioningCertPassword: "P@ssw0rd", } @@ -536,7 +536,7 @@ func TestDecryptAndCheckCertExpiration_Valid(t *testing.T) { func TestDecryptAndCheckCertExpiration_Expired(t *testing.T) { t.Parallel() - domain := dto.Domain{ + domain := dtov1.Domain{ ProvisioningCert: "MIIKZgIBAzCCChwGCSqGSIb3DQEHAaCCCg0EggoJMIIKBTCCBEIGCSqGSIb3DQEHBqCCBDMwggQvAgEAMIIEKAYJKoZIhvcNAQcBMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAhNTymhoYvsogICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEECAXbKnPXTmh3X1t591zFD6AggPAFD2u3VIDcGn+HwsUfgsr/T+klbaBYoMJlNGWWn8Os/cKn7OMDstd5zmf8Z0n+AUwCQqMVEqzwX/rksDPxlOu5RhRxVsE5iViXOsyvHPLh+s+6tZguZfgiVKDJYlROOSJcrV3rmS28swOg6blTsn2RUCYSoCz62a02/SLedA+e30fp2ew+nRMKArtUJeG8NXZMbOJ2uS7IvPsJ3OWVb+2eow7K02FR4GQebx0+HpcWWdy5iYlGBn/r4XE5SqyTsP4TzeqrvlSCkwy4mntQEM73MeUJhioCDdG0ZWGZ5isC4AjENTCxUXaVgOYC40e+0vkeKSSOC1TCBJwvlvUm9AXN84a6nXbEyymIrAeuESCxZnFI2E2LWhxON3PzJsbsrQVIKxkjRm2dYSWWiODHo2s0XAb7r13te5deFOOXmDKEnhsy3k3iCsc9Xanmiz9qT9ibw+M/5WLpjnKeCCc48yRRzvfMPK7R0FUMyjwfFBJLzRw+SgdxxCkMtzHxx4bjxBArnnT20stRMimQOHUfL6dOXM9pKV2RrwkjnoZSBcCYsRR9x228JvyZyx1cmRyRDa8/C3KZzWBo4F9tT34yNbw647R1Ij2PJ763F93Cxg3Z/DK0BVVk9ucuKd48iIqUwdQhJ6T+acUrf0DzDdXJZM4XlmTRxHOPyFgiYxTlsRcQKGDIU533yv2LfVoVRclmflgxxPlf1y3JllqnKdyzIdmDyEBCklQhyLmVek+lPd5+KmDggx1cj99qGmiiMMVrtk08Ijouz0ld3mVWKOeZSeLl40HS/N4XhMPDT/AjPRay1bFe2VdswYnB0RDQWT2OgHp5QtdKzKoqYqbN8345oj3pER2FlcBBRMPRHdtOgPyZr0zgIuDU6VYhyAOvbLz8NPU2VxVxEMcLCp0YQHdGbl84Vy9aDoF9WzNkY5wcb45mlZxUWOqGRX9JSqROlzQh5Kt7FEYDKTh68pPZW73PyeLqEOFztqVQWzrrFuHCHAwFEfYK5NDbgnL3jLSNALOffAH2EFQZPX62Mq8JOAyfO2+OsYJETdn/5lqnt2Evhhco1F32WpaxPYlrL3ChtuqaD2G02Ei41U2SMKKBCKwkceB+MVusvguxnW5/0nT+6hRcYeNXfcEVgpykrc4XFXC6W07ufQ9LQULO/aQphwYbN7CS1I3xWLDqkxm/WfQApz0eWzpw4rlgQe3MD84pgyeIi9URBFFtbZFp2k5U7E2WEyCniCWU49XmgGl1F2K3KlC0hDQFZx087SfeabwGmWlhZQ7MIIFuwYJKoZIhvcNAQcBoIIFrASCBagwggWkMIIFoAYLKoZIhvcNAQwKAQKgggUxMIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQImEq+qLMGK9YCAggAMAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBDEpG9s6BqwtYVhd+ZZV2nWBIIE0IiMJjsqVcQZWCMRMIXDBnfKn4ZCManS7Hj7CS6sjzq7AwA6A24DS1lr3UrghypDoKcadPdLg8FaIFxM+Rg0LZyzG+1Q75r/dwnkFDAbDsgtBVtnYfLBnvbYkwzhsx5HY/G6JcbJBYkKa7L0UZnDmaAsvh7P1oVH00+uA307m7pgKmw2Qf+pntUorto1gk9bP20U9WK6CzXZKy0AKhhSvfdPlK+a+1H8ESN7lC+mdnhZ2XdNR2lp4E9NZPWS11Rpn1/8YWCa14bm1xPKKDi6EuGaPQlnBS0L9XyjJ0JrcBJydojGd/MtAUwAxBhkyJV/C4PRsx77e120lW0xl/U7V/7Rgk5iZ4gwIoCX3VYblyV6k4Ceo0LgUz4LldG9o5Q8CkL6h8uiUMekC2xJfJ4Iim7fv7AIQsZPeI0/Zhly0C0Ii+bMgfEB1xVLtv9FR7tmFDsuWjna+6DCFzpc2n5Ymd+SfZ7p7mUbJrkoBYSbhE52jLZL8L69P8bjyBd4Ai5VyZFj4oHEVEzfgmkRDhidOqPCxZEZs++QsUzFKc90BCuuWJoMPQgZo6VRvq3lrGZvHb6p7gzm034v0+Oj04bSXOoVQB63/WkkB/GTDn1AC8sfYW5IJWN1w4yOiWqYVje65CaiaMQjkeoAcgEgYG09Y2tkHgIMYKK2Oz8NVRkaXV0wAIuxg3ZC2MNkywzMU1OPSEHLhvSDZSTS+1xKZNiF0ScCt0rm6fUTtBZgdMjOquD8WWXmBuBXBKdwEIoEJyudbfzLYf8besWg3WtUoyu+8LQstEPKaPWgW1fi6WjegoGM19KZGSkce299+0zL/1atAkdB0DK5SfEgY2kFAXszf6VRE0WZOE78Keemao8T4Dj1PuEpZ22Etitkoq4H0PpdUxAG0KDlWggro3dMIMks+m2yKpXTzMaNNlzVS2AbcIVYCp/S+8rf2yOppR1znzkZKDp4hAZeAwWy/s4mG4AgDiPBllEFsni4XVqQstRaCEuY/Q7Cfi2v/6r98/M8qI5fFqiZkmVhuT/dWZ09GMvP3UnEUguFHjAG5SpUOMzKbNz7R2hY44XyEE2tkLnMJSXeBuKvR5VVi2fV3hpOADWNAUz8lQqokgUcz3H+xJcu6BnROq50GxCsIJcMnntJFKEv+yE5Nz/sZQrXw+ujBGWp9g2oHLqopZO1/ewYnYn4LAXsW8DPNNJe0LjynXZrEj8H6/Q6E0xtv/8CtIfRqgqHmBfztemzr8XKpz7fCTscBFw8ve/MuxmWv6Ew53daDJuCf8IJU2dYpR0CjW3Cjso/n133aid2SVwhgMX3j9Ue40xZ+os/X4jxyv68tn4dSDZXLOaWKrJ2gArI1HwrDMJy+6tHZxAsiVnvDZXfTC09eczYEVzkX3oE9TuMAeCharxKAKa/JBYgNBB4kd75yQYqsBNRhyt1JqWeah3Og2/Dz63lUfrdpkjejHF0lSLmCz18zTy03ZUbdBOOAIrtX70RB8QGNUJbIt1+zTZ7mxl052dun7AIGx0UPI9FZl+WxwXp7/OaDipqSA+PUpfg6kvscdy+BmHwqO8MIvVo57ICc+ni+6Lf3SkY+GNNxi51r7yRUFfXcQMM4EdUzEnacXHpICpc+jnIV6m6Bs1Q446exWZJMVwwIwYJKoZIhvcNAQkVMRYEFDFxVf35fNFoJoAUxzCsoeFoINarMDUGCSqGSIb3DQEJFDEoHiYARQB4AHAAaQByAGUAZAAgAEMAZQByAHQAaQBmAGkAYwBhAHQAZTBBMDEwDQYJYIZIAWUDBAIBBQAEIKBhnzb5iEOhPofkJL/It6yWSR7N9jflrG4bEWUvOUSTBAh6AoVjZAFrzQICCAA=", ProvisioningCertPassword: "", } @@ -553,7 +553,7 @@ func TestDecryptAndCheckCertExpiration_Expired(t *testing.T) { func TestDecryptAndCheckCertExpiration_IncorrectPassword(t *testing.T) { t.Parallel() - domain := dto.Domain{ + domain := dtov1.Domain{ ProvisioningCert: generateTestPFX(), ProvisioningCertPassword: "WrongP@ssw0rd", } diff --git a/internal/usecase/ieee8021xconfigs/interfaces.go b/internal/usecase/ieee8021xconfigs/interfaces.go index 5cb6f1b1..c3e70f04 100644 --- a/internal/usecase/ieee8021xconfigs/interfaces.go +++ b/internal/usecase/ieee8021xconfigs/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -21,10 +21,10 @@ type ( Feature interface { CheckProfileExists(ctx context.Context, profileName, tenantID string) (bool, error) GetCount(ctx context.Context, tenantID string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.IEEE8021xConfig, error) - GetByName(ctx context.Context, profileName, tenantID string) (*dto.IEEE8021xConfig, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.IEEE8021xConfig, error) + GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.IEEE8021xConfig, error) Delete(ctx context.Context, profileName, tenantID string) error - Update(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) - Insert(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) + Update(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) + Insert(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) } ) diff --git a/internal/usecase/ieee8021xconfigs/mocks_test.go b/internal/usecase/ieee8021xconfigs/mocks_test.go index ce7edd2d..4074c359 100644 --- a/internal/usecase/ieee8021xconfigs/mocks_test.go +++ b/internal/usecase/ieee8021xconfigs/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockFeatureMockRecorder) Delete(ctx, profileName, tenantID any) *gomoc } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.IEEE8021xConfig, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.IEEE8021xConfig) + ret0, _ := ret[0].([]dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetByName mocks base method. -func (m *MockFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dto.IEEE8021xConfig, error) { +func (m *MockFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, profileName, tenantID) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockFeature) Insert(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockFeature) Update(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/ieee8021xconfigs/usecase.go b/internal/usecase/ieee8021xconfigs/usecase.go index d7fc2f96..bb306602 100644 --- a/internal/usecase/ieee8021xconfigs/usecase.go +++ b/internal/usecase/ieee8021xconfigs/usecase.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -49,7 +49,7 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.IEEE8021xConfig, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.IEEE8021xConfig, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) @@ -60,7 +60,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d } // iterate over the data and convert each entity to dto - d1 := make([]dto.IEEE8021xConfig, len(data)) + d1 := make([]dtov1.IEEE8021xConfig, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -70,7 +70,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dto.IEEE8021xConfig, error) { +func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.IEEE8021xConfig, error) { data, err := uc.repo.GetByName(ctx, profileName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByName", "uc.repo.GetByName", err) @@ -98,7 +98,7 @@ func (uc *UseCase) Delete(ctx context.Context, profileName, tenantID string) err return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { d1 := uc.dtoToEntity(d) updated, err := uc.repo.Update(ctx, d1) @@ -120,7 +120,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.IEEE8021xConfig) (*dto.IEE return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { d1 := uc.dtoToEntity(d) _, err := uc.repo.Insert(ctx, d1) @@ -138,8 +138,8 @@ func (uc *UseCase) Insert(ctx context.Context, d *dto.IEEE8021xConfig) (*dto.IEE return d2, nil } -// convert dto.Domain to entity.Domain. -func (uc *UseCase) dtoToEntity(d *dto.IEEE8021xConfig) *entity.IEEE8021xConfig { +// convert dtov1.Domain to entity.Domain. +func (uc *UseCase) dtoToEntity(d *dtov1.IEEE8021xConfig) *entity.IEEE8021xConfig { d1 := &entity.IEEE8021xConfig{ ProfileName: d.ProfileName, AuthenticationProtocol: d.AuthenticationProtocol, @@ -152,9 +152,9 @@ func (uc *UseCase) dtoToEntity(d *dto.IEEE8021xConfig) *entity.IEEE8021xConfig { return d1 } -// convert entity.Domain to dto.Domain. -func (uc *UseCase) entityToDTO(d *entity.IEEE8021xConfig) *dto.IEEE8021xConfig { - d1 := &dto.IEEE8021xConfig{ +// convert entity.Domain to dtov1.Domain. +func (uc *UseCase) entityToDTO(d *entity.IEEE8021xConfig) *dtov1.IEEE8021xConfig { + d1 := &dtov1.IEEE8021xConfig{ ProfileName: d.ProfileName, AuthenticationProtocol: d.AuthenticationProtocol, PXETimeout: d.PXETimeout, diff --git a/internal/usecase/ieee8021xconfigs/usecase_test.go b/internal/usecase/ieee8021xconfigs/usecase_test.go index 6b6aab1b..d75d8124 100644 --- a/internal/usecase/ieee8021xconfigs/usecase_test.go +++ b/internal/usecase/ieee8021xconfigs/usecase_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ieee8021xconfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -136,7 +136,7 @@ func TestGet(t *testing.T) { }, } - IEEE8021xConfigDTOs := []dto.IEEE8021xConfig{ + IEEE8021xConfigDTOs := []dtov1.IEEE8021xConfig{ { ProfileName: "test-IEEE8021xConfig-1", TenantID: "tenant-id-456", @@ -171,7 +171,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 5, 0, "tenant-id-456"). Return(nil, ieee8021xconfigs.ErrDatabase) }, - res: []dto.IEEE8021xConfig(nil), + res: []dtov1.IEEE8021xConfig(nil), err: ieee8021xconfigs.ErrDatabase, }, { @@ -184,7 +184,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 10, 20, "tenant-id-456"). Return([]entity.IEEE8021xConfig{}, nil) }, - res: []dto.IEEE8021xConfig{}, + res: []dtov1.IEEE8021xConfig{}, err: nil, }, } @@ -220,7 +220,7 @@ func TestGetByName(t *testing.T) { Version: "1.0.0", } - ieee8021xconfigDTO := &dto.IEEE8021xConfig{ + ieee8021xconfigDTO := &dtov1.IEEE8021xConfig{ ProfileName: "test-profile", TenantID: "tenant-id-456", Version: "1.0.0", @@ -252,7 +252,7 @@ func TestGetByName(t *testing.T) { GetByName(context.Background(), "unknown-ieee8021xconfig", "tenant-id-456"). Return(nil, nil) }, - res: (*dto.IEEE8021xConfig)(nil), + res: (*dtov1.IEEE8021xConfig)(nil), err: ieee8021xconfigs.ErrNotFound, }, } @@ -335,7 +335,7 @@ func TestUpdate(t *testing.T) { Version: "1.0.0", } - ieee8021xconfigDTO := &dto.IEEE8021xConfig{ + ieee8021xconfigDTO := &dtov1.IEEE8021xConfig{ ProfileName: "example-ieee8021xconfig", TenantID: "tenant-id-456", Version: "1.0.0", @@ -362,7 +362,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), ieee8021xconfig). Return(false, ieee8021xconfigs.ErrNotFound) }, - res: (*dto.IEEE8021xConfig)(nil), + res: (*dtov1.IEEE8021xConfig)(nil), err: ieee8021xconfigs.ErrDatabase, }, { @@ -372,7 +372,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), ieee8021xconfig). Return(false, ieee8021xconfigs.ErrDatabase) }, - res: (*dto.IEEE8021xConfig)(nil), + res: (*dtov1.IEEE8021xConfig)(nil), err: ieee8021xconfigs.ErrDatabase, }, } @@ -402,7 +402,7 @@ func TestInsert(t *testing.T) { Version: "1.0.0", } - ieee8021xconfigDTO := &dto.IEEE8021xConfig{ + ieee8021xconfigDTO := &dtov1.IEEE8021xConfig{ ProfileName: "new-ieee8021xconfig", TenantID: "tenant-id-789", Version: "1.0.0", @@ -429,7 +429,7 @@ func TestInsert(t *testing.T) { Insert(context.Background(), ieee8021xconfig). Return("", ieee8021xconfigs.ErrDatabase) }, - res: (*dto.IEEE8021xConfig)(nil), + res: (*dtov1.IEEE8021xConfig)(nil), err: ieee8021xconfigs.ErrDatabase, }, } diff --git a/internal/usecase/profiles/ieee_mocks_test.go b/internal/usecase/profiles/ieee_mocks_test.go index 9e83b45c..a08ebb43 100644 --- a/internal/usecase/profiles/ieee_mocks_test.go +++ b/internal/usecase/profiles/ieee_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockIEEEFeatureMockRecorder) Delete(ctx, profileName, tenantID any) *g } // Get mocks base method. -func (m *MockIEEEFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.IEEE8021xConfig, error) { +func (m *MockIEEEFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.IEEE8021xConfig) + ret0, _ := ret[0].([]dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockIEEEFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock } // GetByName mocks base method. -func (m *MockIEEEFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEEFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, profileName, tenantID) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockIEEEFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.Call } // Insert mocks base method. -func (m *MockIEEEFeature) Insert(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEEFeature) Insert(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockIEEEFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockIEEEFeature) Update(ctx context.Context, p *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { +func (m *MockIEEEFeature) Update(ctx context.Context, p *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.IEEE8021xConfig) + ret0, _ := ret[0].(*dtov1.IEEE8021xConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/profiles/interfaces.go b/internal/usecase/profiles/interfaces.go index bbb8a0a2..5794ade7 100644 --- a/internal/usecase/profiles/interfaces.go +++ b/internal/usecase/profiles/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -19,10 +19,10 @@ type ( Feature interface { GetCount(ctx context.Context, tenantID string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Profile, error) - GetByName(ctx context.Context, profileName, tenantID string) (*dto.Profile, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Profile, error) + GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.Profile, error) Delete(ctx context.Context, profileName, tenantID string) error - Update(ctx context.Context, p *dto.Profile) (*dto.Profile, error) - Insert(ctx context.Context, p *dto.Profile) (*dto.Profile, error) + Update(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) + Insert(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) } ) diff --git a/internal/usecase/profiles/mocks_test.go b/internal/usecase/profiles/mocks_test.go index 8c49d634..fb2f4927 100644 --- a/internal/usecase/profiles/mocks_test.go +++ b/internal/usecase/profiles/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -169,10 +169,10 @@ func (mr *MockFeatureMockRecorder) Delete(ctx, profileName, tenantID any) *gomoc } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Profile, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.Profile) + ret0, _ := ret[0].([]dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -184,10 +184,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetByName mocks base method. -func (m *MockFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dto.Profile, error) { +func (m *MockFeature) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, profileName, tenantID) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, p *dto.Profile) (*dto.Profile, error) { +func (m *MockFeature) Insert(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -229,10 +229,10 @@ func (mr *MockFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, p *dto.Profile) (*dto.Profile, error) { +func (m *MockFeature) Update(ctx context.Context, p *dtov1.Profile) (*dtov1.Profile, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.Profile) + ret0, _ := ret[0].(*dtov1.Profile) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/profiles/profileswificonfigs_mocks_test.go b/internal/usecase/profiles/profileswificonfigs_mocks_test.go index 6011d725..7fa30556 100644 --- a/internal/usecase/profiles/profileswificonfigs_mocks_test.go +++ b/internal/usecase/profiles/profileswificonfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -124,10 +124,10 @@ func (mr *MockProfileWiFiConfigsFeatureMockRecorder) DeleteByProfileName(ctx, pr } // GetByProfileName mocks base method. -func (m *MockProfileWiFiConfigsFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dto.ProfileWiFiConfigs, error) { +func (m *MockProfileWiFiConfigsFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dtov1.ProfileWiFiConfigs, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByProfileName", ctx, profileName, tenantID) - ret0, _ := ret[0].([]dto.ProfileWiFiConfigs) + ret0, _ := ret[0].([]dtov1.ProfileWiFiConfigs) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -139,7 +139,7 @@ func (mr *MockProfileWiFiConfigsFeatureMockRecorder) GetByProfileName(ctx, profi } // Insert mocks base method. -func (m *MockProfileWiFiConfigsFeature) Insert(ctx context.Context, p *dto.ProfileWiFiConfigs) error { +func (m *MockProfileWiFiConfigsFeature) Insert(ctx context.Context, p *dtov1.ProfileWiFiConfigs) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) ret0, _ := ret[0].(error) diff --git a/internal/usecase/profiles/usecase.go b/internal/usecase/profiles/usecase.go index 4daf9c3e..f1ac6524 100644 --- a/internal/usecase/profiles/usecase.go +++ b/internal/usecase/profiles/usecase.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ieee8021xconfigs" "github.com/open-amt-cloud-toolkit/console/internal/usecase/profilewificonfigs" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" @@ -28,7 +28,7 @@ var ( ErrProfilesUseCase = consoleerrors.CreateConsoleError("ProfilesUseCase") ErrDatabase = sqldb.DatabaseError{Console: consoleerrors.CreateConsoleError("ProfilesUseCase")} ErrNotFound = sqldb.NotFoundError{Console: consoleerrors.CreateConsoleError("ProfilesUseCase")} - ErrNotValid = dto.NotValidError{Console: consoleerrors.CreateConsoleError("ProfilesUseCase")} + ErrNotValid = dtov1.NotValidError{Console: consoleerrors.CreateConsoleError("ProfilesUseCase")} ) // New -. @@ -52,7 +52,7 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.Profile, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.Profile, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) @@ -63,7 +63,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d } // iterate over the data and convert each entity to dto - d1 := make([]dto.Profile, len(data)) + d1 := make([]dtov1.Profile, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -78,7 +78,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dto.Profile, error) { +func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.Profile, error) { data, err := uc.repo.GetByName(ctx, profileName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByName", "uc.repo.GetByName", err) @@ -118,7 +118,7 @@ func (uc *UseCase) Delete(ctx context.Context, profileName, tenantID string) err return nil } -func (uc *UseCase) isWifiProfileExists(ctx context.Context, d *dto.Profile, action string) error { +func (uc *UseCase) isWifiProfileExists(ctx context.Context, d *dtov1.Profile, action string) error { if len(d.WiFiConfigs) > 0 { // check if the wireless profile is exists in the database wifiProfiles := []string{} @@ -142,7 +142,7 @@ func (uc *UseCase) isWifiProfileExists(ctx context.Context, d *dto.Profile, acti return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.Profile) (*dto.Profile, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.Profile) (*dtov1.Profile, error) { d1 := uc.dtoToEntity(d) err := uc.isWifiProfileExists(ctx, d, "update") @@ -191,7 +191,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.Profile) (*dto.Profile, er return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.Profile) (*dto.Profile, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.Profile) (*dtov1.Profile, error) { d1 := uc.dtoToEntity(d) if err := uc.isWifiProfileExists(ctx, d, "insert"); err != nil { @@ -245,7 +245,7 @@ func (uc *UseCase) insertProfile(ctx context.Context, d1 *entity.Profile) error return err } -func (uc *UseCase) insertProfileWifiConfigs(ctx context.Context, d *dto.Profile) error { +func (uc *UseCase) insertProfileWifiConfigs(ctx context.Context, d *dtov1.Profile) error { if len(d.WiFiConfigs) > 0 { for _, wifiConfig := range d.WiFiConfigs { wifiConfig.ProfileName = d.ProfileName @@ -261,7 +261,7 @@ func (uc *UseCase) insertProfileWifiConfigs(ctx context.Context, d *dto.Profile) return nil } -func (uc *UseCase) createdProfile(ctx context.Context, d *dto.Profile) (*dto.Profile, error) { +func (uc *UseCase) createdProfile(ctx context.Context, d *dtov1.Profile) (*dtov1.Profile, error) { newProfile, err := uc.repo.GetByName(ctx, d.ProfileName, d.TenantID) if err != nil { return nil, err @@ -273,8 +273,8 @@ func (uc *UseCase) createdProfile(ctx context.Context, d *dto.Profile) (*dto.Pro return d2, nil } -// convert dto.Profile to entity.Profile. -func (uc *UseCase) dtoToEntity(d *dto.Profile) *entity.Profile { +// convert dtov1.Profile to entity.Profile. +func (uc *UseCase) dtoToEntity(d *dtov1.Profile) *entity.Profile { // convert []string to comma separated string tags := strings.Join(d.Tags, ", ") @@ -306,11 +306,11 @@ func (uc *UseCase) dtoToEntity(d *dto.Profile) *entity.Profile { return d1 } -// convert entity.Profile to dto.Profile. -func (uc *UseCase) entityToDTO(d *entity.Profile) *dto.Profile { +// convert entity.Profile to dtov1.Profile. +func (uc *UseCase) entityToDTO(d *entity.Profile) *dtov1.Profile { // convert comma separated string to []string tags := strings.Split(d.Tags, ",") - d1 := &dto.Profile{ + d1 := &dtov1.Profile{ ProfileName: d.ProfileName, AMTPassword: d.AMTPassword, CreationDate: d.CreationDate, @@ -336,7 +336,7 @@ func (uc *UseCase) entityToDTO(d *entity.Profile) *dto.Profile { } if d.IEEE8021xProfileName != nil && *d.IEEE8021xProfileName != "" { - val := &dto.IEEE8021xConfig{ + val := &dtov1.IEEE8021xConfig{ ProfileName: *d.IEEE8021xProfileName, AuthenticationProtocol: *d.AuthenticationProtocol, PXETimeout: d.PXETimeout, diff --git a/internal/usecase/profiles/usecase_test.go b/internal/usecase/profiles/usecase_test.go index 20c01d2d..b0ed6590 100644 --- a/internal/usecase/profiles/usecase_test.go +++ b/internal/usecase/profiles/usecase_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/profiles" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -99,13 +99,13 @@ func TestGet(t *testing.T) { }, } - testProfileDTOs := []dto.Profile{ + testProfileDTOs := []dtov1.Profile{ { ProfileName: "test-profile-1", TenantID: "tenant-id-456", Tags: []string{""}, IEEE8021xProfileName: &ieeeProfileName, - IEEE8021xProfile: &dto.IEEE8021xConfig{ + IEEE8021xProfile: &dtov1.IEEE8021xConfig{ ProfileName: ieeeProfileName, TenantID: "tenant-id-456", WiredInterface: true, @@ -131,10 +131,10 @@ func TestGet(t *testing.T) { Return(testProfiles, nil) profileWifiRepo.EXPECT(). GetByProfileName(context.Background(), "test-profile-1", "tenant-id-456"). - Return([]dto.ProfileWiFiConfigs{}, nil) + Return([]dtov1.ProfileWiFiConfigs{}, nil) profileWifiRepo.EXPECT(). GetByProfileName(context.Background(), "test-profile-2", "tenant-id-456"). - Return([]dto.ProfileWiFiConfigs{}, nil) + Return([]dtov1.ProfileWiFiConfigs{}, nil) }, res: testProfileDTOs, err: nil, @@ -149,7 +149,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 5, 0, "tenant-id-456"). Return(nil, profiles.ErrDatabase) }, - res: []dto.Profile(nil), + res: []dtov1.Profile(nil), err: profiles.ErrDatabase, }, { @@ -162,7 +162,7 @@ func TestGet(t *testing.T) { Get(context.Background(), 10, 20, "tenant-id-456"). Return([]entity.Profile{}, nil) }, - res: []dto.Profile{}, + res: []dtov1.Profile{}, err: nil, }, } @@ -198,7 +198,7 @@ func TestGetByName(t *testing.T) { Version: "1.0.0", } - profileDTO := &dto.Profile{ + profileDTO := &dtov1.Profile{ ProfileName: "test-profile", TenantID: "tenant-id-456", Version: "1.0.0", @@ -218,7 +218,7 @@ func TestGetByName(t *testing.T) { Return(profile, nil) profilewificonfigfeat.EXPECT(). GetByProfileName(context.Background(), "test-profile", "tenant-id-456"). - Return([]dto.ProfileWiFiConfigs{}, nil) + Return([]dtov1.ProfileWiFiConfigs{}, nil) }, res: profileDTO, err: nil, @@ -234,7 +234,7 @@ func TestGetByName(t *testing.T) { GetByName(context.Background(), "unknown-profile", "tenant-id-456"). Return(nil, nil) }, - res: (*dto.Profile)(nil), + res: (*dtov1.Profile)(nil), err: profiles.ErrNotFound, }, } @@ -323,12 +323,12 @@ func TestUpdate(t *testing.T) { Version: "1.0.0", } - profileDTO := &dto.Profile{ + profileDTO := &dtov1.Profile{ ProfileName: "example-profile", TenantID: "tenant-id-456", Version: "1.0.0", Tags: []string{""}, - WiFiConfigs: []dto.ProfileWiFiConfigs{ + WiFiConfigs: []dtov1.ProfileWiFiConfigs{ { ProfileName: "example-profile", WirelessProfileName: "wireless-profile-1", @@ -366,7 +366,7 @@ func TestUpdate(t *testing.T) { CheckProfileExists(context.Background(), profileDTO.WiFiConfigs[0].WirelessProfileName, profileDTO.TenantID). Return(true, nil) }, - res: (*dto.Profile)(nil), + res: (*dtov1.Profile)(nil), err: profiles.ErrDatabase, }, { @@ -379,7 +379,7 @@ func TestUpdate(t *testing.T) { CheckProfileExists(context.Background(), profileDTO.WiFiConfigs[0].WirelessProfileName, profileDTO.TenantID). Return(true, nil) }, - res: (*dto.Profile)(nil), + res: (*dtov1.Profile)(nil), err: profiles.ErrDatabase, }, } @@ -411,13 +411,13 @@ func TestInsert(t *testing.T) { DHCPEnabled: true, } - profileDTO := &dto.Profile{ + profileDTO := &dtov1.Profile{ ProfileName: "new-profile", TenantID: "tenant-id-789", Version: "1.0.0", Tags: []string{""}, DHCPEnabled: true, - WiFiConfigs: []dto.ProfileWiFiConfigs{ + WiFiConfigs: []dtov1.ProfileWiFiConfigs{ { ProfileName: "new-profile", WirelessProfileName: "wireless-profile-1", @@ -455,7 +455,7 @@ func TestInsert(t *testing.T) { CheckProfileExists(context.Background(), profileDTO.WiFiConfigs[0].WirelessProfileName, profileDTO.TenantID). Return(true, nil) }, - res: (*dto.Profile)(nil), + res: (*dtov1.Profile)(nil), err: profiles.ErrDatabase, }, } diff --git a/internal/usecase/profiles/wificonfigs_mocks_test.go b/internal/usecase/profiles/wificonfigs_mocks_test.go index e9361183..2066c93e 100644 --- a/internal/usecase/profiles/wificonfigs_mocks_test.go +++ b/internal/usecase/profiles/wificonfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockwificonfigsFeatureMockRecorder) Delete(ctx, profileName, tenantID } // Get mocks base method. -func (m *MockwificonfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.WirelessConfig, error) { +func (m *MockwificonfigsFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.WirelessConfig) + ret0, _ := ret[0].([]dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockwificonfigsFeatureMockRecorder) Get(ctx, top, skip, tenantID any) } // GetByName mocks base method. -func (m *MockwificonfigsFeature) GetByName(ctx context.Context, guid, tenantID string) (*dto.WirelessConfig, error) { +func (m *MockwificonfigsFeature) GetByName(ctx context.Context, guid, tenantID string) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockwificonfigsFeatureMockRecorder) GetCount(ctx, tenantID any) *gomoc } // Insert mocks base method. -func (m *MockwificonfigsFeature) Insert(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockwificonfigsFeature) Insert(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockwificonfigsFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockwificonfigsFeature) Update(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockwificonfigsFeature) Update(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/profilewificonfigs/interfaces.go b/internal/usecase/profilewificonfigs/interfaces.go index d16b0bd3..703b69a7 100644 --- a/internal/usecase/profilewificonfigs/interfaces.go +++ b/internal/usecase/profilewificonfigs/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -15,8 +15,8 @@ type ( } Feature interface { - GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dto.ProfileWiFiConfigs, error) + GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dtov1.ProfileWiFiConfigs, error) DeleteByProfileName(ctx context.Context, profileName, tenantID string) error - Insert(ctx context.Context, p *dto.ProfileWiFiConfigs) error + Insert(ctx context.Context, p *dtov1.ProfileWiFiConfigs) error } ) diff --git a/internal/usecase/profilewificonfigs/mocks_test.go b/internal/usecase/profilewificonfigs/mocks_test.go index 51572cca..96e06891 100644 --- a/internal/usecase/profilewificonfigs/mocks_test.go +++ b/internal/usecase/profilewificonfigs/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -124,10 +124,10 @@ func (mr *MockFeatureMockRecorder) DeleteByProfileName(ctx, profileName, tenantI } // GetByProfileName mocks base method. -func (m *MockFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dto.ProfileWiFiConfigs, error) { +func (m *MockFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dtov1.ProfileWiFiConfigs, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByProfileName", ctx, profileName, tenantID) - ret0, _ := ret[0].([]dto.ProfileWiFiConfigs) + ret0, _ := ret[0].([]dtov1.ProfileWiFiConfigs) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -139,7 +139,7 @@ func (mr *MockFeatureMockRecorder) GetByProfileName(ctx, profileName, tenantID a } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, p *dto.ProfileWiFiConfigs) error { +func (m *MockFeature) Insert(ctx context.Context, p *dtov1.ProfileWiFiConfigs) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) ret0, _ := ret[0].(error) diff --git a/internal/usecase/profilewificonfigs/usecase.go b/internal/usecase/profilewificonfigs/usecase.go index 7bbfff09..047a58fe 100644 --- a/internal/usecase/profilewificonfigs/usecase.go +++ b/internal/usecase/profilewificonfigs/usecase.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" "github.com/open-amt-cloud-toolkit/console/pkg/logger" @@ -28,7 +28,7 @@ func New(r Repository, log logger.Interface) *UseCase { } } -func (uc *UseCase) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dto.ProfileWiFiConfigs, error) { +func (uc *UseCase) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dtov1.ProfileWiFiConfigs, error) { data, err := uc.repo.GetByProfileName(ctx, profileName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) @@ -39,7 +39,7 @@ func (uc *UseCase) GetByProfileName(ctx context.Context, profileName, tenantID s } // iterate over the data and convert each entity to dto - d1 := make([]dto.ProfileWiFiConfigs, len(data)) + d1 := make([]dtov1.ProfileWiFiConfigs, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -58,7 +58,7 @@ func (uc *UseCase) DeleteByProfileName(ctx context.Context, profileName, tenantI return nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.ProfileWiFiConfigs) error { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.ProfileWiFiConfigs) error { d1 := uc.dtoToEntity(d) _, err := uc.repo.Insert(ctx, d1) @@ -69,8 +69,8 @@ func (uc *UseCase) Insert(ctx context.Context, d *dto.ProfileWiFiConfigs) error return nil } -// convert dto.ProfileWiFiConfigs to entity.ProfileWiFiConfigs. -func (uc *UseCase) dtoToEntity(d *dto.ProfileWiFiConfigs) *entity.ProfileWiFiConfigs { +// convert dtov1.ProfileWiFiConfigs to entity.ProfileWiFiConfigs. +func (uc *UseCase) dtoToEntity(d *dtov1.ProfileWiFiConfigs) *entity.ProfileWiFiConfigs { d1 := &entity.ProfileWiFiConfigs{ Priority: d.Priority, WirelessProfileName: d.WirelessProfileName, @@ -81,9 +81,9 @@ func (uc *UseCase) dtoToEntity(d *dto.ProfileWiFiConfigs) *entity.ProfileWiFiCon return d1 } -// convert entity.ProfileWiFiConfigs to dto.ProfileWiFiConfigs. -func (uc *UseCase) entityToDTO(d *entity.ProfileWiFiConfigs) *dto.ProfileWiFiConfigs { - d1 := &dto.ProfileWiFiConfigs{ +// convert entity.ProfileWiFiConfigs to dtov1.ProfileWiFiConfigs. +func (uc *UseCase) entityToDTO(d *entity.ProfileWiFiConfigs) *dtov1.ProfileWiFiConfigs { + d1 := &dtov1.ProfileWiFiConfigs{ Priority: d.Priority, WirelessProfileName: d.WirelessProfileName, ProfileName: d.ProfileName, diff --git a/internal/usecase/profilewificonfigs/usecase_test.go b/internal/usecase/profilewificonfigs/usecase_test.go index 152ba8db..1b1c556d 100644 --- a/internal/usecase/profilewificonfigs/usecase_test.go +++ b/internal/usecase/profilewificonfigs/usecase_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/profilewificonfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -54,7 +54,7 @@ func TestGetByProfileName(t *testing.T) { }, }, nil) }, - res: []dto.ProfileWiFiConfigs{ + res: []dtov1.ProfileWiFiConfigs{ { ProfileName: "profile1", TenantID: "tenant1", diff --git a/internal/usecase/wificonfigs/interfaces.go b/internal/usecase/wificonfigs/interfaces.go index 5a8d58b8..b8769048 100644 --- a/internal/usecase/wificonfigs/interfaces.go +++ b/internal/usecase/wificonfigs/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" ) type ( @@ -21,10 +21,10 @@ type ( Feature interface { CheckProfileExists(ctx context.Context, profileName, tenantID string) (bool, error) GetCount(ctx context.Context, tenantID string) (int, error) - Get(ctx context.Context, top, skip int, tenantID string) ([]dto.WirelessConfig, error) - GetByName(ctx context.Context, guid, tenantID string) (*dto.WirelessConfig, error) + Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.WirelessConfig, error) + GetByName(ctx context.Context, guid, tenantID string) (*dtov1.WirelessConfig, error) Delete(ctx context.Context, profileName, tenantID string) error - Update(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) - Insert(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) + Update(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) + Insert(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) } ) diff --git a/internal/usecase/wificonfigs/mocks_test.go b/internal/usecase/wificonfigs/mocks_test.go index d66a2ded..2e56c3ad 100644 --- a/internal/usecase/wificonfigs/mocks_test.go +++ b/internal/usecase/wificonfigs/mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -199,10 +199,10 @@ func (mr *MockFeatureMockRecorder) Delete(ctx, profileName, tenantID any) *gomoc } // Get mocks base method. -func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.WirelessConfig, error) { +func (m *MockFeature) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", ctx, top, skip, tenantID) - ret0, _ := ret[0].([]dto.WirelessConfig) + ret0, _ := ret[0].([]dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -214,10 +214,10 @@ func (mr *MockFeatureMockRecorder) Get(ctx, top, skip, tenantID any) *gomock.Cal } // GetByName mocks base method. -func (m *MockFeature) GetByName(ctx context.Context, guid, tenantID string) (*dto.WirelessConfig, error) { +func (m *MockFeature) GetByName(ctx context.Context, guid, tenantID string) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByName", ctx, guid, tenantID) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -244,10 +244,10 @@ func (mr *MockFeatureMockRecorder) GetCount(ctx, tenantID any) *gomock.Call { } // Insert mocks base method. -func (m *MockFeature) Insert(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockFeature) Insert(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -259,10 +259,10 @@ func (mr *MockFeatureMockRecorder) Insert(ctx, p any) *gomock.Call { } // Update mocks base method. -func (m *MockFeature) Update(ctx context.Context, p *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (m *MockFeature) Update(ctx context.Context, p *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", ctx, p) - ret0, _ := ret[0].(*dto.WirelessConfig) + ret0, _ := ret[0].(*dtov1.WirelessConfig) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/usecase/wificonfigs/profileswificonfigs_mocks_test.go b/internal/usecase/wificonfigs/profileswificonfigs_mocks_test.go index 35b620d9..fab50487 100644 --- a/internal/usecase/wificonfigs/profileswificonfigs_mocks_test.go +++ b/internal/usecase/wificonfigs/profileswificonfigs_mocks_test.go @@ -14,7 +14,7 @@ import ( reflect "reflect" entity "github.com/open-amt-cloud-toolkit/console/internal/entity" - dto "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" gomock "go.uber.org/mock/gomock" ) @@ -124,10 +124,10 @@ func (mr *MockProfileWiFiConfigsFeatureMockRecorder) DeleteByProfileName(ctx, pr } // GetByProfileName mocks base method. -func (m *MockProfileWiFiConfigsFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dto.ProfileWiFiConfigs, error) { +func (m *MockProfileWiFiConfigsFeature) GetByProfileName(ctx context.Context, profileName, tenantID string) ([]dtov1.ProfileWiFiConfigs, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetByProfileName", ctx, profileName, tenantID) - ret0, _ := ret[0].([]dto.ProfileWiFiConfigs) + ret0, _ := ret[0].([]dtov1.ProfileWiFiConfigs) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -139,7 +139,7 @@ func (mr *MockProfileWiFiConfigsFeatureMockRecorder) GetByProfileName(ctx, profi } // Insert mocks base method. -func (m *MockProfileWiFiConfigsFeature) Insert(ctx context.Context, p *dto.ProfileWiFiConfigs) error { +func (m *MockProfileWiFiConfigsFeature) Insert(ctx context.Context, p *dtov1.ProfileWiFiConfigs) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Insert", ctx, p) ret0, _ := ret[0].(error) diff --git a/internal/usecase/wificonfigs/usecase.go b/internal/usecase/wificonfigs/usecase.go index d904dd5e..bb5092e9 100644 --- a/internal/usecase/wificonfigs/usecase.go +++ b/internal/usecase/wificonfigs/usecase.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/ieee8021xconfigs" "github.com/open-amt-cloud-toolkit/console/internal/usecase/sqldb" "github.com/open-amt-cloud-toolkit/console/pkg/consoleerrors" @@ -56,14 +56,14 @@ func (uc *UseCase) GetCount(ctx context.Context, tenantID string) (int, error) { return count, nil } -func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dto.WirelessConfig, error) { +func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]dtov1.WirelessConfig, error) { data, err := uc.repo.Get(ctx, top, skip, tenantID) if err != nil { return nil, ErrDatabase.Wrap("Get", "uc.repo.Get", err) } // iterate over the data and convert each entity to dto - d1 := make([]dto.WirelessConfig, len(data)) + d1 := make([]dtov1.WirelessConfig, len(data)) for i := range data { tmpEntity := data[i] // create a new variable to avoid memory aliasing @@ -73,7 +73,7 @@ func (uc *UseCase) Get(ctx context.Context, top, skip int, tenantID string) ([]d return d1, nil } -func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dto.WirelessConfig, error) { +func (uc *UseCase) GetByName(ctx context.Context, profileName, tenantID string) (*dtov1.WirelessConfig, error) { data, err := uc.repo.GetByName(ctx, profileName, tenantID) if err != nil { return nil, ErrDatabase.Wrap("GetByName", "uc.repo.GetByName", err) @@ -101,7 +101,7 @@ func (uc *UseCase) Delete(ctx context.Context, profileName, tenantID string) err return nil } -func (uc *UseCase) Update(ctx context.Context, d *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (uc *UseCase) Update(ctx context.Context, d *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { d1 := uc.dtoToEntity(d) // check if the IEEE profile is exists in the database @@ -131,7 +131,7 @@ func (uc *UseCase) Update(ctx context.Context, d *dto.WirelessConfig) (*dto.Wire return d2, nil } -func (uc *UseCase) Insert(ctx context.Context, d *dto.WirelessConfig) (*dto.WirelessConfig, error) { +func (uc *UseCase) Insert(ctx context.Context, d *dtov1.WirelessConfig) (*dtov1.WirelessConfig, error) { d1 := uc.dtoToEntity(d) // check if the IEEE profile is exists in the database @@ -157,8 +157,8 @@ func (uc *UseCase) Insert(ctx context.Context, d *dto.WirelessConfig) (*dto.Wire return d2, nil } -// convert dto.WirelessConfig to entity.WirelessConfig. -func (uc *UseCase) dtoToEntity(d *dto.WirelessConfig) *entity.WirelessConfig { +// convert dtov1.WirelessConfig to entity.WirelessConfig. +func (uc *UseCase) dtoToEntity(d *dtov1.WirelessConfig) *entity.WirelessConfig { // convert []int to comma separated string linkPolicy := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(d.LinkPolicy)), ","), "[]") @@ -178,8 +178,8 @@ func (uc *UseCase) dtoToEntity(d *dto.WirelessConfig) *entity.WirelessConfig { return d1 } -// convert entity.WirelessConfig to dto.WirelessConfig. -func (uc *UseCase) entityToDTO(d *entity.WirelessConfig) *dto.WirelessConfig { +// convert entity.WirelessConfig to dtov1.WirelessConfig. +func (uc *UseCase) entityToDTO(d *entity.WirelessConfig) *dtov1.WirelessConfig { // convert comma separated string to []int linkPolicyInt := []int{} @@ -200,7 +200,7 @@ func (uc *UseCase) entityToDTO(d *entity.WirelessConfig) *dto.WirelessConfig { } } - d1 := &dto.WirelessConfig{ + d1 := &dtov1.WirelessConfig{ ProfileName: d.ProfileName, AuthenticationMethod: d.AuthenticationMethod, EncryptionMethod: d.EncryptionMethod, @@ -214,7 +214,7 @@ func (uc *UseCase) entityToDTO(d *entity.WirelessConfig) *dto.WirelessConfig { } if d.IEEE8021xProfileName != nil && *d.IEEE8021xProfileName != "" { - val := &dto.IEEE8021xConfig{ + val := &dtov1.IEEE8021xConfig{ AuthenticationProtocol: *d.AuthenticationProtocol, PXETimeout: d.PXETimeout, WiredInterface: *d.WiredInterface, diff --git a/internal/usecase/wificonfigs/usecase_test.go b/internal/usecase/wificonfigs/usecase_test.go index 56582c36..c6353b43 100644 --- a/internal/usecase/wificonfigs/usecase_test.go +++ b/internal/usecase/wificonfigs/usecase_test.go @@ -8,7 +8,7 @@ import ( "go.uber.org/mock/gomock" "github.com/open-amt-cloud-toolkit/console/internal/entity" - "github.com/open-amt-cloud-toolkit/console/internal/entity/dto" + dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/usecase/wificonfigs" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -17,7 +17,7 @@ type test struct { name string top int skip int - input dto.WirelessConfig + input dtov1.WirelessConfig profileName string tenantID string mock func(*MockRepository, ...interface{}) @@ -34,24 +34,24 @@ func (m MockIEEE8021x) GetCount(_ context.Context, _ string) (int, error) { return 0, nil } -func (m MockIEEE8021x) Get(_ context.Context, _, _ int, _ string) ([]dto.IEEE8021xConfig, error) { - return []dto.IEEE8021xConfig{}, nil +func (m MockIEEE8021x) Get(_ context.Context, _, _ int, _ string) ([]dtov1.IEEE8021xConfig, error) { + return []dtov1.IEEE8021xConfig{}, nil } -func (m MockIEEE8021x) GetByName(_ context.Context, _, _ string) (*dto.IEEE8021xConfig, error) { - return &dto.IEEE8021xConfig{}, nil +func (m MockIEEE8021x) GetByName(_ context.Context, _, _ string) (*dtov1.IEEE8021xConfig, error) { + return &dtov1.IEEE8021xConfig{}, nil } func (m MockIEEE8021x) Delete(_ context.Context, _, _ string) error { return nil } -func (m MockIEEE8021x) Update(_ context.Context, _ *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { - return &dto.IEEE8021xConfig{}, nil +func (m MockIEEE8021x) Update(_ context.Context, _ *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { + return &dtov1.IEEE8021xConfig{}, nil } -func (m MockIEEE8021x) Insert(_ context.Context, _ *dto.IEEE8021xConfig) (*dto.IEEE8021xConfig, error) { - return &dto.IEEE8021xConfig{}, nil +func (m MockIEEE8021x) Insert(_ context.Context, _ *dtov1.IEEE8021xConfig) (*dtov1.IEEE8021xConfig, error) { + return &dtov1.IEEE8021xConfig{}, nil } func wificonfigsTest(t *testing.T) (*wificonfigs.UseCase, *MockRepository) { @@ -170,13 +170,13 @@ func TestGet(t *testing.T) { }, } - testWifiConfigDTOs := []dto.WirelessConfig{ + testWifiConfigDTOs := []dtov1.WirelessConfig{ { ProfileName: "test-wirelessconfig-1", TenantID: "tenant-id-456", LinkPolicy: []int{1, 2}, IEEE8021xProfileName: &ieeeProfileName, - IEEE8021xProfileObject: &dto.IEEE8021xConfig{ + IEEE8021xProfileObject: &dtov1.IEEE8021xConfig{ AuthenticationProtocol: 0, WiredInterface: false, }, @@ -212,7 +212,7 @@ func TestGet(t *testing.T) { Get(context.Background(), args[0], args[1], args[2]). Return(nil, wificonfigs.ErrDatabase) }, - res: []dto.WirelessConfig(nil), + res: []dtov1.WirelessConfig(nil), err: wificonfigs.ErrDatabase, }, { @@ -225,7 +225,7 @@ func TestGet(t *testing.T) { Get(context.Background(), args[0], args[1], args[2]). Return([]entity.WirelessConfig{}, nil) }, - res: []dto.WirelessConfig{}, + res: []dtov1.WirelessConfig{}, err: nil, }, } @@ -261,7 +261,7 @@ func TestGetByName(t *testing.T) { Version: "123", } - wirelessConfigDTO := &dto.WirelessConfig{ + wirelessConfigDTO := &dtov1.WirelessConfig{ ProfileName: "test-WirelessConfig", TenantID: "tenant-id-456", Version: "123", @@ -271,7 +271,7 @@ func TestGetByName(t *testing.T) { tests := []test{ { name: "successful retrieval", - input: dto.WirelessConfig{ + input: dtov1.WirelessConfig{ ProfileName: "test-wirelessConfig", TenantID: "tenant-id-456", }, @@ -285,7 +285,7 @@ func TestGetByName(t *testing.T) { }, { name: "WirelessConfig not found", - input: dto.WirelessConfig{ + input: dtov1.WirelessConfig{ ProfileName: "unknown-WirelessConfig", TenantID: "tenant-id-456", }, @@ -294,7 +294,7 @@ func TestGetByName(t *testing.T) { GetByName(context.Background(), args[0], args[1]). Return(nil, nil) }, - res: (*dto.WirelessConfig)(nil), + res: (*dtov1.WirelessConfig)(nil), err: wificonfigs.ErrNotFound, }, } @@ -378,7 +378,7 @@ func TestUpdate(t *testing.T) { LinkPolicy: new(string), } - wirelessConfigDTO := &dto.WirelessConfig{ + wirelessConfigDTO := &dtov1.WirelessConfig{ ProfileName: "test-WirelessConfig", TenantID: "tenant-id-456", Version: "123", @@ -406,7 +406,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), wirelessConfig). Return(false, wificonfigs.ErrNotFound) }, - res: (*dto.WirelessConfig)(nil), + res: (*dtov1.WirelessConfig)(nil), err: wificonfigs.ErrDatabase, }, { @@ -416,7 +416,7 @@ func TestUpdate(t *testing.T) { Update(context.Background(), wirelessConfig). Return(false, wificonfigs.ErrDatabase) }, - res: (*dto.WirelessConfig)(nil), + res: (*dtov1.WirelessConfig)(nil), err: wificonfigs.ErrDatabase, }, } @@ -448,7 +448,7 @@ func TestInsert(t *testing.T) { LinkPolicy: new(string), } - wirelessConfigDTO := &dto.WirelessConfig{ + wirelessConfigDTO := &dtov1.WirelessConfig{ ProfileName: "test-WirelessConfig", TenantID: "tenant-id-456", Version: "123", @@ -476,7 +476,7 @@ func TestInsert(t *testing.T) { Insert(context.Background(), wirelessConfig). Return("", wificonfigs.ErrDatabase) }, - res: (*dto.WirelessConfig)(nil), + res: (*dtov1.WirelessConfig)(nil), err: wificonfigs.ErrDatabase, }, }