mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
secret code middleware for migration
This commit is contained in:
@@ -16,7 +16,7 @@ func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiControlle
|
|||||||
ac.ApiService = as
|
ac.ApiService = as
|
||||||
|
|
||||||
s.GET("", ac.getFirst)
|
s.GET("", ac.getFirst)
|
||||||
s.POST("migrate", middleware.Auth, ac.postMigrate)
|
s.POST("migrate", middleware.SecretCode, ac.postMigrate)
|
||||||
|
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|||||||
30
pkg/middleware/secretCode.go
Normal file
30
pkg/middleware/secretCode.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"wallet-api/pkg/models"
|
||||||
|
"wallet-api/pkg/utl/configs"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SecretCode(c *gin.Context) {
|
||||||
|
exceptionReturn := new(models.Exception)
|
||||||
|
secretCode := ExtractCode(c)
|
||||||
|
secret := os.Getenv("SECRET_CODE")
|
||||||
|
if secret == "" {
|
||||||
|
secret = configs.SecretCode
|
||||||
|
}
|
||||||
|
if secret != secretCode {
|
||||||
|
exceptionReturn.ErrorCode = "401101"
|
||||||
|
exceptionReturn.StatusCode = 401
|
||||||
|
exceptionReturn.Message = "Invalid secret code"
|
||||||
|
c.AbortWithStatusJSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExtractCode(c *gin.Context) string {
|
||||||
|
secret := c.GetHeader("SECRET_CODE")
|
||||||
|
return secret
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package configs
|
package configs
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.1"
|
Version = "0.0.1"
|
||||||
Prefix = "v1"
|
Prefix = "v1"
|
||||||
Secret = "Donde4sta"
|
Secret = "Donde4sta"
|
||||||
|
SecretCode = "brasno"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user