Skip to content

Commit 4d21adf

Browse files
authored
Merge pull request #81 from nadvornik/filter_ent
Use peripheral_server entitlement
2 parents 8fc7d7d + 455f199 commit 4d21adf

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

integration_tests/hub_infrastructure.go

+13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func initServer(port int64, uyuniServer *UyuniServer) {
3131
codec.RegisterMapping("auth.login", "UyuniServer.Login", parser.LoginRequestParser)
3232
codec.RegisterMapping("auth.logout", "UyuniServer.Logout", parser.LoginRequestParser)
3333
codec.RegisterMapping("system.listSystems", "UyuniServer.ListSystems", parser.LoginRequestParser)
34+
codec.RegisterMapping("system.listSystemsWithEntitlement", "UyuniServer.ListSystemsWithEntitlement", parser.LoginRequestParser)
3435
codec.RegisterMapping("system.listUserSystems", "UyuniServer.ListUserSystems", parser.LoginRequestParser)
3536
codec.RegisterMapping("system.listFqdns", "UyuniServer.ListFqdns", parser.LoginRequestParser)
3637

@@ -108,6 +109,18 @@ func (u *UyuniServer) ListSystems(r *http.Request, args *struct{ SessionKey stri
108109
return nil
109110
}
110111

112+
func (u *UyuniServer) ListSystemsWithEntitlement(r *http.Request, args *struct{ SessionKey, Entitlement string }, reply *struct{ Data []SystemInfoResponse }) error {
113+
log.Println(u.serverName+" -> System.ListSystemsWithEntitlement", args.SessionKey)
114+
if args.SessionKey == u.sessionKey {
115+
minions := make([]SystemInfoResponse, 0, len(u.minionsByID))
116+
for _, minion := range u.minionsByID {
117+
minions = append(minions, SystemInfoResponse{minion.id, minion.name})
118+
}
119+
reply.Data = minions
120+
}
121+
return nil
122+
}
123+
111124
func (u *UyuniServer) ListFqdns(r *http.Request, args *struct {
112125
SessionKey string
113126
ServerId int64

uyuni/uyuni_topology_info_retriever.go

+35-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
)
99

1010
const (
11-
listSystemsPath = "system.listSystems"
12-
listSystemFQDNsPath = "system.listFqdns"
13-
listUserSystemsPath = "system.listUserSystems"
14-
systemIDField = "id"
11+
listSystemsPath = "system.listSystems"
12+
listSystemsWithEntitlementPath = "system.listSystemsWithEntitlement"
13+
listSystemFQDNsPath = "system.listFqdns"
14+
listUserSystemsPath = "system.listUserSystems"
15+
systemIDField = "id"
16+
peripheralServerEntitlement = "peripheral_server"
1517
)
1618

1719
type uyuniTopologyInfoRetriever struct {
@@ -29,23 +31,50 @@ func (h *uyuniTopologyInfoRetriever) RetrieveUserServerIDs(endpoint, sessionKey,
2931
log.Printf("Error ocurred while trying to login into the user systems: %v", err)
3032
return nil, err
3133
}
34+
35+
allServers, err := h.ListServerIDs(endpoint, sessionKey)
36+
if err != nil {
37+
return nil, err
38+
}
39+
3240
userServersSlice := userServers.([]interface{})
3341

3442
serverIDs := make([]int64, 0, len(userServersSlice))
3543
for _, userSystem := range userServersSlice {
3644
serverID := userSystem.(map[string]interface{})[systemIDField].(int64)
37-
serverIDs = append(serverIDs, serverID)
45+
if contains(allServers, serverID) {
46+
serverIDs = append(serverIDs, serverID)
47+
}
3848
}
3949
return serverIDs, nil
4050
}
4151

52+
func contains(s []int64, v int64) bool {
53+
for _, lv := range s {
54+
if lv == v {
55+
return true
56+
}
57+
}
58+
59+
return false
60+
}
61+
4262
func (h *uyuniTopologyInfoRetriever) ListServerIDs(endpoint, sessionKey string) ([]int64, error) {
43-
systemList, err := h.uyuniCallExecutor.ExecuteCall(endpoint, listSystemsPath, []interface{}{sessionKey})
63+
systemList, err := h.uyuniCallExecutor.ExecuteCall(endpoint, listSystemsWithEntitlementPath, []interface{}{sessionKey, peripheralServerEntitlement})
4464
if err != nil {
4565
log.Printf("Error occured while retrieving the list of serverIDs: %v", err)
4666
return nil, err
4767
}
4868
systemsSlice := systemList.([]interface{})
69+
if len(systemsSlice) == 0 {
70+
// No entitled servers - fallback to full list, for legacy HUB server
71+
systemList, err = h.uyuniCallExecutor.ExecuteCall(endpoint, listSystemsPath, []interface{}{sessionKey})
72+
if err != nil {
73+
log.Printf("Error occured while retrieving the list of serverIDs: %v", err)
74+
return nil, err
75+
}
76+
systemsSlice = systemList.([]interface{})
77+
}
4978

5079
systemIDs := make([]int64, len(systemsSlice))
5180
for i, system := range systemsSlice {

0 commit comments

Comments
 (0)