Appearance
Remote Context
Vasat supports microservices and can have elements of business logic scattered amongst multiple servers.
In some cases having a Data Model reside on one server, but be used on another server is desirable.
A RemoteModelContext[A]
allows for this very easily.
scala
@JSONModel // Makes the mode have a JSON representation
case class Account(
name:String,
address:String
)
@RemoteAuto // generates the ModelContext
class ArticleRepo(val remoteHost:RemoteSignedWebservice) extends RemoteContext[Account]
Similar to a DBModelContext. Using a Macro is the quickest way to create a RemoteModelContext.
Once created, The location of the remoteHost needs to be specified. This is the Vasat server that stores the object in question.
A simple RemoteSginedWebservice on a play project can look like this:
scala
@Singleton
class RemoteHost @Inject()(val siteInitService:SiteInitService) extends RemoteSignedWebservice{
val remoteHost = "https://my_account_site"
override def site = siteInitService.siteObject
}
Configuring the 'Remote'
Route
The remote site requires a special route that must be enabled.
routes
POST /crud vasat.play.controllers.RemoteCRUDController.doCRUD
Authentication
RemoteModelContexts can work in 2 ways with regards to authentication
- Web / OAuth
If the 'local' vasat server is exposing the remote servers endpoint. eg:
https://mylocal_site/api/Account -> https://my_account_site/api/Account
The access token used on the local request is simply forwarded to the remote
- Site Authentication
Through the trust policy of the Site
objects between the local and remote Vasat a level of access can be defined. This can be full access where Site.trusted = true
or partial access where the Site.trusted = false
and a list of ACL levels are defined in the site definition.
This is used for when the ModelContext is being used directly in code on the 'local' server
scala
val accountRemoteRepo = new AccountRepository(...)
val a:Account = ???
accountRemoteRepo.writeObject("abc-123",a).andThenMap(_ =>
println("Saved")
) // request is sent to remote server and written there