Skip to content

Commit

Permalink
internal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Apr 29, 2019
1 parent f68d479 commit 55e7e3a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/tm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ import (
"flag"
"os"

"github.com/gin-gonic/gin"

"github.com/txn2/micro"
"github.com/txn2/provision"
"github.com/txn2/tm"
)

var (
modeEnv = getEnv("MODE", "protected")
elasticServerEnv = getEnv("ELASTIC_SERVER", "http://elasticsearch:9200")
)

func main() {
mode := flag.String("mode", elasticServerEnv, "Protected or internal modes. (internal = security bypass)")
esServer := flag.String("esServer", elasticServerEnv, "Elasticsearch Server")

serverCfg, _ := micro.NewServerCfg("Type Model (tm)")
Expand All @@ -41,24 +45,36 @@ func main() {
os.Exit(1)
}

accessCheck := func(admin bool) gin.HandlerFunc {
return provision.AccountAccessCheckHandler(admin)
}

if *mode == "internal" {
accessCheck = func(admin bool) gin.HandlerFunc {
return func(c *gin.Context) {}
}
}

// User token middleware
server.Router.Use(provision.UserTokenHandler())
if *mode != "internal" {
server.Router.Use(provision.UserTokenHandler())
}

// Get a model
server.Router.GET("model/:account/:id",
provision.AccountAccessCheckHandler(false),
accessCheck(false),
tmApi.GetModelHandler,
)

// Upsert a model
server.Router.POST("model/:account",
provision.AccountAccessCheckHandler(true),
accessCheck(true),
tmApi.UpsertModelHandler,
)

// Search Models
server.Router.POST("searchModels/:account",
provision.AccountAccessCheckHandler(false),
accessCheck(false),
tmApi.SearchModelsHandler,
)

Expand Down

0 comments on commit 55e7e3a

Please sign in to comment.