Skip to content
Snippets Groups Projects
Commit f2422f28 authored by Pierre Ecarlat's avatar Pierre Ecarlat
Browse files

feat: Add the ability to deactivate GRDF token

parent 99066c3a
3 merge requests!120feat: Allow to download all consents,!117chore: Set GRDF token refresh as an option,!115feat: Add the ability to deactivate GRDF token
......@@ -22,5 +22,6 @@ DATABASE_NAME
BO_API_TOKEN
FETCH_GRDF_TOKEN=true
GRDF_CLIENT_ID
GRDF_CLIENT_SECRET
......@@ -142,6 +142,7 @@ deploy_rec:
- sed -i "s/{{CLIENT_ID}}/$REC_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{CLIENT_SECRET}}/$REC_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{BO_API_TOKEN}}/$REC_BO_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{FETCH_GRDF_TOKEN}}/$REC_FETCH_GRDF_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{GRDF_CLIENT_ID}}/$GRDF_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{GRDF_CLIENT_SECRET}}/$GRDF_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{HOSTNAME}}/ecolyo-agent-rec.apps.grandlyon.com/g" ./k8s/secrets/ecolyo-agent-server-config.yml
......@@ -174,6 +175,7 @@ deploy_prod:
- sed -i "s/{{CLIENT_ID}}/$PROD_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{CLIENT_SECRET}}/$PROD_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{BO_API_TOKEN}}/$PROD_BO_API_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{FETCH_GRDF_TOKEN}}/$PROD_FETCH_GRDF_TOKEN/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{GRDF_CLIENT_ID}}/$GRDF_CLIENT_ID/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{GRDF_CLIENT_SECRET}}/$GRDF_CLIENT_SECRET/" ./k8s/secrets/ecolyo-agent-server-config.yml
- sed -i "s/{{HOSTNAME}}/ecolyo-agent.apps.grandlyon.com/g" ./k8s/secrets/ecolyo-agent-server-config.yml
......
......@@ -20,6 +20,7 @@ stringData:
BO_API_TOKEN: {{BO_API_TOKEN}}
TOKEN_URL: {{TOKEN_URL}}
USERINFO_URL: {{USERINFO_URL}}
FETCH_GRDF_TOKEN: {{FETCH_GRDF_TOKEN}}
GRDF_CLIENT_ID: {{GRDF_CLIENT_ID}}
GRDF_CLIENT_SECRET: {{GRDF_CLIENT_SECRET}}
type: Opaque
......@@ -16,9 +16,10 @@ import (
)
var (
httpsPort = common.IntValueFromEnv("HTTPS_PORT", 443) // HTTPS port to serve on
debugMode = common.BoolValueFromEnv("DEBUG_MODE", false) // Debug mode, disable Secure attribute for cookies
mockOAuth2 = common.BoolValueFromEnv("MOCK_OAUTH2", false) // Enable mock OAuth2 login
httpsPort = common.IntValueFromEnv("HTTPS_PORT", 443) // HTTPS port to serve on
debugMode = common.BoolValueFromEnv("DEBUG_MODE", false) // Debug mode, disable Secure attribute for cookies
mockOAuth2 = common.BoolValueFromEnv("MOCK_OAUTH2", false) // Enable mock OAuth2 login
fetchGrdfToken = common.BoolValueFromEnv("FETCH_GRDF_TOKEN", true) // HTTPS port to serve on
)
func main() {
......@@ -41,23 +42,27 @@ func main() {
fmt.Println("Mock OAuth2 server Listening on: http://localhost" + mockOAuth2Port)
}
// Call the function immediately when the server starts
models.FetchGRDFAuthAPI()
// then call GRDF auth api every two hours
ticker := time.NewTicker(time.Hour * 2)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
models.FetchGRDFAuthAPI()
case <-quit:
ticker.Stop()
return
// If needed, we shall request a new GRDF token every 2-hours
if fetchGrdfToken {
// Call the function immediately when the server starts
models.FetchGRDFAuthAPI()
// then call GRDF auth api every two hours
ticker := time.NewTicker(time.Hour * 2)
go func() {
for {
select {
case <-ticker.C:
models.FetchGRDFAuthAPI()
case <-quit:
ticker.Stop()
return
}
}
}
}()
}()
}
// Deletes outdated consents every 24h
dh := models.NewDataHandler()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment