Browse Source

deteministically search via subject

Mark deVilliers 2 years ago
parent
commit
88301efeff
3 changed files with 9 additions and 5 deletions
  1. 4 2
      node/api/entitlement_store.go
  2. 3 2
      node/api/metadata_store.go
  3. 2 1
      node/device_manager.go

+ 4 - 2
node/api/entitlement_store.go

@@ -81,8 +81,9 @@ func (e entitlementMap) FindForSubject(subject utils.Subject) (Entitlement, bool
81 81
 	perms := subject.Perms()
82 82
 
83 83
 	// TODO : optimise optimise optimise - rewrite as a trie
84
-	for _, ent := range e.store {
85
-		for _, s := range perms {
84
+	for _, s := range perms {
85
+		for _, ent := range e.store {
86
+
86 87
 			if ent.Subject == s {
87 88
 				return ent, true
88 89
 			}
@@ -135,6 +136,7 @@ func (e entitlementMap) AppendOrReplaceOnSubject(ent Entitlement) {
135 136
 
136 137
 	if found {
137 138
 		ent.UID = existing.UID
139
+		ent.AccessLevel = existing.AccessLevel
138 140
 		e.store[existing.UID] = ent
139 141
 		return
140 142
 	}

+ 3 - 2
node/api/metadata_store.go

@@ -37,8 +37,9 @@ func (m *MetadataStore) FindBySubject(subject utils.Subject) (Metadata, bool) {
37 37
 	perms := subject.Perms()
38 38
 
39 39
 	// TODO : optimise optimise optimise - rewrite as a trie
40
-	for _, m := range m.store {
41
-		for _, s := range perms {
40
+
41
+	for _, s := range perms {
42
+		for _, m := range m.store {
42 43
 			if m.Subject == s {
43 44
 				return m, true
44 45
 			}

+ 2 - 1
node/device_manager.go

@@ -85,7 +85,7 @@ func (d *device_manager) loop() {
85 85
 				// ensure we have metadata for the key
86 86
 				// the default is to copy the subjects parents metadata.
87 87
 				// Our system is loosely bound between devices
88
-				// and data - we don't catalog a fixed dataset from the devices.
88
+				// and data - we don't know the fixed dataset from a specific device.
89 89
 				m, found := d.metaStore.FindBySubject(subject)
90 90
 
91 91
 				if !found {
@@ -95,6 +95,7 @@ func (d *device_manager) loop() {
95 95
 
96 96
 				currentSubject := subject.String()
97 97
 				ss, _ := utils.ParseSubject(ent.Subject)
98
+
98 99
 				if ss.IsRoot() {
99 100
 
100 101
 					m.Subject = currentSubject