Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit a5d8298

Browse files
Merge pull request #55 from bancodobrasil/optional-auth
feat: Auth mode config and route setup
2 parents a2a2504 + e42eae3 commit a5d8298

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Config struct {
2020
GitlabCIScript string `mapstructure:"FEATWS_API_GITLAB_CI_SCRIPT"`
2121
ExternalHost string `mapstructure:"EXTERNAL_HOST"`
2222
OpenAMURL string `mapstructure:"OPENAM_URL"`
23+
AuthMode string `mapstructure:"FEATWS_API_AUTH_MODE"`
2324
}
2425

2526
var config = &Config{}
@@ -43,6 +44,7 @@ func LoadConfig() (err error) {
4344
viper.SetDefault("FEATWS_API_GITLAB_CI_SCRIPT", "")
4445
viper.SetDefault("EXTERNAL_HOST", "localhost:9007")
4546
viper.SetDefault("OPENAM_URL", "")
47+
viper.SetDefault("FEATWS_API_AUTH_MODE", "none")
4648

4749
err = viper.ReadInConfig()
4850
if err != nil {

routes/api/v1/v1.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package v1
22

33
import (
4+
"strings"
5+
6+
"github.com/bancodobrasil/featws-api/config"
47
"github.com/bancodobrasil/featws-api/middlewares"
58
"github.com/gin-gonic/gin"
69
)
710

811
// Router define routes the API V1
912
func Router(router *gin.RouterGroup) {
10-
router.Use(middlewares.VerifyAuthToken())
13+
cfg := config.GetConfig()
14+
15+
switch strings.ToLower(cfg.AuthMode) {
16+
case "openam":
17+
router.Use(middlewares.VerifyAuthToken())
18+
}
19+
1120
rulesheetsRouter(router.Group("/rulesheets"))
1221
//rpcRouter(router.Group("/"))
1322
}

0 commit comments

Comments
 (0)