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

Remote repository scanning improvements #60

Merged
merged 36 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ac736b0
Remote repository scanning improvements progress
brianwyka Dec 11, 2021
75e5054
remote-repository: Remote repository file reading improvements for B…
brianwyka Dec 13, 2021
74635f5
remote-repository: Fix maven version
brianwyka Jan 6, 2022
ac60c93
remote-repository: Update groovy to 3.0.9 for JDK 17 support
brianwyka Jan 6, 2022
546c03a
remote-repository: Fix maven version in test
brianwyka Jan 6, 2022
d80fc05
remote-repository: Fix more tests for JDK 17
brianwyka Jan 7, 2022
2068eda
remote-repository: Fix Dockerfile ci images references
brianwyka Jan 7, 2022
cc2fa22
remote-repository: Fix java8 graalvm version
brianwyka Jan 7, 2022
7ddac54
remote-repository: Vulnerability fixes, Fixes #38, Fixes #59, update…
brianwyka Jan 7, 2022
915366d
remote-repository: Login to GHCR with correct creds
brianwyka Jan 7, 2022
31c48bf
remote-repository: Update static native imate to be -H:+StaticExecut…
brianwyka Jan 7, 2022
0dbbc01
remote-repository: Update busybox
brianwyka Jan 7, 2022
fe26db4
remote-repository: Static native image builds on musl, scratch Docke…
brianwyka Jan 22, 2022
0c75dfe
remote-repository: Update github workflows
brianwyka Jan 22, 2022
80531bc
remote-repository: Fix native image builder and push to ghcr
brianwyka Jan 22, 2022
1ddfcf7
remote-repository: Fix docker image builder for native image musl, a…
brianwyka Jan 22, 2022
35bfe1b
remote-repository: Push docker builders
brianwyka Jan 22, 2022
4950433
remote-repository: Push docker builders
brianwyka Jan 22, 2022
a0a57ac
remote-repository: 0.7.0
brianwyka Jan 22, 2022
c61d431
remote-repository: Skip native image build for java 8
brianwyka Jan 22, 2022
e23b5f1
remote-repository: Skip native image build for java 8
brianwyka Jan 22, 2022
e611c42
remote-repository: Fix java8 build and workflow dependencies
brianwyka Jan 22, 2022
27f1624
remote-repository: Fix needs syntax
brianwyka Jan 23, 2022
1758b92
remote-repository: 1.8 reference to identigy java 8 in mvn profile
brianwyka Jan 23, 2022
05be46b
remote-repository: Skip failsafe integration tests for java8
brianwyka Jan 23, 2022
8b6d5c6
remote-repository: Only build dist when not java 8
brianwyka Jan 23, 2022
df01c7f
remote-repository: Fix dist pom
brianwyka Jan 23, 2022
9597d76
remote-repository: Don't cache docker builders
brianwyka Jan 23, 2022
873a4cb
remote-repository: Only build dist for java 11, use 20.3.0 for windo…
brianwyka Jan 23, 2022
e1c89f2
Revert to Test Report
brianwyka Jan 23, 2022
9068a86
remote-repository: Remove git-commitid-plugin, fixes #68
brianwyka Jan 24, 2022
9d27746
remote-repository: Fix git scripts format
brianwyka Jan 24, 2022
dc3f477
remote-repository: Archive completion script without 'bash'
brianwyka Jan 24, 2022
08123dc
remote-repository: Update workflow names and archive linux native image
brianwyka Jan 24, 2022
b69192e
Fix Linux native image archive path
brianwyka Jan 24, 2022
101a21c
Merge branch 'main' into remote-repository-scanning-improvements
brianwyka Jan 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
server-password: SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.SONATYPE_GPG_PRIVATE_KEY }}
gpg-passphrase: SONATYPE_GPG_PASSPHRASE
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GIT_USERNAME }}
password: ${{ secrets.GIT_PACKAGE_TOKEN }}
- name: Set Maven Project Version
shell: bash
run: |
Expand Down Expand Up @@ -138,11 +144,12 @@ jobs:
with:
java-version: 8
- name: Setup GraalVM
uses: DeLaGuardo/setup-graalvm@master
uses: graalvm/setup-graalvm@v1
with:
graalvm-version: 21.2.0.java8
- name: Setup GraalVM Native Image Tool
run: gu install native-image
version: '21.2.0'
java-version: '8'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Mac Native Image
if: success()
working-directory: build
Expand Down Expand Up @@ -180,20 +187,16 @@ jobs:
- name: Rename Native Image JAR
working-directory: build
run: ren *.jar native-image.jar
- name: Setup GraalVM Native Image and Visual C Build Tools
run: |
Invoke-RestMethod -Uri https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java11-windows-amd64-21.3.0.zip -OutFile 'graal.zip'
Expand-Archive -path 'graal.zip' -destinationpath '.'
graalvm-ce-java11-21.3.0\bin\gu.cmd install native-image
choco install visualstudio2017-workload-vctools
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: '21.3.0'
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Windows Native Image
if: success()
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
graalvm-ce-java11-21.3.0\bin\native-image -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
env:
JAVA_HOME: ./graalvm-ce-java11-21.3.0
run: native-image.cmd -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- name: Archive Windows Native Image
if: success()
continue-on-error: true
Expand Down
35 changes: 19 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
server-password: SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.SONATYPE_GPG_PRIVATE_KEY }}
gpg-passphrase: SONATYPE_GPG_PASSPHRASE
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GIT_USERNAME }}
password: ${{ secrets.GIT_PACKAGE_TOKEN }}
- name: Set Maven Project Version
id: set_maven_project_version
shell: bash
Expand Down Expand Up @@ -226,11 +232,12 @@ jobs:
with:
java-version: 8
- name: Setup GraalVM
uses: DeLaGuardo/setup-graalvm@master
uses: graalvm/setup-graalvm@v1
with:
graalvm-version: 21.2.0.java8
- name: Setup GraalVM Native Image Tool
run: gu install native-image
version: '21.2.0'
java-version: '8'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Mac Native Image
if: success()
working-directory: build
Expand Down Expand Up @@ -289,20 +296,16 @@ jobs:
- name: Rename Native Image JAR
working-directory: build
run: ren *.jar native-image.jar
- name: Setup GraalVM Native Image and Visual C Build Tools
run: |
Invoke-RestMethod -Uri https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java11-windows-amd64-21.3.0.zip -OutFile 'graal.zip'
Expand-Archive -path 'graal.zip' -destinationpath '.'
graalvm-ce-java11-21.3.0\bin\gu.cmd install native-image
choco install visualstudio2017-workload-vctools
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: '21.3.0'
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Windows Native Image
if: success()
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
graalvm-ce-java11-21.3.0\bin\native-image -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
env:
JAVA_HOME: ./graalvm-ce-java11-21.3.0
run: native-image.cmd -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- name: Smoke Test
if: success()
shell: cmd
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl = https://apache.claz.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
distributionUrl = https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
6 changes: 3 additions & 3 deletions attribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ https://opensource.org/licenses/BSD-2-Clause

