-
Notifications
You must be signed in to change notification settings - Fork 13
/
teamcache.go
86 lines (70 loc) · 1.94 KB
/
teamcache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package agent
import (
"fmt"
"os"
"time"
"github.com/Axway/agent-sdk/pkg/apic/definitions"
"github.com/Axway/agent-sdk/pkg/jobs"
"github.com/Axway/agent-sdk/pkg/util/log"
)
// QA EnvVars
const qaTeamCacheInterval = "QA_CENTRAL_TEAMCACHE_INTERVAL"
type centralTeamsCache struct {
jobs.Job
}
func (j *centralTeamsCache) Ready() bool {
return true
}
func (j *centralTeamsCache) Status() error {
return nil
}
func (j *centralTeamsCache) Execute() error {
platformTeams, err := agent.apicClient.GetTeam(map[string]string{})
if err != nil {
return err
}
if len(platformTeams) == 0 {
return fmt.Errorf("error: no teams returned from central")
}
for _, team := range platformTeams {
savedTeam := agent.cacheManager.GetTeamByID(team.ID)
if savedTeam == nil {
agent.cacheManager.AddTeam(&team)
}
}
return nil
}
// registerTeamMapCacheJob -
func registerTeamMapCacheJob() {
job := ¢ralTeamsCache{}
// execute the job on startup to populate the team cache
job.Execute()
jobs.RegisterIntervalJobWithName(job, getJobInterval(), "Team Cache")
}
func getJobInterval() time.Duration {
interval := time.Hour
// check for QA env vars
if val := os.Getenv(qaTeamCacheInterval); val != "" {
if duration, err := time.ParseDuration(val); err == nil {
log.Tracef("Using %s (%s) rather than the default (%s) for non-QA", qaTeamCacheInterval, val, time.Hour)
interval = duration
} else {
log.Tracef("Could not use %s (%s) it is not a proper duration", qaTeamCacheInterval, val)
}
}
return interval
}
// GetTeamByName - Returns the PlatformTeam associated with the name
func GetTeamByName(name string) *definitions.PlatformTeam {
if agent.cacheManager != nil {
return agent.cacheManager.GetTeamByName(name)
}
return nil
}
// GetTeamByID - Returns the PlatformTeam associated with the id
func GetTeamByID(id string) *definitions.PlatformTeam {
if agent.cacheManager != nil {
return agent.cacheManager.GetTeamByID(id)
}
return nil
}