Añadir una Web application por código
Hola comunidad,
Voy a publicar varios artículos de como realizar acciones que puedes hacer desde el web portal, pero por código.
Hoy.... Web Applications por código
Introducción
Si quieres añadir una nueva Web Application, sueles utilizar la opción de administración - Seguridad - Aplicaciones - Aplicaciones web
Entonces añadimos el rol para usar en la aplicación
Pero, si no tienes acceso al portal de gestión, puedes hacerlo por código.
RegisterWebApplication
Con este método, puedes registar una nueva aplicación web por código.
/// Register a web application. It configure only services that doesn't need special access. /// <ul> /// <li><var>pNameSpace</var> Name of the namespace when the web application runs.</li> /// <li><var>pName</var> Service name to create/update.</li> /// <li><var>pClassName</var> Name of class to run.</li> /// <li><var>pDescription</var> Comment to include.</li> /// </ul> /// <example> /// // Add web api /// Do myClass.RegisterWebApplication("SAMPLES","/myApp/api","Host.RS.Rest","This is my api rest")</example> ClassMethod RegisterWebApplication(pNameSpace As %String, pName As %String, pClassName As %String, pDescription As %String = "") As %Status { New $Namespace Set $Namespace = "%SYS" Set ret = $$$OK Set spec("AutheEnabled") = $$$AutheUnauthenticated Set spec("NameSpace") = pNameSpace Set spec("Description") = pDescription Set spec("IsNameSpaceDefault") = $$$NO Set spec("DispatchClass") = pClassName Set spec("MatchRoles")=":%All" If ('##class(Security.Applications).Exists(pName)) { Write !,"Creating Web application """_pName_"""..." Set ret = ##class(Security.Applications).Create(pName, .spec) Write !, "Web application """_pName_""" is created." } Else { // ensure configuration matches in case of updating from old terminal versions Write !, "Updating web application """_pName_"""..." Set ret = ##class(Security.Applications).Modify(pName, .spec) Write !, "Web application """_pName_""" is updated." } Return ret }
Por defecto, usa el rol %All, pero puedes modificarlo según tus necesidades
RemoveWebApplication
/// Remove a web application /// <ul> /// <li><var>pName</var> Name of web application to remove.</li> /// <li><var>pClassName</var> Name of the class linked to the web application.</li> /// </ul> /// <example> /// // Remove web api /// Do myClass.RemoveWebApplication("/myApp/api","Host.RS.Rest")</example> ClassMethod RemoveWebApplication(pName As %String, pClassName As %String) { New $Namespace Set $Namespace = "%SYS" Set ret = $$$OK If (##class(Security.Applications).Exists(pName)) { Do ##class(Security.Applications).Get(pName, .props) If (props("DispatchClass") '= pClassName) { Write !, "Web application doesn't refer to DispatchClass "_pClassName } Else { Write !, "Deleting Web application """_pName_"""..." Set ret = ##class(Security.Applications).Delete(pName) Write !, "Web application """_pName_""" was successfully deleted." } } Return ret }
Por seguridad, el nombre de la clase es necesario para comprobar que no estás eliminando una aplicación web por error.
Espero que os sea útil.
Saludos,
Kurro Lopez