Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ interface IRebindModulesSyncService {
* Creates a connection to the model server. Do not forget to close the created client after use.
*
* @param serverURL the model server URL
* @param jwt the JWT auth token
* @param authProvider a function that generates a JWT token that can be used for auth
*
* @return the model client that is connected to the model server
*/
@Throws(IOException::class)
fun connectModelServer(serverURL: String, jwt: String? = null): ModelClientV2?
fun connectModelServer(serverURL: String, authProvider: () -> String? = { null }): ModelClientV2?

/**
* Connects to the model server's specific branch's specific version, and creates [IBinding]s for the modules and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import java.util.concurrent.CompletableFuture
@UnstableModelixFeature(reason = "The new modelix MPS plugin is under construction", intendedFinalization = "This feature is finalized when the new sync plugin is ready for release.")
interface ISyncService : IRebindModulesSyncService {

override fun connectModelServer(serverURL: String, jwt: String?) = connectModelServer(URL(serverURL), jwt)
override fun connectModelServer(serverURL: String, authProvider: () -> String?) = connectModelServer(URL(serverURL), authProvider)

@Throws(IOException::class)
fun connectModelServer(serverURL: URL, jwt: String? = null): ModelClientV2
fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2

fun disconnectModelServer(client: ModelClientV2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class SyncServiceImpl : ISyncService, InjectableService {
}

@Throws(IOException::class)
override fun connectModelServer(serverURL: URL, jwt: String?): ModelClientV2 {
override fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2 {
logger.info { "Connecting to $serverURL" }
val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken { jwt }.build()
val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken(authProvider).build()
runBlocking(networkDispatcher) {
modelClientV2.init()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class PersistableState(
*
* @return some context statistics about the restored state
*/
fun restoreState(syncService: IRebindModulesSyncService, project: Project): RestoredStateContext? {
fun restoreState(syncService: IRebindModulesSyncService, project: Project, authProvider: () -> String? = { null }): RestoredStateContext? {
var client: ModelClientV2? = null

try {
Expand All @@ -120,7 +120,8 @@ data class PersistableState(
}

logger.debug { "Restoring connection to model server." }
client = syncService.connectModelServer(clientUrl, "")
// TODO FIXME auth token is missing
client = syncService.connectModelServer(clientUrl, authProvider)
if (client == null) {
throw IllegalStateException("Connection to $clientUrl failed, thus PersistableState is not restored.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class ModelSyncService(project: Project) : IRebindModulesSyncService {
logger.debug { "ModelixSyncPlugin: InjectableNotifierWrapper is initialized" }
}

override fun connectModelServer(serverURL: String, jwt: String?): ModelClientV2? {
override fun connectModelServer(serverURL: String, authProvider: () -> String?): ModelClientV2? {
var client: ModelClientV2? = null
try {
client = syncService.connectModelServer(URL(serverURL), jwt)
client = syncService.connectModelServer(URL(serverURL), authProvider)
notifier.notifyAndLogInfo("Connected to server: $serverURL", logger)
} catch (t: Throwable) {
val message = "Unable to connect to $serverURL. Cause: ${t.message}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ModelSyncGuiFactory : ToolWindowFactory {
return@addActionListener
}

val client = modelSyncService.connectModelServer(serverURL.text, jwt.text)
val client = modelSyncService.connectModelServer(serverURL.text) { jwt.text }
triggerRefresh(client)
}
jwtPanel.add(connectButton)
Expand Down
Loading