-
Notifications
You must be signed in to change notification settings - Fork 59
/
server_collector.go
56 lines (46 loc) · 1.28 KB
/
server_collector.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
package gitlab
import (
"github.com/Legit-Labs/legitify/internal/collected/gitlab_collected"
"log"
"github.com/Legit-Labs/legitify/internal/clients/gitlab"
"github.com/Legit-Labs/legitify/internal/collectors"
"github.com/Legit-Labs/legitify/internal/common/namespace"
"golang.org/x/net/context"
)
type serverCollector struct {
collectors.BaseCollector
Client *gitlab.Client
Context context.Context
isServer bool
}
func NewServerCollector(ctx context.Context, client *gitlab.Client) collectors.Collector {
c := &serverCollector{
BaseCollector: collectors.NewBaseCollector(namespace.Enterprise),
Client: client,
Context: ctx,
isServer: client.IsServer(),
}
return c
}
func (c *serverCollector) CollectTotalEntities() int {
if c.isServer {
return 1
}
return 0
}
func (c *serverCollector) Collect() collectors.SubCollectorChannels {
return c.WrappedCollection(func() {
if !c.isServer {
return
}
settings, _, err := c.Client.Client().Settings.GetSettings()
if err != nil {
log.Printf("failed to collect server settings %s", err)
return
}
entity := gitlab_collected.NewServer(c.Client.ServerUrl(), settings)
c.CollectDataWithContext(entity, entity.CanonicalLink(),
newServerCollectionContext())
c.CollectionChangeByOne()
})
}