diff --git a/cmd/devices-api/api.go b/cmd/devices-api/api.go index 6a4e6c8db..54b56638e 100644 --- a/cmd/devices-api/api.go +++ b/cmd/devices-api/api.go @@ -214,7 +214,7 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store, amdOwnerMw := owner.AftermarketDevice(pdb, usersClient, &logger) apOwner := v1Auth.Group("/autopi/unit/:serial", amdOwnerMw) // same as above but AftermarketDevice - amdOwner := v1Auth.Group("/aftermarket/device/hw/:serial", amdOwnerMw) + amdOwner := v1Auth.Group("/aftermarket/device/by-serial/:serial", amdOwnerMw) apOwner.Get("/", userDeviceController.GetAutoPiUnitInfo) amdOwner.Get("/", userDeviceController.GetAutoPiUnitInfo) diff --git a/docs/docs.go b/docs/docs.go index 749035c50..4ab1bbd6b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,4 +1,4 @@ -// Code generated by swaggo/swag at 2023-07-21 14:15:44.947049 -0400 EDT m=+2.148109751. DO NOT EDIT +// Code generated by swaggo/swag at 2023-07-24 12:08:47.475015 -0400 EDT m=+1.934596292. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -15,7 +15,7 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/aftermarket/device/hw/:serial": { + "/aftermarket/device/by-serial/:serial": { "get": { "security": [ { @@ -48,7 +48,7 @@ const docTemplate = `{ } } }, - "/aftermarket/device/hw/:serial/commands/claim": { + "/aftermarket/device/by-serial/:serial/commands/claim": { "get": { "security": [ { @@ -112,7 +112,7 @@ const docTemplate = `{ } } }, - "/aftermarket/device/hw/:serial/commands/unclaim": { + "/aftermarket/device/by-serial/:serial/commands/unclaim": { "post": { "security": [ { @@ -139,7 +139,7 @@ const docTemplate = `{ } } }, - "/aftermarket/device/hw/:serial/update": { + "/aftermarket/device/by-serial/:serial/update": { "post": { "security": [ { diff --git a/docs/swagger.json b/docs/swagger.json index 75edf182b..7fb798c27 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -7,7 +7,7 @@ }, "basePath": "/v1", "paths": { - "/aftermarket/device/hw/:serial": { + "/aftermarket/device/by-serial/:serial": { "get": { "security": [ { @@ -40,7 +40,7 @@ } } }, - "/aftermarket/device/hw/:serial/commands/claim": { + "/aftermarket/device/by-serial/:serial/commands/claim": { "get": { "security": [ { @@ -104,7 +104,7 @@ } } }, - "/aftermarket/device/hw/:serial/commands/unclaim": { + "/aftermarket/device/by-serial/:serial/commands/unclaim": { "post": { "security": [ { @@ -131,7 +131,7 @@ } } }, - "/aftermarket/device/hw/:serial/update": { + "/aftermarket/device/by-serial/:serial/update": { "post": { "security": [ { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 079725006..53770a176 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1026,7 +1026,7 @@ paths: description: Not Found tags: - nfts - /aftermarket/device/hw/:serial: + /aftermarket/device/by-serial/:serial: get: description: gets the information about the aftermarket device by the hw serial parameters: @@ -1046,7 +1046,7 @@ paths: - BearerAuth: [] tags: - integrations - /aftermarket/device/hw/:serial/commands/claim: + /aftermarket/device/by-serial/:serial/commands/claim: get: description: Return the EIP-712 payload to be signed for Aftermarket device claiming. @@ -1087,7 +1087,7 @@ paths: description: No Content security: - BearerAuth: [] - /aftermarket/device/hw/:serial/commands/unclaim: + /aftermarket/device/by-serial/:serial/commands/unclaim: post: description: |- Dev-only endpoint for removing a claim. Removes the flag on-chain and clears @@ -1105,7 +1105,7 @@ paths: description: No Content security: - BearerAuth: [] - /aftermarket/device/hw/:serial/update: + /aftermarket/device/by-serial/:serial/update: post: description: checks to see if aftermarket device needs to be updated, and starts update process if so. diff --git a/internal/controllers/user_integrations_controller.go b/internal/controllers/user_integrations_controller.go index 87feb928f..1751e9b57 100644 --- a/internal/controllers/user_integrations_controller.go +++ b/internal/controllers/user_integrations_controller.go @@ -439,7 +439,7 @@ func (udc *UserDevicesController) OpenFrunk(c *fiber.Ctx) error { // @Param serial path string true "autopi unit id or macaron serial" // @Success 200 {object} controllers.AutoPiDeviceInfo // @Security BearerAuth -// @Router /aftermarket/device/hw/:serial [get] +// @Router /aftermarket/device/by-serial/:serial [get] func (udc *UserDevicesController) GetAutoPiUnitInfo(c *fiber.Ctx) error { const minimumAutoPiRelease = "v1.22.8" // correct semver has leading v @@ -567,7 +567,7 @@ func (udc *UserDevicesController) GetAutoPiUnitInfo(c *fiber.Ctx) error { // @Param serial path string true "autopi unit id", ie. physical barcode // @Success 200 {object} services.AutoPiTask // @Security BearerAuth -// @Router /aftermarket/device/hw/:serial/update [post] +// @Router /aftermarket/device/by-serial/:serial/update [post] func (udc *UserDevicesController) StartAutoPiUpdateTask(c *fiber.Ctx) error { unitID := c.Locals("serial").(string) userID := helpers.GetUserID(c) @@ -610,7 +610,7 @@ func (udc *UserDevicesController) StartAutoPiUpdateTask(c *fiber.Ctx) error { // @Param serial path string true "AutoPi unit id" // @Success 200 {object} signer.TypedData // @Security BearerAuth -// @Router /aftermarket/device/hw/:serial/commands/claim [get] +// @Router /aftermarket/device/by-serial/:serial/commands/claim [get] func (udc *UserDevicesController) GetAutoPiClaimMessage(c *fiber.Ctx) error { userID := helpers.GetUserID(c) @@ -1340,7 +1340,7 @@ type AutoPiPairRequest struct { // @Param serial path string true "AutoPi unit id" // @Success 204 // @Security BearerAuth -// @Router /aftermarket/device/hw/:serial/commands/unclaim [post] +// @Router /aftermarket/device/by-serial/:serial/commands/unclaim [post] func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error { userID := helpers.GetUserID(c) unitID := c.Params("serial") @@ -1394,7 +1394,7 @@ func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error { // @Param claimRequest body controllers.AutoPiClaimRequest true "Signatures from the user and AutoPi" // @Success 204 // @Security BearerAuth -// @Router /aftermarket/device/hw/:serial/commands/claim [post] +// @Router /aftermarket/device/by-serial/:serial/commands/claim [post] func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error { userID := helpers.GetUserID(c) unitID := c.Params("serial") diff --git a/internal/controllers/user_integrations_controller_test.go b/internal/controllers/user_integrations_controller_test.go index 97448f84d..f601813d9 100644 --- a/internal/controllers/user_integrations_controller_test.go +++ b/internal/controllers/user_integrations_controller_test.go @@ -591,7 +591,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil) app := fiber.New() logger := zerolog.Nop() - app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) + app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) // arrange const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9" test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb) @@ -608,7 +608,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda }, nil) // act - request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "") + request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "") response, err := app.Test(request) require.NoError(s.T(), err) // assert @@ -629,7 +629,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate() c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil) app := fiber.New() logger := zerolog.Nop() - app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) + app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) // arrange const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9" test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb) @@ -646,7 +646,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_UpToDate() }, nil) // act - request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "") + request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "") response, err := app.Test(request) require.NoError(s.T(), err) // assert @@ -664,7 +664,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil) app := fiber.New() logger := zerolog.Nop() - app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) + app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) // arrange const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9" test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb) @@ -681,7 +681,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda }, nil) // act - request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "") + request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "") response, err := app.Test(request) require.NoError(s.T(), err) // assert @@ -692,6 +692,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_FutureUpda assert.Equal(s.T(), "1.23.1", gjson.GetBytes(body, "releaseVersion").String()) assert.Equal(s.T(), false, gjson.GetBytes(body, "shouldUpdate").Bool()) } + func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpdate_Semver() { // as of jun 12 23, versions are now correctly semverd starting with "v", so test for this too const environment = "prod" // shouldUpdate only applies in prod @@ -700,7 +701,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda c := NewUserDevicesController(&config.Settings{Port: "3000", Environment: environment}, s.pdb.DBS, test.Logger(), s.deviceDefSvc, s.deviceDefIntSvc, &fakeEventService{}, s.scClient, s.scTaskSvc, s.teslaSvc, s.teslaTaskService, new(shared.ROT13Cipher), autopiAPISvc, nil, s.autoPiIngest, s.deviceDefinitionRegistrar, nil, nil, nil, nil, nil, nil, nil, nil, nil) app := fiber.New() logger := zerolog.Nop() - app.Get("/autopi/unit/:unitID", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) + app.Get("/aftermarket/device/by-serial/:serial", test.AuthInjectorTestHandler(testUserID), owner.AftermarketDevice(s.pdb, s.userClient, &logger), c.GetAutoPiUnitInfo) // arrange const unitID = "431d2e89-46f1-6884-6226-5d1ad20c84d9" test.SetupCreateAftermarketDevice(s.T(), "", nil, unitID, nil, s.pdb) @@ -717,7 +718,7 @@ func (s *UserIntegrationsControllerTestSuite) TestGetAutoPiInfoNoUDAI_ShouldUpda }, nil) // act - request := test.BuildRequest("GET", "/autopi/unit/"+unitID, "") + request := test.BuildRequest("GET", "/aftermarket/device/by-serial/"+unitID, "") response, err := app.Test(request) require.NoError(s.T(), err) // assert