Skip to content

Commit

Permalink
feat(SPV-1393): remove access keys old api
Browse files Browse the repository at this point in the history
  • Loading branch information
dorzepowski committed Jan 16, 2025
1 parent f69d82d commit 5939be9
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 372 deletions.
45 changes: 0 additions & 45 deletions actions/access_keys/count.go

This file was deleted.

30 changes: 0 additions & 30 deletions actions/access_keys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ import (
"github.com/gin-gonic/gin"
)

// create will make a new model using the services defined in the action object
// Create access key godoc
// @Summary Create access key - Use (POST) /api/v1/users/current/keys instead.
// @Description This endpoint has been deprecated. Use (POST) /api/v1/users/current/keys instead.
// @Tags Access-key
// @Produce json
// @Param CreateAccessKey body CreateAccessKey true " "
// @Success 201 {object} models.AccessKey "Created AccessKey"
// @Failure 400 "Bad request - Error while parsing CreateAccessKey from request body"
// @Failure 500 "Internal server error - Error while creating new access key"
// @DeprecatedRouter /v1/access-key [post]
// @Security x-auth-xpub
func oldCreate(c *gin.Context, userContext *reqctx.UserContext) {
xpub, err := userContext.ShouldGetXPub()
if err != nil {
spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c))
return
}
createHelper(c, true, xpub)
}

// create will make a new model using the services defined in the action object
// Create access key godoc
// @Summary Create access key
Expand All @@ -49,10 +28,7 @@ func create(c *gin.Context, userContext *reqctx.UserContext) {
spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c))
return
}
createHelper(c, false, xpub)
}

func createHelper(c *gin.Context, snakeCase bool, xpub string) {
logger := reqctx.Logger(c)
var requestBody CreateAccessKey
if err := c.Bind(&requestBody); err != nil {
Expand All @@ -71,12 +47,6 @@ func createHelper(c *gin.Context, snakeCase bool, xpub string) {
return
}

if snakeCase {
contract := mappings.MapToOldAccessKeyContract(accessKey)
c.JSON(http.StatusCreated, contract)
return
}

contract := mappings.MapToAccessKeyContract(accessKey)
c.JSON(http.StatusCreated, contract)
}
30 changes: 1 addition & 29 deletions actions/access_keys/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@ import (
"github.com/gin-gonic/gin"
)

// get will get an existing model
// Get access key godoc
// @Summary Get access key - Use (GET) /api/v1/users/current/keys/{id} instead.
// @Description This endpoint has been deprecated. Use (GET) /api/v1/users/current/keys/{id} instead.
// @Tags Access-key
// @Produce json
// @Param id query string true "id of the access key"
// @Success 200 {object} models.AccessKey "AccessKey with given id"
// @Failure 400 "Bad request - Missing required field: id"
// @Failure 403 "Forbidden - Access key is not owned by the user"
// @Failure 500 "Internal server error - Error while getting access key"
// @DeprecatedRouter /v1/access-key [get]
// @Security x-auth-xpub
func oldGet(c *gin.Context, userContext *reqctx.UserContext) {
id := c.Query("id")

getHelper(c, id, true, userContext.GetXPubID())
}

// get will get an existing model
// Get access key godoc
// @Summary Get access key
Expand All @@ -43,11 +24,8 @@ func oldGet(c *gin.Context, userContext *reqctx.UserContext) {
// @Security x-auth-xpub
func get(c *gin.Context, userContext *reqctx.UserContext) {
id := c.Params.ByName("id")
reqXPubID := userContext.GetXPubID()

getHelper(c, id, false, userContext.GetXPubID())
}

func getHelper(c *gin.Context, id string, snakeCase bool, reqXPubID string) {
logger := reqctx.Logger(c)

if id == "" {
Expand All @@ -69,12 +47,6 @@ func getHelper(c *gin.Context, id string, snakeCase bool, reqXPubID string) {
return
}

if snakeCase {
contract := mappings.MapToOldAccessKeyContract(accessKey)
c.JSON(http.StatusOK, contract)
return
}

contract := mappings.MapToAccessKeyContract(accessKey)
c.JSON(http.StatusOK, contract)
}
36 changes: 1 addition & 35 deletions actions/access_keys/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,10 @@ import (
"net/http"

"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/mappings"
"github.com/bitcoin-sv/spv-wallet/server/reqctx"
"github.com/gin-gonic/gin"
)

// revoke will revoke the intended model by id
// Revoke access key godoc
// @Summary Revoke access key - Use (DELETE) /api/v1/users/current/keys/{id} instead.
// @Description This endpoint has been deprecated. Use (DELETE) /api/v1/users/current/keys/{id} instead.
// @Tags Access-key
// @Produce json
// @Param id query string true "id of the access key"
// @Success 200 {object} models.AccessKey "Revoked AccessKey"
// @Failure 400 "Bad request - Missing required field: id"
// @Failure 500 "Internal server error - Error while revoking access key"
// @DeprecatedRouter /v1/access-key [delete]
// @Security x-auth-xpub
func oldRevoke(c *gin.Context, userContext *reqctx.UserContext) {
id := c.Query("id")
xpub, err := userContext.ShouldGetXPub()
if err != nil {
spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c))
return
}

revokeHelper(c, id, true, xpub)
}

// revoke will revoke the intended model by id
// Revoke access key godoc
// @Summary Revoke access key
Expand All @@ -51,18 +27,14 @@ func revoke(c *gin.Context, userContext *reqctx.UserContext) {
spverrors.AbortWithErrorResponse(c, err, reqctx.Logger(c))
return
}
revokeHelper(c, id, false, xpub)
}

