From 827d53a0ece6245188c050011cfc01743e3c8225 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Wed, 23 Nov 2022 06:48:26 +0700 Subject: [PATCH] feat: add multiple basic auth account --- src/cmd/root.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index b7cf302..ff39495 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -74,16 +74,21 @@ func runRest(_ *cobra.Command, _ []string) { })) if config.AppBasicAuthCredential != "" { - ba := strings.Split(config.AppBasicAuthCredential, ":") - if len(ba) != 2 { - log.Fatalln("Basic auth is not valid, please this following format :") + account := make(map[string]string, 0) + multipleBA := strings.Split(config.AppBasicAuthCredential, ",") + for _, basicAuth := range multipleBA { + ba := strings.Split(basicAuth, ":") + if len(ba) != 2 { + log.Fatalln("Basic auth is not valid, please this following format :") + } + account[ba[0]] = ba[1] } - app.Use(basicauth.New(basicauth.Config{ - Users: map[string]string{ - ba[0]: ba[1], - }, - })) + if account != nil { + app.Use(basicauth.New(basicauth.Config{ + Users: account, + })) + } } db := utils.InitWaDB()