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

Version 0.0.6. #11

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 2 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ jobs:
timeout-minutes: 15
permissions:
contents: write
env:
QUARKUS_JACOCO_REPORT_LOCATION: 'coverage'
QUARKUS_JACOCO_FOOTER: 'httpbucket'
QUARKUS_JACOCO_TITLE: 'httpbucket'
QUARKUS_JACOCO_EXCLUDES: '**/SimpleHealthCheck.class'
steps:
- name: Code Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -87,10 +82,10 @@ jobs:

- name: Overwrite Coverage Theme
run: |
/bin/cp -rf helpers/coverage/* build/coverage/.
/bin/cp -rf helpers/jacoco-report/* build/jacoco-report/.

- name: Publishing to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./build/coverage
publish_dir: ./build/jacoco-report
github_token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies {
implementation 'io.quarkus:quarkus-micrometer-registry-prometheus'
implementation 'io.quarkus:quarkus-smallrye-openapi'
implementation "io.quarkus:quarkus-smallrye-health"
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-resteasy-jackson'
implementation 'io.quarkus:quarkus-resteasy-reactive'
implementation 'io.quarkus:quarkus-resteasy-reactive-jackson'
implementation 'io.quarkus:quarkus-container-image-jib'
implementation 'io.quarkus:quarkus-info'
implementation 'io.quarkus:quarkus-arc'
Expand All @@ -25,7 +25,7 @@ dependencies {
}

group 'com.testainers'
version '0.0.5'
version '0.0.6'

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
9 changes: 2 additions & 7 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

set -e

export QUARKUS_JACOCO_REPORT_LOCATION='coverage'
export QUARKUS_JACOCO_FOOTER='httpbucket'
export QUARKUS_JACOCO_TITLE='httpbucket'
export QUARKUS_JACOCO_EXCLUDES='**/SimpleHealthCheck.class'

./gradlew cleanTest test

/bin/cp -rf helpers/coverage/* build/coverage/.
/bin/cp -rf helpers/jacoco-report/* build/jacoco-report/.

/opt/google/chrome/google-chrome build/coverage/index.html
# /opt/google/chrome/google-chrome build/coverage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ table.coverage tfoot td.ctr2 {
margin-top: 20px;
border-top: #d6d3ce 1px solid;
padding-top: 2px;
font-size: 8pt;
color: #a0a0a0;
font-size: 1.5em;
}

.footer a {
color: #a0a0a0;
}

.right {
float: right;
display: none;
}

68 changes: 39 additions & 29 deletions src/main/java/com/testainers/BasicAuthResource.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.testainers;

import io.quarkus.security.Authenticated;
import io.vertx.core.http.HttpServerRequest;
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 jakarta.ws.rs.core.UriInfo;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.reactive.RestHeader;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
Expand All @@ -18,52 +20,60 @@
/**
* @author Eduardo Folly
*/
@Path("/basic-auth")
@Authenticated
@Path("/basic-auth/{user}/{pass}")
@APIResponses({
@APIResponse(responseCode = "200"),
@APIResponse(responseCode = "401"),
@APIResponse(responseCode = "403"),
})
@Produces(MediaType.APPLICATION_JSON)
public class BasicAuthResource {

@Inject
HttpRequest request;
HttpServerRequest request;

@Inject
UriInfo uriInfo;

@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
) {
public Response get(@RestHeader(HttpHeaders.AUTHORIZATION) String auth,
String user, String pass) {

return getResponse(auth, user, pass, null);
}

@POST
public Response post(@RestHeader(HttpHeaders.AUTHORIZATION) String auth,
String user, String pass, Object body) {

return getResponse(auth, user, pass, body);
}

@PUT
public Response put(@RestHeader(HttpHeaders.AUTHORIZATION) String auth,
String user, String pass, Object body) {

return getResponse(auth, user, pass, body);
}

@PATCH
public Response patch(@RestHeader(HttpHeaders.AUTHORIZATION) String auth,
String user, String pass, Object body) {

return getResponse(auth, user, pass, body);
}

@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) {
public Response delete(@RestHeader(HttpHeaders.AUTHORIZATION) String auth,
String user, 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);
ResponseBody responseBody = new ResponseBody(request, uriInfo, body);
int code = 403;

Map<String, Object> bodyMap = new HashMap<>();
Expand Down
86 changes: 51 additions & 35 deletions src/main/java/com/testainers/DelayResource.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,85 @@
package com.testainers;

import io.vertx.core.http.HttpServerRequest;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.jboss.resteasy.spi.HttpRequest;

/**
* @author Eduardo Folly
*/
@Path("/delay")
@Path("/delay/{delay}")
@APIResponses({
@APIResponse(responseCode = "200"),
@APIResponse(responseCode = "400"),
@APIResponse(responseCode = "500"),
})
@Produces(MediaType.APPLICATION_JSON)
public class DelayResource {

@Inject
HttpRequest request;
HttpServerRequest request;

@Inject
UriInfo uriInfo;

@GET
@HEAD
@Path("/{delay}")
@APIResponses({
@APIResponse(responseCode = "200"),
@APIResponse(responseCode = "400"),
@APIResponse(responseCode = "500"),
})
@Produces(MediaType.APPLICATION_JSON)
public Response withoutBody(
public Response get(
@Parameter(description = "Delay must be between 0 and 10 seconds.",
schema = @Schema(minimum = "1", maximum = "10",
defaultValue = "10"
)
)
@PathParam("delay") int delay
) {
return getResponse(delay, null);
defaultValue = "10")) int delay) {

return internal(delay, null);
}

@POST
public Response post(
@Parameter(description = "Delay must be between 0 and 10 seconds.",
schema = @Schema(minimum = "1", maximum = "10",
defaultValue = "10"))
int delay, Object body) {

return internal(delay, body);
}

@PUT
public Response put(
@Parameter(description = "Delay must be between 0 and 10 seconds.",
schema = @Schema(minimum = "1", maximum = "10",
defaultValue = "10"))
int delay, Object body) {

return internal(delay, body);
}

@PATCH
public Response patch(
@Parameter(description = "Delay must be between 0 and 10 seconds.",
schema = @Schema(minimum = "1", maximum = "10",
defaultValue = "10"))
int delay, Object body) {

return internal(delay, body);
}

@DELETE
@Path("/{delay}")
@APIResponses({
@APIResponse(responseCode = "200"),
@APIResponse(responseCode = "400"),
@APIResponse(responseCode = "500"),
})
@Produces(MediaType.APPLICATION_JSON)
public Response withBody(
public Response delete(
@Parameter(description = "Delay must be between 0 and 10 seconds.",
schema = @Schema(minimum = "1", maximum = "10",
defaultValue = "10"
)
)
@PathParam("delay") int delay,
Object body
) {
return getResponse(delay, body);
defaultValue = "10"))
int delay, Object body) {

return internal(delay, body);
}

private Response getResponse(int delay, Object body) {
ResponseBody responseBody = new ResponseBody(request, body);
private Response internal(int delay, Object body) {
ResponseBody responseBody = new ResponseBody(request, uriInfo, body);
int code = 200;

if (delay < 0 || delay > 10) {
Expand Down
Loading