Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conf reload endpoint #4

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions cocas/cocas.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,35 @@ type GalaxyConf struct {
LocalRoles []string `yaml:"local_roles"`
G33kTeam []string `yaml:"geek_username"`
AssoId string `yaml:"asso_id"`
ExtraUsername []string `yaml:"extra_username"`
ExtraUsername []string `yaml:"extra_admin"`
}

var GalaxyUsers GalaxyConf

func InitCas() {

// Conf
GalaxyUsers.ExtraUsername = helpers.TheAppConfig().ExtraAdmin[:]
GalaxyUsers.AssoId = helpers.TheAppConfig().AssoId
ExternalLoadConf()

// Server init
cocasmwd = http.NewServeMux()
cocasmwd.Handle("/", MyHandler)

url, _ := url.Parse(GalaxyUsers.CASServer)
client := cas.NewClient(&cas.Options{
URL: url,
})

cocas = &http.Server{
Addr: ":" + helpers.TheAppConfig().PortCas,
Handler: client.Handle(cocasmwd),
}

logger.GetLogger().LogInfo("cocas", "Conf up !")
}

func ExternalLoadConf() {
// Global conf
GalaxyUsers.GlobalConfUrl = helpers.TheAppConfig().GlobalUrl
global_conf, err := http.Get(GalaxyUsers.GlobalConfUrl)
Expand All @@ -54,7 +72,7 @@ func InitCas() {
// Local conf
if helpers.TheAppConfig().LocalAsso != "" {
GalaxyUsers.LocalConfUrl = helpers.TheAppConfig().LocalAsso
local_conf, err := http.Get(GalaxyUsers.GlobalConfUrl)
local_conf, err := http.Get(GalaxyUsers.LocalConfUrl)
if err != nil {
logger.GetLogger().LogError("cocas", "local conf url file unavailable", err)
}
Expand All @@ -65,22 +83,6 @@ func InitCas() {
fmt.Println(err)
}
}

// Server init
cocasmwd = http.NewServeMux()
cocasmwd.Handle("/", MyHandler)

url, _ := url.Parse(GalaxyUsers.CASServer)
client := cas.NewClient(&cas.Options{
URL: url,
})

cocas = &http.Server{
Addr: ":" + helpers.TheAppConfig().PortCas,
Handler: client.Handle(cocasmwd),
}

logger.GetLogger().LogInfo("cocas", "Conf up !")
}

func GetCasServer() *http.Server {
Expand Down
6 changes: 6 additions & 0 deletions cocas/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

if r.URL.Path == "/reload" {
ExternalLoadConf()
logger.GetLogger().LogInfo("cocas", "Reloaded conf")
return
}

esner := GetProfile(r)

w.WriteHeader(http.StatusOK)
Expand Down
1 change: 1 addition & 0 deletions test/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ portcas: "8181"
# Local Asso conf
asso_id: "FR-LYON-ESN"
extra_admin: []
# Local conf url
local_url: "https://raw.githubusercontent.com/ESN-CosmoCode/.github/main/cocas/galaxy.yaml"
# Global and G33kTeam conf url
global_url: "https://raw.githubusercontent.com/ESNFranceG33kTeam/.github/main/cocas/galaxy.yaml"