diff --git a/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/TemerityApi.kt b/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/TemerityApi.kt index 692c59d386ceb8af23cc77cff7d4d917786de4d1..b3908d6ea163ba77148fc0dbdf9125828e1d6f69 100644 --- a/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/TemerityApi.kt +++ b/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/TemerityApi.kt @@ -47,6 +47,13 @@ public interface TemerityApi { // User API public library functions + /** + * Fetches the version of the Temerity client library. + * @return The version of the client library as a semantic versioning formatted string. + */ + @Suppress("PropertyName") + public val VERSION: String + /** * Fetches the list of users from the platform. * @return A list of User objects @@ -230,8 +237,6 @@ public interface TemerityApi { * @param refresh Whether to fetch the roles if not present locally. */ public suspend fun getCachedUserRoles(refresh: Boolean = true): List<String> - - public fun version(): String } // Objects used by library consumers and re-implementations of the Temerity API spec diff --git a/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/core/Temerity.kt b/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/core/Temerity.kt index 708245830dde61a447015132b5545dc7c7cad2fb..683aacb261f20845da7e5d72c4a1d21dcb5e4abc 100644 --- a/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/core/Temerity.kt +++ b/temerity/src/commonMain/kotlin/edu/ucsc/its/temerity/core/Temerity.kt @@ -83,7 +83,6 @@ import org.koin.core.Koin import org.koin.core.KoinApplication import org.koin.core.component.KoinComponent import org.koin.core.component.get -import org.koin.core.context.GlobalContext.get import org.koin.core.logger.Level import org.koin.core.logger.Level.DEBUG import org.koin.core.logger.Level.ERROR @@ -142,7 +141,7 @@ public class Temerity internal constructor( ) } factory { (config: TemClientConfig) -> - val client: HttpClient = get { parametersOf(config) } + val client: HttpClient = get { parametersOf(config, createLogger("Temerity Library Web Request engine")) } val ktorfit = ktorfit { config.serviceUrl?.let { baseUrl(it) } httpClient(client) @@ -185,7 +184,8 @@ public class Temerity internal constructor( abstract val koin: Koin } - override fun version(): String = BuildConfig.LIB_VERSION + @Suppress("PropertyName") + override val VERSION: String = BuildConfig.LIB_VERSION private val json: Json = buildJson() internal val koinContext = createKoinApp() @@ -193,7 +193,7 @@ public class Temerity internal constructor( private var platformApi: PlatformApi private var cachedUserRoleList: ConcurrentMutableMap<Int, String> - private var clientCoroutineScope: CoroutineScope + private var libraryCoroutineScope: CoroutineScope init { check(!config.serviceToken.isNullOrBlank()) { @@ -204,7 +204,7 @@ public class Temerity internal constructor( "Service url must be provided. Set it using TemClientConfig.serviceUrl(url)" } - clientCoroutineScope = get<CoroutineScope> { + libraryCoroutineScope = get<CoroutineScope> { when (val optThreadCount = config.threadCount) { null -> parametersOf(DispatcherFactory.calculateMaxThreads(DEFAULT_MINIMUM_THREAD_COUNT)) else -> parametersOf(DispatcherFactory.setThreadCount(optThreadCount)) @@ -400,7 +400,7 @@ public class Temerity internal constructor( ): List<AuditLogEntry> { // TODO: Error out if user inputs time window > 1 month, since the platform API doesn't support val returnedEntries = ArrayList<AuditLogEntry>() - val jobScope = createJobScope(clientCoroutineScope.coroutineContext) + val jobScope = createJobScope(libraryCoroutineScope.coroutineContext) val requestJobs = with(eventTypeList ?: EventType.entries) { map { eventType -> jobScope.async { diff --git a/temerity/src/jvmTest/kotlin/edu/ucsc/its/temerity/test/TemerityDevTest.kt b/temerity/src/jvmTest/kotlin/edu/ucsc/its/temerity/test/TemerityDevTest.kt index 95d28429589872961b83c7dde363e728975b9ab2..b98aea8a3321c7370ca9f24a920123efbeab46bd 100644 --- a/temerity/src/jvmTest/kotlin/edu/ucsc/its/temerity/test/TemerityDevTest.kt +++ b/temerity/src/jvmTest/kotlin/edu/ucsc/its/temerity/test/TemerityDevTest.kt @@ -21,7 +21,6 @@ import co.touchlab.kermit.Logger import com.skydoves.sandwich.StatusCode import com.skydoves.sandwich.ktor.getStatusCode import edu.ucsc.its.temerity.AuditLogSortOrder.NEW_FIRST -import edu.ucsc.its.temerity.core.TemClientConfig import edu.ucsc.its.temerity.core.Temerity import edu.ucsc.its.temerity.currentDate import edu.ucsc.its.temerity.model.EventType.NEW_LOG_IN @@ -38,17 +37,13 @@ import kotlinx.datetime.plus import org.dotenv.vault.dotenvVault import org.jetbrains.kotlinx.dataframe.api.toDataFrame import org.jetbrains.kotlinx.dataframe.io.writeCSV -import org.koin.core.parameter.parametersOf -import org.koin.test.KoinTest import java.io.File import kotlin.test.assertNotEquals import kotlin.uuid.ExperimentalUuidApi import kotlin.uuid.Uuid @OptIn(ExperimentalUuidApi::class) -class TemerityDevTest : - FunSpec(), - KoinTest { +class TemerityDevTest : FunSpec() { private lateinit var kermit: Logger @@ -61,13 +56,13 @@ class TemerityDevTest : testTemerity = Temerity { configureDevEnvironment(dotenv) } - kermit = getKoin().get { parametersOf("TemerityDevTest", TemClientConfig { supportKtxNotebook = false }) } + kermit = Temerity.createLogger("TemerityDevTest") } test("Temerity client returns a correctly-formatted version String") { - val returnedVersion = testTemerity.version().toVersion() + val returnedVersion = testTemerity.VERSION.toVersion() kermit.d { "Returned client version: $returnedVersion" } - assert(testTemerity.version().isNotEmpty()) + assert(testTemerity.VERSION.isNotEmpty()) assert(returnedVersion < Version(0, 1, 0)) assert(returnedVersion.isPreRelease) }