Skip to content

Commit 3e6ae4e

Browse files
authored
Merge pull request #54 from intersystems-community/proxy-registry
multi-namespace uplinks config
2 parents 255e3d2 + 7c3463e commit 3e6ae4e

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/cls/ZPM/UpLink.cls

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,58 @@ ClassMethod ReadUplinksFromFile() As %Status
296296
// DateTime hasn't changed - skip file
297297
Return sc
298298
}
299-
set obj = ##class(YAML.Utils).FileToJSON("/usr/irissys/zpm-registry.yaml", .sc)
299+
set obj = ##class(YAML.Utils).FileToJSON(tFilename, .sc)
300+
300301
$$$ThrowOnError(sc)
301-
Set joUplinks = obj."uplinks"
302-
&sql(TRUNCATE TABLE ZPM.UpLink)
303-
Set iter = joUplinks.%GetIterator()
304-
Set position = 0
305-
While iter.%GetNext(.key , .joOneUplink) {
306-
Set position = position + 1
307-
Do ..AddUplink(key, joOneUplink.url, joOneUplink."allow_packages", position)
302+
Set filemodificationTS = tFile.DateModified
303+
If (..IsDefaultConfig(obj)) {
304+
// namespace doesn't specified
305+
Do ..SaveUplinks(obj."uplinks", filemodificationTS)
306+
} Else{
307+
// namespace specified - search for current ns settings
308+
Set iter = obj.%GetIterator()
309+
Set ns = $$$lcase($NAMESPACE)
310+
While iter.%GetNext(.key , .uplinks) {
311+
If (ns = $$$lcase(key)) {
312+
Do ..SaveUplinks(uplinks."uplinks", filemodificationTS)
313+
}
314+
}
308315
}
309-
Set ^zpmregistry("filemodified") = tFile.DateModified
310316
} Catch ex {
311317
Set sc = ex.AsStatus()
312318
}
313319
Return sc
314320
}
315321

322+
ClassMethod SaveUplinks(joUplinks As %DynamicObject, filemodificationTS As %String) As %Status
323+
{
324+
&sql(TRUNCATE TABLE ZPM.UpLink)
325+
Set iter = joUplinks.%GetIterator()
326+
Set position = 0
327+
While iter.%GetNext(.key , .joOneUplink) {
328+
Set position = position + 1
329+
Do ..AddUplink(key, joOneUplink.url, joOneUplink."allow_packages", position)
330+
}
331+
Set ^zpmregistry("filemodified") = filemodificationTS
332+
}
333+
334+
ClassMethod IsDefaultConfig(obj As %DynamicObject) As %Boolean
335+
{
336+
Try {
337+
If (obj.%GetTypeOf("uplinks")="object") {
338+
Set iter = obj.uplinks.%GetIterator()
339+
If iter.%GetNext(.key , .joOneUplink) {
340+
If (joOneUplink.%IsDefined("url")) {
341+
return 1
342+
}
343+
}
344+
}
345+
} Catch ex {
346+
return 0
347+
}
348+
return 0
349+
}
350+
316351
ClassMethod AddUplink(name, url, allowList, position) As %Status
317352
{
318353
If (url = "") { return 0 }

0 commit comments

Comments
 (0)