-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from testainers/dev
Version 0.0.5.
- Loading branch information
Showing
64 changed files
with
2,089 additions
and
1,152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ on: | |
push: | ||
branches: [ main ] | ||
|
||
|
||
jobs: | ||
build: | ||
name: Build | ||
|
@@ -19,29 +18,28 @@ jobs: | |
QUARKUS_JACOCO_EXCLUDES: '**/SimpleHealthCheck.class' | ||
steps: | ||
- name: Code Checkout | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v3 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
cache: 'gradle' | ||
|
||
- name: Get Gradle Version | ||
id: version-step | ||
run: | | ||
VERSION=$(grep 'version' build.gradle | cut -f 2 -d "'") | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "REPO=$GITHUB_REPOSITORY" >> $GITHUB_ENV | ||
REPO=$(echo $GITHUB_REPOSITORY | cut -f 2 -d "/") | ||
echo "REPO=$REPO" >> $GITHUB_ENV | ||
echo "OWNER=$GITHUB_REPOSITORY_OWNER" >> $GITHUB_ENV | ||
- name: Check if version is used | ||
run: | | ||
URL=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest | ||
LATEST=$(curl --silent "$URL" | jq -r .name) | ||
if [ "$LATEST" == "$VERSION" ]; then | ||
echo "Version is used." | ||
echo "Version already used: $VERSION" | ||
exit 1 | ||
fi | ||
|
@@ -57,24 +55,20 @@ jobs: | |
-out cert.pem \ | ||
-subj "/C=US/ST=SC/L=Hometown/O=IT/emailAddress=root@localhost/CN=localhost" | ||
- name: Build | ||
run: ./gradlew build --no-daemon -Dquarkus.package.type=native -Dquarkus.native.container-build=true | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ env.OWNER }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Docker Build & Push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
push: true | ||
context: . | ||
file: src/main/docker/Dockerfile.native-micro | ||
tags: | | ||
${{ env.REPO }}:${{ env.VERSION }} | ||
${{ env.REPO }}:latest | ||
- name: Test & Build | ||
run: | | ||
./gradlew build --no-daemon \ | ||
-Dquarkus.package.type=native \ | ||
-Dquarkus.native.container-build=true \ | ||
-Dquarkus.container-image.build=true \ | ||
-Dquarkus.container-image.push=true \ | ||
-Dquarkus.container-image.username=${{ env.OWNER }} \ | ||
-Dquarkus.container-image.password=${{ secrets.DOCKER_TOKEN }} \ | ||
-Dquarkus.container-image.group=${{ env.OWNER }} \ | ||
-Dquarkus.container-image.name=${{ env.REPO }} \ | ||
-Dquarkus.container-image.tag=t${{ env.VERSION }} \ | ||
-Dquarkus.container-image.additional-tags=test \ | ||
-Dquarkus.jib.platforms=linux/amd64,linux/arm64 | ||
- name: Creating GitHub Tag | ||
uses: mathieudutour/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Gradle properties | ||
quarkusPluginId=io.quarkus | ||
quarkusPluginVersion=3.2.0.Final | ||
quarkusPluginVersion=3.7.2 | ||
quarkusPlatformGroupId=io.quarkus.platform | ||
quarkusPlatformArtifactId=quarkus-bom | ||
quarkusPlatformVersion=3.2.0.Final | ||
quarkusPlatformVersion=3.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.testainers; | ||
|
||
import io.quarkus.security.Authenticated; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; | ||
import org.jboss.resteasy.spi.HttpRequest; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Eduardo Folly | ||
*/ | ||
@Path("/basic-auth") | ||
@Authenticated | ||
public class BasicAuthResource { | ||
|
||
@Inject | ||
HttpRequest request; | ||
|
||
@GET | ||
@HEAD | ||
@Path("/{user}/{pass}") | ||
@APIResponses({ | ||
@APIResponse(responseCode = "200"), | ||
@APIResponse(responseCode = "401"), | ||
@APIResponse(responseCode = "403"), | ||
}) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response withoutBody( | ||
@HeaderParam(HttpHeaders.AUTHORIZATION) String auth, | ||
@PathParam("user") String user, | ||
@PathParam("pass") String pass | ||
) { | ||
return getResponse(auth, user, pass, null); | ||
} | ||
|
||
@POST | ||
@PUT | ||
@PATCH | ||
@DELETE | ||
@Path("/{user}/{pass}") | ||
@APIResponses({ | ||
@APIResponse(responseCode = "200"), | ||
@APIResponse(responseCode = "401"), | ||
@APIResponse(responseCode = "403"), | ||
}) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response withBody( | ||
@HeaderParam(HttpHeaders.AUTHORIZATION) String auth, | ||
@PathParam("user") String user, | ||
@PathParam("pass") String pass, | ||
Object body) { | ||
return getResponse(auth, user, pass, body); | ||
} | ||
|
||
private Response getResponse(String auth, String user, String pass, | ||
Object body) { | ||
ResponseBody responseBody = new ResponseBody(request, body); | ||
int code = 403; | ||
|
||
Map<String, Object> bodyMap = new HashMap<>(); | ||
bodyMap.put("auth", false); | ||
bodyMap.put("user", user); | ||
bodyMap.put("pass", pass); | ||
bodyMap.put("message", "Forbidden."); | ||
|
||
if (body != null) { | ||
bodyMap.put("body", body); | ||
} | ||
|
||
if (auth == null || auth.isBlank()) { | ||
code = 401; | ||
bodyMap.put("message", "Authorization header not present."); | ||
} else { | ||
String encoded = Base64 | ||
.getEncoder() | ||
.encodeToString((user + ":" + pass) | ||
.getBytes(StandardCharsets.UTF_8)); | ||
|
||
boolean ok = auth.equals("Basic " + encoded); | ||
|
||
bodyMap.put("auth", ok); | ||
|
||
if (ok) { | ||
code = 200; | ||
bodyMap.put("message", "Success."); | ||
} | ||
|
||
} | ||
|
||
responseBody.body = bodyMap; | ||
|
||
return Response.status(code).entity(responseBody).build(); | ||
} | ||
|
||
} |
Oops, something went wrong.