func revokeHelper(c *gin.Context, id string, snakeCase bool, xpub string) {
logger := reqctx.Logger(c)

if id == "" {
spverrors.ErrorResponse(c, spverrors.ErrMissingFieldID, logger)
return
}

accessKey, err := reqctx.Engine(c).RevokeAccessKey(
_, err = reqctx.Engine(c).RevokeAccessKey(
c.Request.Context(),
xpub,
id,
Expand All @@ -72,11 +44,5 @@ func revokeHelper(c *gin.Context, id string, snakeCase bool, xpub string) {
return
}

if snakeCase {
contract := mappings.MapToOldAccessKeyContract(accessKey)
c.JSON(http.StatusCreated, contract)
return
}

c.Status(http.StatusOK)
}
7 changes: 0 additions & 7 deletions actions/access_keys/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (

// RegisterRoutes creates the specific package routes
func RegisterRoutes(handlersManager *handlers.Manager) {
old := handlersManager.Group(handlers.GroupOldAPI, "/access-key")
old.POST("", handlers.AsUser(oldCreate))
old.GET("", handlers.AsUser(oldGet))
old.DELETE("", handlers.AsUser(oldRevoke))
old.POST("/count", handlers.AsUser(count))
old.POST("/search", handlers.AsUser(oldSearch))

group := handlersManager.Group(handlers.GroupAPI, "/users/current/keys")
group.GET("/:id", handlers.AsUser(get))
group.POST("", handlers.AsUser(create))
Expand Down
5 changes: 0 additions & 5 deletions actions/access_keys/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ func (ts *TestSuite) TestRegisterRoutes() {
method string
url string
}{
{"GET", "/" + config.APIVersion + "/access-key"},
{"POST", "/" + config.APIVersion + "/access-key"},
{"DELETE", "/" + config.APIVersion + "/access-key"},
{"POST", "/" + config.APIVersion + "/access-key/search"},

{"GET", "/api/" + config.APIVersion + "/users/current/keys/:id"},
{"POST", "/api/" + config.APIVersion + "/users/current/keys"},
{"DELETE", "/api/" + config.APIVersion + "/users/current/keys/:id"},
Expand Down
46 changes: 2 additions & 44 deletions actions/access_keys/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,12 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/internal/query"
"github.com/bitcoin-sv/spv-wallet/mappings"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/bitcoin-sv/spv-wallet/server/reqctx"
"github.com/gin-gonic/gin"
)

// oldSearch will fetch a list of access keys filtered by metadata
// Search access key godoc
// @Summary Search access key - Use (GET) /api/v1/users/current/keys instead.
// @Description This endpoint has been deprecated. Use (GET) /api/v1/users/current/keys instead.
// @Tags Access-key
// @Produce json
// @Param SearchAccessKeys body filter.SearchAccessKeys false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis"
// @Success 200 {object} []models.AccessKey "List of access keys"
// @Failure 400 "Bad request - Error while SearchAccessKeys from request body"
// @Failure 500 "Internal server error - Error while searching for access keys"
// @DeprecatedRouter /v1/access-key/search [post]
// @Security x-auth-xpub
func oldSearch(c *gin.Context, userContext *reqctx.UserContext) {
logger := reqctx.Logger(c)

var reqParams filter.SearchAccessKeys
if err := c.Bind(&reqParams); err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger)
return
}

accessKeys, err := reqctx.Engine(c).GetAccessKeysByXPubID(
c.Request.Context(),
userContext.GetXPubID(),
mappings.MapToMetadata(reqParams.Metadata),
reqParams.Conditions.ToDbConditions(),
mappings.MapToQueryParams(reqParams.QueryParams),
)
if err != nil {
spverrors.ErrorResponse(c, err, logger)
return
}

accessKeyContracts := make([]*models.AccessKey, 0)
for _, accessKey := range accessKeys {
accessKeyContracts = append(accessKeyContracts, mappings.MapToOldAccessKeyContract(accessKey))
}

c.JSON(http.StatusOK, accessKeyContracts)
}

// search will fetch a list of access keys filtered by metadata
// Search access key godoc
// @Summary Search access key
Expand Down Expand Up @@ -112,10 +70,10 @@ func search(c *gin.Context, userContext *reqctx.UserContext) {
return
}

response := response.PageModel[response.AccessKey]{
res := response.PageModel[response.AccessKey]{
Content: accessKeyContracts,
Page: common.GetPageDescriptionFromSearchParams(pageOptions, count),
}

c.JSON(http.StatusOK, response)
c.JSON(http.StatusOK, res)
}
86 changes: 0 additions & 86 deletions actions/admin/access_keys_old.go

This file was deleted.

Loading

0 comments on commit 5939be9

Please sign in to comment.