forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorgs.go
86 lines (71 loc) · 2.18 KB
/
orgs.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 services
import (
"context"
"errors"
"fmt"
"sync"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
const (
ROOT_ORG_ID = "root"
)
var (
mu sync.Mutex
org_manager OrgManager
NotFoundError = errors.New("Org not found")
)
// Currently the org manager is the only binary wide global - all
// other services use the org manager to find other services.
func GetOrgManager() (OrgManager, error) {
mu.Lock()
defer mu.Unlock()
if org_manager == nil {
return nil, errors.New("Org Manager not initialized")
}
return org_manager, nil
}
func RegisterOrgManager(m OrgManager) {
mu.Lock()
defer mu.Unlock()
org_manager = m
}
// hold all the services for each org
type ServiceContainer interface {
FrontendManager() (FrontendManager, error)
Journal() (JournalService, error)
ClientInfoManager() (ClientInfoManager, error)
Indexer() (Indexer, error)
BroadcastService() (BroadcastService, error)
Inventory() (Inventory, error)
VFSService() (VFSService, error)
Labeler() (Labeler, error)
RepositoryManager() (RepositoryManager, error)
HuntDispatcher() (IHuntDispatcher, error)
Launcher() (Launcher, error)
NotebookManager() (NotebookManager, error)
ClientEventManager() (ClientEventTable, error)
ServerEventManager() (ServerEventManager, error)
Notifier() (Notifier, error)
ACLManager() (ACLManager, error)
}
// The org manager manages multi-tenancies.
type OrgManager interface {
GetOrgConfig(org_id string) (*config_proto.Config, error)
OrgIdByNonce(nonce string) (string, error)
CreateNewOrg(name, id string) (*api_proto.OrgRecord, error)
ListOrgs() []*api_proto.OrgRecord
GetOrg(org_id string) (*api_proto.OrgRecord, error)
DeleteOrg(ctx context.Context, org_id string) error
// The manager is responsible for running multiple services - one
// for each org. This ensures org services are separated out and
// one org can not access data from another org.
Services(org_id string) ServiceContainer
}
func GetOrgName(config_obj *config_proto.Config) string {
if config_obj.OrgId == "" {
return "Root Org"
}
return fmt.Sprintf("Org %v (%v)",
config_obj.OrgName, config_obj.OrgId)
}