Skip to content

Commit

Permalink
use gradle secure check
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed May 21, 2020
1 parent be159ec commit 7f0a45c
Showing 1 changed file with 3 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.artifacts.repositories.ExclusiveContentRepository;
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.artifacts.repositories.UrlArtifactRepository;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.ExtraPropertiesExtension;
Expand Down Expand Up @@ -154,15 +155,8 @@ public static void configureConfigurations(Project project) {
public static void configureRepositories(Project project) {
// ensure all repositories use secure urls
project.getRepositories().all(repository -> {
if (repository instanceof MavenArtifactRepository) {
final MavenArtifactRepository maven = (MavenArtifactRepository) repository;
assertRepositoryURIIsSecure(maven.getName(), project.getPath(), maven.getUrl());
for (URI uri : maven.getArtifactUrls()) {
assertRepositoryURIIsSecure(maven.getName(), project.getPath(), uri);
}
} else if (repository instanceof IvyArtifactRepository) {
final IvyArtifactRepository ivy = (IvyArtifactRepository) repository;
assertRepositoryURIIsSecure(ivy.getName(), project.getPath(), ivy.getUrl());
if (repository instanceof UrlArtifactRepository) {
((UrlArtifactRepository) repository).setAllowInsecureProtocol(false);
}
});
RepositoryHandler repos = project.getRepositories();
Expand Down Expand Up @@ -195,26 +189,6 @@ public static void configureRepositories(Project project) {
}
}

private static final List<String> SECURE_URL_SCHEMES = Arrays.asList("file", "https", "s3");

private static void assertRepositoryURIIsSecure(final String repositoryName, final String projectPath, final URI uri) {
if (uri != null && SECURE_URL_SCHEMES.contains(uri.getScheme()) == false) {
String url;
try {
url = uri.toURL().toString();
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
final String message = String.format(
Locale.ROOT,
"repository [%s] on project with path [%s] is not using a secure protocol for artifacts on [%s]",
repositoryName,
projectPath,
url);
throw new GradleException(message);
}
}

/** Adds compiler settings to the project */
public static void configureCompile(Project project) {
project.getExtensions().getExtraProperties().set("compactProfile", "full");
Expand Down

0 comments on commit 7f0a45c

Please sign in to comment.