Skip to content

License Component

The License component is a transport adapter used to communicate with the Cereal licensing server. It is not called directly — instead, you pass it to the LicenseChecker class from the Cereal License Verification library, which handles the verification logic for you.

Usage

Access provider.license() in onStart and pass it to LicenseChecker:

class MyScript : Script<MyConfiguration> {

    private var isLicensed = false

    override suspend fun onStart(
        configuration: MyConfiguration,
        provider: ComponentProvider
    ): Boolean {
        val licenseChecker = LicenseChecker(
            "com.example.myscript",   // your script's package name
            MY_PUBLIC_KEY,            // public key from the Developer Console
            provider.license()        // the transport component
        )

        val result = licenseChecker.checkAccess()
        isLicensed = result is LicenseState.Licensed

        // Return false on network error so the user can retry.
        // Any other non-Licensed state means the user is unlicensed — allow the script to start
        // and block in execute() instead.
        return result !is LicenseState.ErrorValidatingLicense
    }

    override suspend fun execute(
        configuration: MyConfiguration,
        provider: ComponentProvider,
        statusUpdate: suspend (String) -> Unit
    ): ExecutionResult {
        if (!isLicensed) {
            return ExecutionResult.Error("A valid license is required to run this script.")
        }
        // Your script logic here
    }
}

More Information

For full setup instructions — including where to get your public key, how to add the Gradle dependency, and how to handle each LicenseState — refer to the Script Licensing documentation.