Skip to content

Using Multi Tenancy

Arturo Salazar edited this page Mar 24, 2014 · 6 revisions

Here's a walk-through of how to use a Multi-Tenancy, as of version 0.7.0 of the gem.

The Basics

There are three objects you will use when working with Multi-Tenancy.

  • SiloProfile - Defines the features available to a silo and can be used limit the features available to each silo.
  • Silo - Can be used to define your tenant and their asset and user limitations.
  • MultiTenantUser - Is similar to user but can also define access and permissions across different silos.

The Connection has methods for getting a summary for each object:nsc.list_silo_profiles nsc.list_silos nsc.list_silo_users

There are also methods in the Connection to delete each object:delete_silo_profile(id) delete_silo_user(id) delete_silo(id)

The following methods are shared across each object: load(nsc, id) save(nsc) delete(nsc)

The copy(nsc, id) method is shared between Silo and SiloProfile.

Modifying

The following example loads an existing silo profile and restricts the text format from being used in reprots.

profile = SiloProfile.load(nsc, 'pci_profile')
profile.restricted_report_formats << 'text'
profile.save(nsc)

Reduce the asset count for a Silo:

silo = Silo.load(nsc, 'default')
silo.max_assets = 100
silo.save(nsc)

Give a user admin access to silo1 and user access to sites 3,7 and groups 4,8 of silo2:

user = MultiTenantUser.load(nsc, 25)
user.silo_access << SiloAccess.new do |access|
  access.silo_id = 'silo1'
  access.role_name = Role::GLOBAL_ADMINISTRATOR
  access.default = false
  access.all_sites = true
  access.all_groups = true
end
user.silo_access << SiloAccess.new do |access|
  access.silo_id = 'silo2'
  access.role_name = Role::USER
  access.default = false
  access.all_sites = false
  access.sites = [3,7]
  access.all_groups = false
  access.groups = [4,8]
end
user.save(nsc)