-------------------------------------------------------------------------------------------------------------------------------

Package: org.spockframework:spock-core:2.0-M3-groovy-3.0
Package: org.spockframework:spock-core:2.0-groovy-3.0

License: Apache-2.0

Expand Down Expand Up @@ -1847,7 +1847,7 @@ limitations under the License.

-------------------------------------------------------------------------------------------------------------------------------

Package: org.codehaus.groovy:groovy:3.0.4
Package: org.codehaus.groovy:groovy:3.0.9

License: Apache-2.0

Expand Down Expand Up @@ -1955,7 +1955,7 @@ limitations under the License.

-------------------------------------------------------------------------------------------------------------------------------

Package: org.apache.maven:maven-model:3.6.3
Package: org.apache.maven:maven-model:3.8.4

License: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.optum.sourcehawk</groupId>
<artifactId>sourcehawk</artifactId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
</parent>

<artifactId>sourcehawk-bom</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>sourcehawk</artifactId>
<groupId>com.optum.sourcehawk</groupId>
<version>0.6.0-SNAPSHOT</version>
<version>0.6.1-SNAPSHOT</version>
</parent>

<artifactId>sourcehawk-cli</artifactId>
Expand All @@ -23,7 +23,7 @@
<cli.class>com.optum.sourcehawk.cli.Sourcehawk</cli.class>

<!-- JACOCO OVERRIDES -->
<jacoco.coverage.minimum>0.94</jacoco.coverage.minimum> <!-- jacoco-maven-plugin -->
<jacoco.coverage.minimum>0.91</jacoco.coverage.minimum> <!-- jacoco-maven-plugin -->

