diff --git a/.github/workflows/branch-release.yml b/.github/workflows/branch-release.yml new file mode 100644 index 0000000..4c8c660 --- /dev/null +++ b/.github/workflows/branch-release.yml @@ -0,0 +1,30 @@ +name: maven branch release + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: build with maven + run: | + mvn -B -s settings.xml \ + build-helper:parse-version \ + -DbranchName='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}' \ + -DdevelopmentVersion='${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT' \ + release:branch + env: + NVD_API_KEY: ${{ secrets.NVD_API_KEY }} + ARTIFACTORY_API_USERNAME: ${{ vars.ARTIFACTORY_API_USERNAME }} + ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }} + ARTIFACTORY_SNAPSHOT_URL: ${{ vars.ARTIFACTORY_SNAPSHOT_URL }} + ARTIFACTORY_RELEASE_URL: ${{ vars.ARTIFACTORY_RELEASE_URL }} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e0a6ac2 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,37 @@ +name: maven build + +on: + push: + branches: [ "**" ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: build with maven + run: mvn -B -s settings.xml clean deploy -Pdep-check + env: + NVD_API_KEY: ${{ secrets.NVD_API_KEY }} + ARTIFACTORY_API_USERNAME: ${{ vars.ARTIFACTORY_API_USERNAME }} + ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }} + ARTIFACTORY_SNAPSHOT_URL: ${{ vars.ARTIFACTORY_SNAPSHOT_URL }} + ARTIFACTORY_RELEASE_URL: ${{ vars.ARTIFACTORY_RELEASE_URL }} + - name: notify dependencies + run: | + set -ex + mvn dependency:list | grep 'SNAPSHOT:compile' > dependencies.txt || true + mvn -q -Dexec.executable='echo' -Dexec.args='${project.groupId}:${project.artifactId}:${project.packaging}:${project.version}' exec:exec | grep :jar: > artifacts.txt + echo "{\"event_type\":\"update-dependencies\",\"client_payload\":{\"project\":\"${{ github.event.repository.name }}:${{ github.head_ref || github.ref_name }}\",\"artifacts\":\"$( cat artifacts.txt | awk -v ORS='\\n' '1' )\",\"dependencies\":\"$( cat dependencies.txt | awk -v ORS='\\n' '1' )\"}}" > dependency-action.json + curl -n "https://api.github.com/repos/CI-CMG/maven-dependency-build/dispatches" \ + --header 'Accept: application/vnd.github+json' \ + --header "Authorization: token ${{ secrets.RELEASE_PAT }}" \ + --data @dependency-action.json \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 7c71b9f..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,72 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "trunk", "1.1" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "trunk", "1.1" ] - schedule: - - cron: '42 10 * * 5' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml new file mode 100644 index 0000000..2adc91c --- /dev/null +++ b/.github/workflows/tag-release.yml @@ -0,0 +1,33 @@ +name: maven tag release + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: set up git + run: git config --global user.email bloop@bloop.org && git config --global user.name 'Bloopy McBloopFace' + - name: build with maven + run: | + mvn -B -s settings.xml \ + build-helper:parse-version \ + -Dresume=false -Dtag='v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' \ + -DreleaseVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' \ + -DdevelopmentVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT' \ + release:prepare release:perform + env: + NVD_API_KEY: ${{ secrets.NVD_API_KEY }} + ARTIFACTORY_API_USERNAME: ${{ vars.ARTIFACTORY_API_USERNAME }} + ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }} + ARTIFACTORY_SNAPSHOT_URL: ${{ vars.ARTIFACTORY_SNAPSHOT_URL }} + ARTIFACTORY_RELEASE_URL: ${{ vars.ARTIFACTORY_RELEASE_URL }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 72a3ba9..593def6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 io.github.ci-cmg @@ -27,8 +28,8 @@ - scm:git:git@github.com:CI-CMG/aws-s3-outputstream.git - scm:git:git@github.com:CI-CMG/aws-s3-outputstream.git + scm:git:https://github.com/CI-CMG/aws-s3-outputstream.git + scm:git:https://github.com/CI-CMG/aws-s3-outputstream.git https://github.com/CI-CMG/aws-s3-outputstream HEAD @@ -46,9 +47,12 @@ UTF-8 gpg-sign 1.7.32 - 3.3.1 - 0.8.7 + 3.11.12 + 0.8.12 5.8.1 + ${env.NVD_API_KEY} + + @@ -56,7 +60,7 @@ software.amazon.awssdk bom - 2.21.37 + 2.29.37 pom import @@ -126,21 +130,21 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.5.2 maven-antrun-plugin - 3.0.0 + 3.1.0 org.apache.maven.plugins maven-release-plugin - 3.0.0-M4 + 3.1.1 pl.project13.maven @@ -155,23 +159,37 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.1 org.apache.maven.plugins maven-site-plugin - 3.9.1 + 3.21.0 org.apache.maven.plugins maven-project-info-reports-plugin - 3.1.2 + 3.8.0 org.apache.maven.plugins maven-javadoc-plugin ${javadoc.version} + + org.owasp + dependency-check-maven + 10.0.3 + + + com.github.spotbugs + spotbugs-maven-plugin + 4.8.6.5 + + + maven-resources-plugin + 3.3.1 + @@ -198,7 +216,9 @@ release,site-publish deploy site v@{project.version} - -Pdep-check -D${sign.serverId} + -DskipTests -D${sign.serverId} + ${git.username} + ${git.password} @@ -224,7 +244,6 @@ com.github.spotbugs spotbugs-maven-plugin - 4.2.2 @@ -232,6 +251,9 @@ + + spotbugs-exclude.xml + @@ -245,11 +267,10 @@ org.owasp dependency-check-maven - 7.4.3 - true + 0 - ${project.basedir}/owasp-dep-check-suppression.xml + owasp-dep-check-suppression.xml @@ -349,7 +370,6 @@ maven-resources-plugin - 3.1.0 index.html @@ -384,47 +404,47 @@ - + - - - + + + - - - - + + + + - - - + + + - + - + - + - - + + - - + + - - - + + + - - - + + + diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml new file mode 100644 index 0000000..eb6f31b --- /dev/null +++ b/spotbugs-exclude.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/edu/colorado/cires/cmg/s3out/UploadPartParams.java b/src/main/java/edu/colorado/cires/cmg/s3out/UploadPartParams.java index f05dd79..ede5639 100644 --- a/src/main/java/edu/colorado/cires/cmg/s3out/UploadPartParams.java +++ b/src/main/java/edu/colorado/cires/cmg/s3out/UploadPartParams.java @@ -21,7 +21,7 @@ public static Builder builder() { private final ByteBuffer buffer; private final String checksumAlgorithm; - public UploadPartParams(String bucket, String key, String uploadId, int partNumber, ByteBuffer buffer, String checksumAlgorithm) { + private UploadPartParams(String bucket, String key, String uploadId, int partNumber, ByteBuffer buffer, String checksumAlgorithm) { this.bucket = bucket; this.key = key; this.uploadId = uploadId; diff --git a/src/test/java/edu/colorado/cires/cmg/s3out/AwsS3ClientMultipartUploadTest.java b/src/test/java/edu/colorado/cires/cmg/s3out/AwsS3ClientMultipartUploadTest.java index 22cd5d4..b7c5bb0 100644 --- a/src/test/java/edu/colorado/cires/cmg/s3out/AwsS3ClientMultipartUploadTest.java +++ b/src/test/java/edu/colorado/cires/cmg/s3out/AwsS3ClientMultipartUploadTest.java @@ -7,12 +7,18 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.nio.ByteBuffer; import java.util.Optional; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.ChecksumAlgorithm; +import software.amazon.awssdk.services.s3.model.CompletedPart; import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest; import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse; +import software.amazon.awssdk.services.s3.model.UploadPartRequest; +import software.amazon.awssdk.services.s3.model.UploadPartResponse; public class AwsS3ClientMultipartUploadTest { @@ -78,4 +84,56 @@ public void testObjectMetadataDefaultContentType() throws Exception { assertEquals("defaultContentType", argument.getValue().contentType()); } + + @Test + public void testUploadPartParams() throws Exception { + S3Client s3Client = mock(S3Client.class); + ContentTypeResolver contentTypeResolver = mock(ContentTypeResolver.class); + UploadPartResponse uploadPartResponse = UploadPartResponse.builder() + .checksumCRC32("myChecksumCRC32") + .checksumCRC32C("myChecksumCRC32C") + .checksumSHA1("myChecksumSHA1") + .checksumSHA256("myChecksumSHA256") + .eTag("myEtag") + .build(); + + when(s3Client.uploadPart(any(UploadPartRequest.class), any(RequestBody.class))).thenReturn(uploadPartResponse); + + AwsS3ClientMultipartUpload awsS3ClientMultipartUpload = AwsS3ClientMultipartUpload.builder() + .s3(s3Client) + .contentTypeResolver(contentTypeResolver) + .build(); + + UploadPartParams params = UploadPartParams.builder() + .bucket("myBucket") + .key("myKey") + .uploadId("myUploadId") + .partNumber(5) + .buffer(ByteBuffer.allocate(256)) + .checksumAlgorithm("SHA1") + .build(); + + CompletedPart completedPart = awsS3ClientMultipartUpload.uploadPart(params); + + ArgumentCaptor uploadPartRequestArg = ArgumentCaptor.forClass(UploadPartRequest.class); + ArgumentCaptor requestBodyArg = ArgumentCaptor.forClass(RequestBody.class); + verify(s3Client).uploadPart(uploadPartRequestArg.capture(), requestBodyArg.capture()); + UploadPartRequest uploadPartRequest = uploadPartRequestArg.getValue(); + RequestBody requestBody = requestBodyArg.getValue(); + + assertEquals("myBucket", uploadPartRequest.bucket()); + assertEquals("myKey", uploadPartRequest.key()); + assertEquals(ChecksumAlgorithm.SHA1, uploadPartRequest.checksumAlgorithm()); + assertEquals("myUploadId", uploadPartRequest.uploadId()); + assertEquals(5, uploadPartRequest.partNumber()); + + assertEquals(256, requestBody.contentLength()); + + assertEquals(5, completedPart.partNumber()); + assertEquals("myChecksumCRC32", completedPart.checksumCRC32()); + assertEquals("myChecksumCRC32C", completedPart.checksumCRC32C()); + assertEquals("myChecksumSHA1", completedPart.checksumSHA1()); + assertEquals("myChecksumSHA256", completedPart.checksumSHA256()); + assertEquals("myEtag", completedPart.eTag()); + } } \ No newline at end of file