Skip to content

Commit d427e73

Browse files
committed
run entity collection not on request but on intervals
1 parent ed5ce58 commit d427e73

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

docs/config/federation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,20 @@ It is generally more performant to rely on an external endpoint.
286286
use_entity_collection_endpoint: true
287287
```
288288

289+
290+
## `entity_collection_interval`
291+
<span class="badge badge-purple" title="Value Type">integer</span>
292+
<span class="badge badge-blue" title="Default Value">5</span>
293+
<span class="badge badge-green" title="If this option is required or optional">optional</span>
294+
295+
The `entity_collection_interval` option defines in which interval OFFA will
296+
query the Entity Collection Endpoint or do entity collection on its own. The
297+
time is given in minutes!
298+
299+
??? file "config.yaml"
300+
301+
```yaml
302+
federation:
303+
entity_collection_interval: 60
304+
```
305+

internal/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type federationConf struct {
4444
TrustMarks []*pkg.EntityConfigurationTrustMarkConfig `yaml:"trust_marks"`
4545
UseResolveEndpoint bool `yaml:"use_resolve_endpoint"`
4646
UseEntityCollectionEndpoint bool `yaml:"use_entity_collection_endpoint"`
47+
EntityCollectionInterval int64 `yaml:"entity_collection_interval"`
4748
}
4849

4950
type sessionConf struct {
@@ -287,7 +288,10 @@ func MustLoadConfig() {
287288
TTL: 3600,
288289
CookieName: "offa-session",
289290
},
290-
Federation: federationConf{ClientName: "OFFA - Openid Federation Forward Auth"},
291+
Federation: federationConf{
292+
ClientName: "OFFA - Openid Federation Forward Auth",
293+
EntityCollectionInterval: 5,
294+
},
291295
}
292296
if err := yaml.Unmarshal(data, conf); err != nil {
293297
log.Fatal(err)

internal/server/login.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ func addLoginHandlers(s fiber.Router) {
3636
s.Get("/redirect", codeExchange)
3737
}
3838

39-
func showLoginPage(c *fiber.Ctx) error {
39+
var opOptions string
40+
41+
func scheduleBuildOPOptions() {
42+
ticker := time.NewTicker(time.Duration(config.Get().Federation.EntityCollectionInterval) * time.Minute) // Replace 5 with your desired interval
43+
44+
go buildOPOptions()
45+
46+
go func() {
47+
for range ticker.C {
48+
buildOPOptions()
49+
}
50+
}()
51+
}
52+
53+
func buildOPOptions() {
4054
const opOptionFmt = `<option value="%s">%s</option>`
4155
var options string
4256
filters := []pkg.EntityCollectionFilter{}
@@ -70,12 +84,16 @@ func showLoginPage(c *fiber.Ctx) error {
7084
),
7185
)
7286
}
87+
opOptions = options
88+
}
89+
90+
func showLoginPage(c *fiber.Ctx) error {
7391
var img string
7492
if config.Get().Federation.LogoURI != "" {
7593
img = fmt.Sprintf(`<img src="%s" alt="%s" class="logo"/>`, config.Get().Federation.LogoURI, "Logo")
7694
}
7795
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
78-
return c.SendString(fmt.Sprintf(loginHtml, config.Get().Federation.ClientName, img, options, c.Query("next")))
96+
return c.SendString(fmt.Sprintf(loginHtml, config.Get().Federation.ClientName, img, opOptions, c.Query("next")))
7997
}
8098

8199
type stateData struct {

internal/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var fullLoginPath string
3434

3535
// Init initializes the server
3636
func Init() {
37+
scheduleBuildOPOptions()
3738
initHtmls()
3839
initFederationEntity()
3940
server = fiber.New(serverConfig)

0 commit comments

Comments
 (0)