Question
Evgeny Shvarov · Feb 25, 2017

How to deploy resources and roles?

Hi, Community!

Consider I have ResourceA which is used by role RoleA in dev environment and want to deploy it with the solution on a target system.

Would you please share the best practices to make it?

Thank you in advance!

00
0 8 307 2

Replies

There are many predefined methods defined by Cache under Security.* package to maintain/manage Roles/Users/Resources ...ect.

Specific to your query, you can use below command to export/import Roles:

Write ##class(Security.Roles).Export("C:\RolesExport.xml")
Write ##class(Security.Roles).Import("C:\RolesExport.xml")

Roles: 
Please refer to below class doc for more: http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25sys&CLASSNAME=Security.Roles&CSPCHD=000000000000gt0xiwWBxf8D77QROEE$c2JR50xdHrcUuUzSzc&CSPSHARE=1

Resources:
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25sys&CLASSNAME=Security.Roles&CSPCHD=000000000000gt0xiwWBxf8D77QROEE$c2JR50xdHrcUuUzSzc&CSPSHARE=1

In case it's not obvious to people, the Security package is only available in the %SYS namespace.

True John, agree with you. Its only available from %SYS.

Thank you, Bachhar for the thorough and full answer!

What if I want to export Resources only and then manage it on a target system manually?

It's not obvious how to export Resources only.

Write ##class(Security.Resources).Export("C:\Resources.xml")
Write ##class(Security.Resources).Import("C:\Resources.xml")

Note that apart from Export and Import options -

If you are using a %Installer Manifest for your deployment (for any environment - test or prod) - you can include in that manifest also the creation of Security elements such as Resources and Roles, etc.

For example:

<Resource
    Name="%accounting_user" 
    Description="Accounting"
    Permission="RW"/>

And:

<Role 
    Name="%DB_USER"
    Description="Database user"
    Resources="MyResource:RW,MyResource1:RWU"
    RolesGranted= />

See more information here (in the docs).

[Defining a Role as part of a manifest is also included in an example in [@Eduard Lebedyuk]'s post here]