<!-- SONAR PROPERTIES -->
<sonar.exclusions>**/picocli/**/*.*</sonar.exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,14 @@ public Integer call() {
.isPresent();
val remoteRef = validateAndParseRemoteRef();
execOptionsBuilder.remoteRef(remoteRef);
val repositoryFileReader = createRepositoryFileReader(remoteRef);
execOptionsBuilder.repositoryFileReader(repositoryFileReader);
if (StringUtils.equals(SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME, parentExecOptions.getConfigurationFileLocation()) && !configFileProvided) {
execOptionsBuilder.configurationFileLocation(constructRemoteConfigFileLocation(remoteRef));
execOptionsBuilder.configurationFileLocation(repositoryFileReader.getAbsoluteLocation(SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME));
}
execOptionsBuilder.repositoryFileReader(createRepositoryFileReader(remoteRef)).build();
return parentCommand.call(execOptionsBuilder.build());
}

/**
* Construct the remote config file location
*
* @param remoteRef the remote reference
* @return the config file remote location
*/
protected abstract String constructRemoteConfigFileLocation(final RemoteRef remoteRef);

/**
* Create the repository file reader based off the remote reference
*
Expand All @@ -76,11 +69,11 @@ public Integer call() {
protected abstract RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef);

/**
* Get the remote reference descriptor
* Get the raw remote reference
*
* @return the raw remote reference descriptor
* @return the raw remote reference
*/
protected abstract Pair<RemoteRef.Type, String> getRawRemoteReference();
protected abstract Pair<String, String> getRawRemoteReference();

