Question
· Jun 11, 2023

Can a ZPM / IPM package be required to install in %SYS only?

I am trying to write the module.xml for a package that creates a web application associated with the %SYS namespace.

I didn't find a way of specifying that the CSPApplication tag should create the app for a specific namespace. It apparently gets set up to use the namespace in which the package install command gets run. This contrasts with how an installer manifest works, where the <CSPApplication> tag is put inside a <Namespace> tag.

So I wondered if I could make my package fail installation if the current namespace isn't %SYS. My package doesn't need to load anything, only create the web app. So I'd prefer not the have to load a class purely in order to invoke a method in it and have this return a failure status if $namespace'="%SYS"

I found https://github.com/intersystems/ipm/issues/106 which may be relevant but doesn't yet seem to have been implemented.

Discussion (3)3
Log in or sign up to continue

Maybe you can use a generator method somewhere in your code to create the WebApp, something like:

ClassMethod CreateApplication() As %Status [ CodeMode = objectgenerator ]
{
Set $ZTrap="Error"
New $Namespace
Write !,"Creating XXX API",!
Set URL="/xxx"
Set $Namespace="%SYS"
If ##class(Security.Applications).Exists(URL) {
Return $$$OK
}
Set Props("Name")=URL
Set Props("NameSpace")="%SYS"
Set Props("Description")="XXX API endpoint"
Set Props("AutheEnabled")=64 ; unauthenticated
Set Props("DispatchClass")="API.Handler.Class"
Set Props("Type")=2 ; CSP App
Set Props("MatchRoles")=":%All"
Set sc=##class(Security.Applications).Create(URL,.Props)
Return sc
Error
Set $ZTrap=""
Return $$$ERROR($$$GeneralError,"ErrorTrap: "_$ZError)
}

Thanks for the suggestions. The solution I came up with can be seen at https://github.com/intersystems-community/vscode-per-namespace-settings

It installs a class, runs a method in it to create the web app so it uses the correct namespace, then deletes the class. Actually, it deletes a whole package which I named %Z.IPM.Bootstraps with the idea that this could be by convention a package reserved for exactly this purpose.

I had to devise a little hack to prevent the deletion from happening during packaging, otherwise the web-app-creating class wouldn't actually be in the package, meaning end-user installation would fail.

Maybe there's already a better way of achieving the effect I wanted.