Skip to content

Commit

Permalink
Merge pull request #9 from testainers/dev
Browse files Browse the repository at this point in the history
Version 0.0.5.
  • Loading branch information
edufolly authored Feb 12, 2024
2 parents b65e45b + aa8089b commit 0a5daf8
Show file tree
Hide file tree
Showing 64 changed files with 2,089 additions and 1,152 deletions.
44 changes: 19 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ main ]


jobs:
build:
name: Build
Expand All @@ -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
Expand All @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
timeout-minutes: 20
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: Generating self-signed certificate
run: |
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
httpbucket
</h1>

[![BuildWithLove](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg "build with love")](https://github.com/testainers/httpbucket/stargazers)
[![Docker Image Version](https://img.shields.io/docker/v/testainers/httpbucket)](https://hub.docker.com/r/testainers/httpbucket/tags)
[![Build With Love](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg)](https://github.com/testainers/httpbucket/stargazers)
[![Version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Ftestainers%2Fhttpbucket%2Freleases%2Flatest&query=%24.name&label=version&color=orange)](https://hub.docker.com/r/testainers/httpbucket/tags)
[![Licence](https://img.shields.io/github/license/testainers/httpbucket?color=blue)](https://github.com/testainers/httpbucket/blob/main/LICENSE)
[![Build](https://img.shields.io/github/actions/workflow/status/testainers/httpbucket/main.yml?branch=main)](https://github.com/testainers/httpbucket/releases/latest)
[![Coverage Report](https://img.shields.io/badge/coverage-report-C08EA1 "Coverage Report")](https://testainers.github.io/httpbucket/)
[![Coverage Report](https://img.shields.io/badge/coverage-report-C08EA1)](https://testainers.github.io/httpbucket/)

**httpucket** is a powerful microservice designed specifically for testing HTTP
requests with a wide range of request URLs. It serves as a valuable tool for
Expand Down Expand Up @@ -93,3 +93,4 @@ openssl req \
- /swagger-ui
- /health
- /metrics
- /info
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies {
implementation "io.quarkus:quarkus-smallrye-health"
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-resteasy-jackson'
implementation 'io.quarkus:quarkus-container-image-jib'
implementation 'io.quarkus:quarkus-info'
implementation 'io.quarkus:quarkus-arc'
implementation 'io.smallrye.config:smallrye-config-source-file-system'
testImplementation 'io.quarkus:quarkus-junit5'
Expand All @@ -23,7 +25,7 @@ dependencies {
}

group 'com.testainers'
version '0.0.4'
version '0.0.5'

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
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
5 changes: 3 additions & 2 deletions src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
FROM registry.access.redhat.com/ubi8/openjdk-17:1.15
FROM registry.access.redhat.com/ubi8/openjdk-17:1.18

ENV LANGUAGE='en_US:en'

Expand All @@ -90,6 +90,7 @@ COPY --chown=185 build/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"

ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
6 changes: 4 additions & 2 deletions src/main/docker/Dockerfile.legacy-jar
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
FROM registry.access.redhat.com/ubi8/openjdk-17:1.15
FROM registry.access.redhat.com/ubi8/openjdk-17:1.18

ENV LANGUAGE='en_US:en'

Expand All @@ -87,5 +87,7 @@ COPY build/*-runner.jar /deployments/quarkus-run.jar

EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"

ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
4 changes: 2 additions & 2 deletions src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# docker run -i --rm -p 8080:8080 quarkus/httpbucket
#
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.9
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
Expand All @@ -24,4 +24,4 @@ COPY --chown=1001:root build/*-runner /work/application
EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
2 changes: 1 addition & 1 deletion src/main/docker/Dockerfile.native-micro
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ EXPOSE 8443

USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
104 changes: 104 additions & 0 deletions src/main/java/com/testainers/BasicAuthResource.java
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();
}

}
Loading

0 comments on commit 0a5daf8

Please sign in to comment.