From 545bf548464642284a6beb0f6fdce645f434b81e Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Tue, 23 Jan 2024 13:56:40 -0600 Subject: [PATCH] feat: snyk controller extension point Add an extension point to allow third-party plugins to interact with Snyk in the IDE. --- META-INF/plugin.xml | 10 ++++++++++ .../plugin/extensionpoints/SnykController.kt | 20 +++++++++++++++++++ .../SnykControllerLifecycleManager.kt | 11 ++++++++++ 3 files changed, 41 insertions(+) create mode 100644 META-INF/plugin.xml create mode 100644 src/main/kotlin/io/snyk/plugin/extensionpoints/SnykController.kt create mode 100644 src/main/kotlin/io/snyk/plugin/extensionpoints/SnykControllerLifecycleManager.kt diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml new file mode 100644 index 000000000..e929129dd --- /dev/null +++ b/META-INF/plugin.xml @@ -0,0 +1,10 @@ + + io.snyk.plugin + + + + + + diff --git a/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykController.kt b/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykController.kt new file mode 100644 index 000000000..29006709d --- /dev/null +++ b/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykController.kt @@ -0,0 +1,20 @@ +package io.snyk.plugin.extensionpoints + +import com.intellij.openapi.project.Project +import io.snyk.plugin.getSnykApiService +import io.snyk.plugin.getSnykTaskQueueService +import org.apache.commons.lang3.NotImplementedException + +// SnykController is used by third-party plugins to interact with the Snyk plugin. +sealed class SnykController { + // scan enqueues a scan of the project for vulnerabilities. + fun scan(project: Project) { + getSnykTaskQueueService(project)?.scan(); + } + + // userId returns the current authenticated Snyk user's ID. + // If no user is authenticated, this will return null. + fun userId(): String? { + return getSnykApiService().userId; + } +} diff --git a/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykControllerLifecycleManager.kt b/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykControllerLifecycleManager.kt new file mode 100644 index 000000000..cd9a8f71d --- /dev/null +++ b/src/main/kotlin/io/snyk/plugin/extensionpoints/SnykControllerLifecycleManager.kt @@ -0,0 +1,11 @@ +package io.snyk.plugin.extensionpoints + +// SnykControllerLifecycleManager is the extension point interface +// which other plugins can implement in order to integrate with Snyk. +interface SnykControllerLifecycleManager { + + // register is called by Snyk on third-party implementations of this interface + // to give the calling plugin an instance of SnykController which can be used + // to control Snyk in the IDE. + fun register(controller: SnykController) +}