Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for downloading scan resources from an external repository #433

Merged
merged 10 commits into from
Nov 9, 2023
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def idePluginsCommonVersion = '2.3.0'
dependencies {
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.15.2'
implementation group: 'org.jfrog.buildinfo', name: 'build-info-extractor', version: buildInfoVersion
implementation group: 'com.jfrog.ide', name: 'ide-plugins-common', version: idePluginsCommonVersion
implementation('com.jfrog.ide:ide-plugins-common') {
asafgabai marked this conversation as resolved.
Show resolved Hide resolved
version {
branch = 'air-gap-support'
}
}
implementation group: 'org.jfrog.buildinfo', name: 'build-info-client', version: buildInfoVersion
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.2'
implementation group: 'org.jfrog.buildinfo', name: 'build-info-api', version: buildInfoVersion
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ pluginManagement {
}
}

sourceControl {
gitRepository("https://github.com/asafgabai/ide-plugins-common.git") {
producesModule("com.jfrog.ide:ide-plugins-common")
}
}

rootProject.name = 'jfrog-idea-plugin'
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.jfrog.ide.idea.events.ApplicationEvents;
import com.jfrog.ide.idea.log.Logger;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -66,6 +67,7 @@ public GlobalSettings getState() {
serverConfig.setWatches(this.serverConfig.getWatches());
serverConfig.setConnectionRetries(this.serverConfig.getConnectionRetries());
serverConfig.setConnectionTimeout(this.serverConfig.getConnectionTimeout());
serverConfig.setExternalResourcesRepo(this.serverConfig.getExternalResourcesRepo());

GlobalSettings settings = new GlobalSettings();
settings.serverConfig = serverConfig;
Expand All @@ -80,11 +82,12 @@ public GlobalSettings getState() {
@Override
public void loadState(@NotNull GlobalSettings state) {
XmlSerializerUtil.copyBean(state, this);
serverConfig.readMissingConfFromEnv();
}

@Override
public void noStateLoaded() {
reloadXrayCredentials();
reloadMissingConfiguration();
}

/**
Expand Down Expand Up @@ -130,17 +133,19 @@ private void setAdvancedSettings(ServerConfigImpl serverConfig) {
this.serverConfig.setExcludedPaths(serverConfig.getExcludedPaths());
this.serverConfig.setConnectionRetries(serverConfig.getConnectionRetries());
this.serverConfig.setConnectionTimeout(serverConfig.getConnectionTimeout());
this.serverConfig.setExternalResourcesRepo(serverConfig.getExternalResourcesRepo());
this.serverConfig.setPolicyType(serverConfig.getPolicyType());
this.serverConfig.setProject(serverConfig.getProject());
this.serverConfig.setWatches(serverConfig.getWatches());
}

/**
* Reloads Xray credentials.
* Reloads missing configuration from the plugin settings, environment variables or JFrog CLI configuration.
*
* @return true if credentials exist and Xray is configured, false otherwise.
*/
public boolean reloadXrayCredentials() {
public boolean reloadMissingConfiguration() {
serverConfig.readMissingConfFromEnv();
if (serverConfig.isXrayConfigured()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.jfrog.ide.idea.ui.configuration.ConnectionRetriesSpinner;
import com.jfrog.ide.idea.ui.configuration.ConnectionTimeoutSpinner;
import org.apache.commons.collections4.CollectionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.jfrog.build.client.ProxyConfiguration;

import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -62,14 +63,15 @@ public enum ConnectionType {
}

private static final String JFROG_SETTINGS_CREDENTIALS_KEY = "credentials";
static final String ARTIFACTORY_URL_ENV = "JFROG_IDE_ARTIFACTORY_URL";
public static final String JFROG_SETTINGS_KEY = "com.jfrog.idea";
static final String PLATFORM_URL_ENV = "JFROG_IDE_PLATFORM_URL";
static final String ARTIFACTORY_URL_ENV = "JFROG_IDE_ARTIFACTORY_URL";
static final String XRAY_URL_ENV = "JFROG_IDE_XRAY_URL";
static final String USERNAME_ENV = "JFROG_IDE_USERNAME";
static final String PASSWORD_ENV = "JFROG_IDE_PASSWORD";
static final String ACCESS_TOKEN_ENV = "JFROG_IDE_ACCESS_TOKEN";
static final String PROJECT_ENV = "JFROG_IDE_PROJECT";
static final String EXTERNAL_RESOURCES_REPO_ENV = "JFROG_IDE_RELEASES_REPO";

@OptionTag
private ConnectionType connectionType;
Expand Down Expand Up @@ -100,6 +102,8 @@ public enum ConnectionType {
private Integer connectionRetries;
@Tag
private Integer connectionTimeout;
@Tag
private String externalResourcesRepo;
// The subsystem key of the plugin configuration in the PasswordSafe
@Transient
private String jfrogSettingsCredentialsKey = JFROG_SETTINGS_KEY;
Expand All @@ -121,6 +125,7 @@ public enum ConnectionType {
this.excludedPaths = builder.excludedPaths;
this.connectionRetries = builder.connectionRetries;
this.connectionTimeout = builder.connectionTimeout;
this.externalResourcesRepo = builder.externalResourcesRepo;
this.jfrogSettingsCredentialsKey = builder.jfrogSettingsCredentialsKey;
}

Expand Down Expand Up @@ -155,13 +160,14 @@ public boolean equals(Object o) {
Objects.equals(getWatches(), other.getWatches()) &&
Objects.equals(getExcludedPaths(), other.getExcludedPaths()) &&
getConnectionRetries() == other.getConnectionRetries() &&
getConnectionTimeout() == other.getConnectionTimeout();
getConnectionTimeout() == other.getConnectionTimeout() &&
getExternalResourcesRepo() == other.getExternalResourcesRepo();
}

@Override
public int hashCode() {
return Objects.hash(getConnectionType(), getUrl(), getXrayUrl(), getArtifactoryUrl(), getPassword(), getAccessToken(),
getUsername(), getProject(), getExcludedPaths(), getConnectionRetries(), getConnectionTimeout());
getUsername(), getProject(), getExcludedPaths(), getConnectionRetries(), getConnectionTimeout(), getExternalResourcesRepo());
}

@Override
Expand Down Expand Up @@ -257,6 +263,11 @@ public int getConnectionTimeout() {
return defaultIfNull(this.connectionTimeout, ConnectionTimeoutSpinner.RANGE.initial);
}

@Override
public String getExternalResourcesRepo() {
return this.externalResourcesRepo;
}

public String getJFrogSettingsCredentialsKey() {
return this.jfrogSettingsCredentialsKey;
}
Expand Down Expand Up @@ -402,6 +413,10 @@ void setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}

void setExternalResourcesRepo(String externalResourcesRepo) {
this.externalResourcesRepo = externalResourcesRepo;
}

public void setJFrogSettingsCredentialsKey(String jfrogSettingsCredentialsKey) {
this.jfrogSettingsCredentialsKey = jfrogSettingsCredentialsKey;
}
Expand Down Expand Up @@ -451,6 +466,18 @@ public void readConnectionDetailsFromEnv() {
}
}

/**
* Read missing configuration from environment variables.
*/
public void readMissingConfFromEnv() {
if (isBlank(getExternalResourcesRepo())) {
String externalResourcesRepoEnv = EnvironmentUtil.getValue(EXTERNAL_RESOURCES_REPO_ENV);
if (isNotBlank(externalResourcesRepoEnv)) {
setExternalResourcesRepo(externalResourcesRepoEnv);
}
asafgabai marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Read the connection details from JFrog CLI's config. The configuration is read by executing JFrog CLI.
* If no JFrog CLI server configuration was found or the config
Expand Down Expand Up @@ -505,6 +532,7 @@ public static class Builder {
private String watches;
private int connectionRetries;
private int connectionTimeout;
private String externalResourcesRepo;

public ServerConfigImpl build() {
return new ServerConfigImpl(this);
Expand Down Expand Up @@ -577,6 +605,11 @@ public Builder setConnectionTimeout(int connectionTimeout) {
return this;
}

public Builder setExternalResourcesRepo(String externalResourcesRepo) {
this.externalResourcesRepo = externalResourcesRepo;
return this;
}

public Builder setJFrogSettingsCredentialsKey(String jfrogSettingsCredentialsKey) {
this.jfrogSettingsCredentialsKey = jfrogSettingsCredentialsKey;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ public class ApplicabilityScannerExecutor extends ScanBinaryExecutor {
private static final List<String> SCANNER_ARGS = List.of("ca");
private static final List<PackageManagerType> SUPPORTED_PACKAGE_TYPES = List.of(PackageManagerType.PYPI, PackageManagerType.NPM, PackageManagerType.YARN, PackageManagerType.GRADLE, PackageManagerType.MAVEN);


public ApplicabilityScannerExecutor(Log log, ServerConfig serverConfig) {
this(log, serverConfig, "", true);
}

public ApplicabilityScannerExecutor(Log log, ServerConfig serverConfig, String binaryDownloadUrl, boolean useJFrogReleases) {
super(SourceCodeScanType.CONTEXTUAL, binaryDownloadUrl, log, serverConfig, useJFrogReleases);
public ApplicabilityScannerExecutor(Log log) {
super(SourceCodeScanType.CONTEXTUAL, log);
supportedPackageTypes = SUPPORTED_PACKAGE_TYPES;
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/jfrog/ide/idea/scan/IACScannerExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ public class IACScannerExecutor extends ScanBinaryExecutor {
private static final List<String> SCANNER_ARGS = List.of("iac");
private static final String ISSUE_TITLE = "Infrastructure as Code Vulnerability";

public IACScannerExecutor(Log log, ServerConfig serverConfig) {
this(log, serverConfig, null, true);
}

public IACScannerExecutor(Log log, ServerConfig serverConfig, String binaryDownloadUrl, boolean useJFrogReleases) {
super(SourceCodeScanType.IAC, binaryDownloadUrl, log, serverConfig, useJFrogReleases);
public IACScannerExecutor(Log log) {
super(SourceCodeScanType.IAC, log);
}

public List<JFrogSecurityWarning> execute(ScanConfig.Builder inputFileBuilder, Runnable checkCanceled) throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ public class SastScannerExecutor extends ScanBinaryExecutor {
private static final boolean RUN_WITH_NEW_CONFIG_FILE = true;
private static final List<PackageManagerType> SUPPORTED_PACKAGE_TYPES = List.of(PackageManagerType.PYPI, PackageManagerType.NPM, PackageManagerType.YARN, PackageManagerType.GRADLE, PackageManagerType.MAVEN);

public SastScannerExecutor(Log log, ServerConfig serverConfig) {
this(log, serverConfig, null, true);
}

public SastScannerExecutor(Log log, ServerConfig serverConfig, String binaryDownloadUrl, boolean useJFrogReleases) {
super(SourceCodeScanType.SAST, binaryDownloadUrl, log, serverConfig, useJFrogReleases);
public SastScannerExecutor(Log log) {
super(SourceCodeScanType.SAST, log);
}

public List<JFrogSecurityWarning> execute(ScanConfig.Builder inputFileBuilder, Runnable checkCanceled) throws IOException, InterruptedException {
Expand Down
Loading
Loading