Written by

Question Rubens Silva · Mar 9, 2020

How to create a REST web application using a Installer manifest

Just like the title says, I'm attempting to find a way to create a web application that instead of serving CSP files, it uses a dispatch class.
I searched for clues in the documentation, but the CSPApplication tag seems to be exclusively for CSP file-based applications.
I'm trying to avoid implementing a workaround such as using the Invoke tag to call the Security.Applications to generate the web application but I might be forced to do so, even though it's unpleasant if I had to say...
So, is there an official way to execute this task?

Comments

Eduard Lebedyuk · Mar 9, 2020

Invoke is the way to go.

ClassMethod CreateWebApp(pVars, pLogLevel, tInstaller) As %Status
{
    Set Namespace=tInstaller.Evaluate("${Namespace}")
    Do tInstaller.PushNS("%SYS")
    Do ##class(Security.System).GetInstallationSecuritySetting(.security)
    If (security="None") {
        Set cspProperties("AutheEnabled") = $$$AutheUnauthenticated
    } Else {
        Set cspProperties("AutheEnabled") = $$$AutheCache // Password
    }
    Set cspProperties("NameSpace") = Namespace
    Set cspProperties("IsNameSpaceDefault") = $$$YES
    Set cspProperties("DispatchClass") = "MDX2JSON.REST"
        Set cspProperties("UseCookies") = $$$YES
    Set tSC = ##class(Security.Applications).Create("/"_Namespace, .cspProperties)
    Do tInstaller.PopNS()
    If $$$ISERR(tSC) Throw ##class(%Installer.Exception).CreateFromStatus(tSC)
    Quit $$$OK
}

And invoke with

<RunInstall Class="MDX2JSON.Installer" Method="CreateWebApp"/>
0
Peter Steiwer · Mar 9, 2020

The code for CSPApplication appears to accept DispatchClass (even though documentation does not say it). I have not yet tested it. But in PivotSubscriptions I create my WebApp the way that Eduard says, but I was planning on changing it to use %Installer this week or next.

0
Rubens Silva  Mar 9, 2020 to Peter Steiwer

I might have to check the IRIS version, because my Caché 2018 doesn't have any traces of the DispatchClass configuration.
Method CSPApplication(
pUrl As %String,
pNamespace As %String,
pDescription As %String,
pDirectory As %String,
pResource As %String,
pRecurse As %String,
pLoginClass As %String,
pGrant As %String,
pCookiePath As %String,
pAuthMethods As %Integer,
pLockCSPName As %Boolean,
pEventClass As %String,
pDefaultTimeout As %Integer,
pDefaultSuperclass As %String,
pUseSessionCookie As %Integer,
pServeFiles As %Boolean,
pServeFilesTimeout As %Integer,
pCustomErrorPage As %String,
pPackageName As %String,
pChangePasswordPage As %String,
pGroupById As %String = "",
pCspZenEnabled As %Boolean = 1,
pInboundWebServicesEnabled As %Boolean = 1,
pTwoFactorEnabled As %Boolean = 0,
pIsNameSpaceDefault As %Boolean = 0,
pPermittedClasses As %String = "",
pAutoCompile As %Boolean = 1) [ Internal ]

0
Peter Steiwer  Mar 9, 2020 to Rubens Silva

Yes, it does look like it was included for IRIS

0
Peter Steiwer  Mar 10, 2020 to Rubens Silva

I tried this out and it works as expected:

        <CSPApplication
            Url="/api/pivotsubscriptionsunsubscribe"
            Directory="${CSPDIR}"
            DispatchClass="PivotSubscriptions.UI.Unsubscribe"
            AuthenticationMethods="64"
        />

0
Evgeny Shvarov  Mar 10, 2020 to Peter Steiwer

Wow. This is cool! And what is the version?

0
Peter Steiwer  Mar 10, 2020 to Evgeny Shvarov

I tested this in a 2020.2 IRIS development build.

(Also my code example will be included in PivotSubscriptions v1.6 wink)

0
Peter Steiwer  Mar 10, 2020 to Peter Steiwer

I have also tested it in IRIS 2018.1 and 2019.1

0
Peter Steiwer  Mar 10, 2020 to Peter Steiwer

After further testing, it looks like this isn't working as I originally thought. It looks like our only option at this point is to use Security.Applications sad

0
Rubens Silva  Mar 10, 2020 to Peter Steiwer

From your code above I see that you attempted to use both Directory and DispatchClass attributes. Have you tried removing the Directory attribute?

0
Peter Steiwer  Mar 11, 2020 to Rubens Silva

I seem to get an error when I do not specify Directory:

2020-03-11 08:29:03 0 PivotSubscriptions.Installer: ERROR #5001: - ERROR when creating Portal application: Application name, namespace and directory must not be null

0
Rubens Silva  Mar 11, 2020 to Peter Steiwer

Indeed, I got this error too. However if I use a dummy directory it accepts.
I haven't used this feature yet because I must change plenty of things to actually consume that REST application. But the way I'm seeing things so far I guess it would work.
So what if you provide a dummy directory like: "/tmp/dummycsp" as well?

0
Peter Steiwer  Mar 11, 2020 to Rubens Silva

Even though it isn't throwing an error it is not creating the Web App correctly. If you view your Web App, the Dispatch class is not set

0
Rubens Silva  Mar 12, 2020 to Peter Steiwer

Ahh, yes, it could be used that way too.
Either way, basically only the schema is supporting the DispatchClass, the engine itself doesn't, making it looks like a feature that's in development. So I'm sure that will get this feature on the near future.
Well... here's how I did it:
https://github.com/rfns/iris-ci/blob/master/ci/App/Installer.cls

0
Rubens Silva  Mar 9, 2020 to Evgeny Shvarov

Can I use the ZPM client like a standalone the same way it works when using the %Installer manifest? Bu that I mean, just calling the ZPM to parse the manifest and install it without relying on the registry and the CLI for now, because all the code I want to import is already local, I just need to create a web application that uses the DispatchClass property.

0
Evgeny Shvarov  Mar 9, 2020 to Rubens Silva

I don't know, actually. Tagging @Nikolay Solovyev, @Timothy Leavitt  and @Dmitry.Maslennikov.

But IMHO zpm is overkill for this if you don't plan to deploy using registry and zpm client. Maybe just a few ObjectScript calls will help like in this Dockerfile.

HTH


 

0
Rubens Silva  Mar 9, 2020 to Evgeny Shvarov

Looks like the new version of the %Installer for IRIS already supports this setting.
But it might still be helpful to clear that question about the ZPM for other circunstances.

0
Dmitry Maslennikov  Mar 9, 2020 to Rubens Silva

Yes, for sure, you can install any packages locally

ZPM> load /path/to/package -v

it can be as a folder, or as file tgz, which you can get with command

ZPM> package-name package -v

-v is optional, to get more logs for debugging

0
Timothy Leavitt  Mar 9, 2020 to Dmitry Maslennikov

Agreed, I tend to use zpm for my own projects even if I don't intend to distribute. Between declaring dependencies, simpler running of unit tests, ability to script more things with my project than just "install" - it's just generally handy.

0