/**
* Parse the coordinates to github options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.optum.sourcehawk.cli;

import com.optum.sourcehawk.core.constants.SourcehawkConstants;
import com.optum.sourcehawk.core.data.Pair;
import com.optum.sourcehawk.core.data.RemoteRef;
import com.optum.sourcehawk.core.repository.BitbucketRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RemoteRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RepositoryFileReader;
import lombok.val;
import picocli.CommandLine;

import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Optional;

/**
Expand All @@ -25,6 +26,9 @@
)
public class BitbucketScanCommand extends AbstractRemoteScanCommand {

private static final String DEFAULT_BASE_URL = "https://bitbucket.org";
private static final String DEFAULT_REF = "main";

/**
* The Bitbucket options
*/
Expand All @@ -44,25 +48,24 @@ public static void main(final String... args) {
/** {@inheritDoc} */
@Override
protected RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef) {
if (bitbucket.serverUrl != null) {
return new BitbucketRepositoryFileReader(bitbucket.token, bitbucket.serverUrl.toString(), remoteRef);
val rawFileUrlTemplate = Optional.ofNullable(bitbucket.serverUrl)
.map(bitbucketServerUrl -> String.format("%s/rest/api/1.0/projects/%s/repos/%s/raw/%%s?at=%s",
bitbucketServerUrl, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef()))
.orElseGet(() -> String.format("%s/api/2.0/repositories/%s/%s/src/%s/%%s", DEFAULT_BASE_URL, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef()));
val requestProperties = new HashMap<String, String>();
requestProperties.put("Accept", "text/plain");
if (bitbucket.token != null) {
val authScheme = Optional.ofNullable(bitbucket.authScheme)
.orElse(CommandOptions.Bitbucket.DEFAULT_AUTH_SCHEME);
requestProperties.put("Authorization", String.format("%s %s", authScheme, bitbucket.token));
}
return new BitbucketRepositoryFileReader(bitbucket.token, remoteRef);
}

/** {@inheritDoc} */
@Override
protected Pair<RemoteRef.Type, String> getRawRemoteReference() {
return Pair.of(RemoteRef.Type.BITBUCKET, bitbucket.remoteReference);
return new RemoteRepositoryFileReader(rawFileUrlTemplate, requestProperties);
}

/** {@inheritDoc} */
@Override
protected String constructRemoteConfigFileLocation(final RemoteRef remoteRef) {
val bitbucketBaseUrl = Optional.ofNullable(bitbucket.serverUrl)
.map(URL::toString)
.orElseGet(RemoteRef.Type.BITBUCKET::getBaseUrl);
return BitbucketRepositoryFileReader.constructBaseUrl(remoteRef, bitbucketBaseUrl) + SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME;
protected Pair<String, String> getRawRemoteReference() {
return Pair.of(bitbucket.remoteReference, DEFAULT_REF);
}

}
11 changes: 10 additions & 1 deletion cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ static class Bitbucket {
)
String token;

@CommandLine.Option(
names = {"-a", "--auth-scheme"},
paramLabel = "auth-scheme",
defaultValue = DEFAULT_AUTH_SCHEME,
description = "The authorization scheme to use (either Bearer or Basic). If Basic, the provided token must be base64 encoded."
)
String authScheme;
static final String DEFAULT_AUTH_SCHEME = "Bearer";

@CommandLine.Option(
names = {"-S", "--server-url"},
paramLabel = "bitbucket-server-url",
Expand All @@ -162,7 +171,7 @@ static class Bitbucket {
@CommandLine.Parameters(
paramLabel = REMOTE_REFERENCE_LABEL,
description = "The Bitbucket remote reference - project/repo@ref combination, "
+ "i.e - project/repo, project/repo@master, project/[email protected], or project/repo@a6de43fa51c",
+ "i.e - project/repo, project/repo@main, project/[email protected], or project/repo@a6de43fa51c",
arity = "1"
)
String remoteReference;
Expand Down
37 changes: 17 additions & 20 deletions cli/src/main/java/com/optum/sourcehawk/cli/GithubScanCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.optum.sourcehawk.cli;

import com.optum.sourcehawk.core.constants.SourcehawkConstants;
import com.optum.sourcehawk.core.data.Pair;
import com.optum.sourcehawk.core.data.RemoteRef;
import com.optum.sourcehawk.core.repository.GithubRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RemoteRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RepositoryFileReader;
import lombok.val;
import picocli.CommandLine;

import java.net.URL;
import java.util.HashMap;
import java.util.Optional;

/**
Expand All @@ -25,6 +24,10 @@
)
public class GithubScanCommand extends AbstractRemoteScanCommand {

private static final String DEFAULT_BASE_URL = "raw.githubusercontent.com";
private static final String DEFAULT_REF = "main";
private static final String AUTHORIZATION_TOKEN_PREFIX = "Bearer";

/**
* The github options
*/
Expand All @@ -44,28 +47,22 @@ public static void main(final String... args) {
/** {@inheritDoc} */
@Override
protected RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef) {
if (github.enterpriseUrl != null) {
return new GithubRepositoryFileReader(github.token, github.enterpriseUrl.toString(), remoteRef);
val baseUrl = Optional.ofNullable(github.enterpriseUrl)
.map(githubEnterpriseUrl -> String.format("%s/raw", github.enterpriseUrl))
.orElse(DEFAULT_BASE_URL);
val rawFileUrlTemplate = String.format("%s/%s/%s/%s/%%s", baseUrl, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef());
val requestProperties = new HashMap<String, String>();
requestProperties.put("Accept", "text/plain");
if (github.token != null) {
requestProperties.put("Authorization", String.format("%s %s", AUTHORIZATION_TOKEN_PREFIX, github.token));
}
return new GithubRepositoryFileReader(github.token, remoteRef);
}

/** {@inheritDoc} */
@Override
protected Pair<RemoteRef.Type, String> getRawRemoteReference() {
return Pair.of(RemoteRef.Type.GITHUB, github.remoteReference);
return new RemoteRepositoryFileReader(rawFileUrlTemplate, requestProperties);
}

/** {@inheritDoc} */
@Override
protected String constructRemoteConfigFileLocation(final RemoteRef remoteRef) {
val githubEnterpriseUrl = Optional.ofNullable(github.enterpriseUrl).map(URL::toString);
val githubRepoBaseUrl = GithubRepositoryFileReader.constructBaseUrl(
githubEnterpriseUrl.orElseGet(RemoteRef.Type.GITHUB::getBaseUrl),
githubEnterpriseUrl.isPresent(),
remoteRef
);
return githubRepoBaseUrl + SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME;
protected Pair<String, String> getRawRemoteReference() {
return Pair.of(github.remoteReference, DEFAULT_REF);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Args = -H:Class=${cli.class} \
-H:Name=${cli.name} \
--no-server
-H:Name=${cli.name}
Loading