diff --git a/.github/workflows/check-for-updates.yml b/.github/workflows/check-for-updates.yml index 768c145..7b0030a 100644 --- a/.github/workflows/check-for-updates.yml +++ b/.github/workflows/check-for-updates.yml @@ -7,9 +7,6 @@ on: jobs: check: runs-on: ubuntu-latest - env: - # used by Gradle to read packages published by other repos - GH_READ_PACKAGES_TOKEN: ${{ secrets.GH_READ_PACKAGES_TOKEN }} steps: - uses: actions/checkout@v2 with: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 521e16e..78f8ce3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -7,8 +7,6 @@ jobs: permissions: contents: read packages: write - env: - GH_READ_PACKAGES_TOKEN: ${{ secrets.GH_READ_PACKAGES_TOKEN }} steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0f8e882..571e253 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,6 @@ jobs: permissions: contents: read packages: write - env: - GH_READ_PACKAGES_TOKEN: ${{ secrets.GH_READ_PACKAGES_TOKEN }} steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v2 @@ -20,7 +18,10 @@ jobs: - name: Build run: ./gradlew --no-daemon build - name: Publish - run: ./gradlew --no-daemon publish + run: ./gradlew --no-daemon publishToSonatype closeAndReleaseSonatypeStagingRepository env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAVEN_CENTRAL_USER: ${{ secrets.MAVEN_CENTRAL_USER }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} diff --git a/barista/build.gradle.kts b/barista/build.gradle.kts index 21600ed..e914c4d 100644 --- a/barista/build.gradle.kts +++ b/barista/build.gradle.kts @@ -1,8 +1,7 @@ -import java.net.URI - plugins { `java-library` `maven-publish` + `signing` } dependencies { @@ -14,7 +13,7 @@ dependencies { implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.google.guava:guava") - implementation("io.github.markelliot.barista-tracing:barista-tracing") + implementation("com.markelliot.barista.tracing:barista-tracing") implementation("io.undertow:undertow-core") implementation("org.apache.logging.log4j:log4j-core") @@ -39,26 +38,46 @@ tasks.test { } java { + withJavadocJar() withSourcesJar() } publishing { publications { - create("library") { + create("mavenJava") { from(components["java"]) - } - } - - repositories { - maven { - name = "GitHubPackages" - url = URI.create("https://maven.pkg.github.com/markelliot/barista") - credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") + suppressPomMetadataWarningsFor("javadocElements") + pom { + name.set("barista") + description.set("an opinionated java server library.") + url.set("https://github.com/markelliot/barista") + licenses { + license { + name.set("Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0") + } + } + developers { + developer { + id.set("markelliot") + name.set("Mark Elliot") + email.set("markelliot@users.noreply.github.com") + } + } + scm { + connection.set("scm:git:https://github.com/markelliot/barista.git") + developerConnection.set("scm:git:https://github.com/markelliot/barista.git") + url.set("https://github.com/markelliot/barista") + } } } } } -tasks["publishLibraryPublicationToGitHubPackagesRepository"].enabled = System.getenv("GITHUB_ACTOR") != null +configure { + val key = System.getenv("SIGNING_KEY") + val password = System.getenv("SIGNING_PASSWORD") + val publishing: PublishingExtension by project + useInMemoryPgpKeys(key, password) + sign(publishing.publications) +} diff --git a/barista/src/main/java/barista/Endpoints.java b/barista/src/main/java/barista/Endpoints.java deleted file mode 100644 index 54ddef0..0000000 --- a/barista/src/main/java/barista/Endpoints.java +++ /dev/null @@ -1,21 +0,0 @@ -package barista; - -import barista.authz.VerifiedAuthToken; - -public final class Endpoints { - private interface Endpoint { - Class requestClass(); - - String path(); - - HttpMethod method(); - } - - public interface VerifiedAuth extends Endpoint { - Response call(VerifiedAuthToken authToken, Request request); - } - - public interface Open extends Endpoint { - Response call(Request request); - } -} diff --git a/barista/src/main/java/barista/HttpMethod.java b/barista/src/main/java/barista/HttpMethod.java deleted file mode 100644 index d50c1e7..0000000 --- a/barista/src/main/java/barista/HttpMethod.java +++ /dev/null @@ -1,21 +0,0 @@ -package barista; - -import io.undertow.util.HttpString; -import io.undertow.util.Methods; - -@SuppressWarnings("ImmutableEnumChecker") -public enum HttpMethod { - GET(Methods.GET), - PUT(Methods.PUT), - POST(Methods.POST); - - private final HttpString method; - - HttpMethod(HttpString method) { - this.method = method; - } - - public HttpString method() { - return method; - } -} diff --git a/barista/src/main/java/barista/authz/AuthToken.java b/barista/src/main/java/barista/authz/AuthToken.java deleted file mode 100644 index 54cac56..0000000 --- a/barista/src/main/java/barista/authz/AuthToken.java +++ /dev/null @@ -1,4 +0,0 @@ -package barista.authz; - -/** Type-specific alias for an auth authToken. */ -public record AuthToken(String token) {} diff --git a/barista/src/main/java/barista/authz/AuthTokens.java b/barista/src/main/java/barista/authz/AuthTokens.java deleted file mode 100644 index f08e9fc..0000000 --- a/barista/src/main/java/barista/authz/AuthTokens.java +++ /dev/null @@ -1,17 +0,0 @@ -package barista.authz; - -import java.util.regex.Pattern; - -public final class AuthTokens { - private static final Pattern BEARER = Pattern.compile("Bearer\s+"); - - private AuthTokens() {} - - public static AuthToken fromAuthorizationHeader(String headerValue) { - return new AuthToken(BEARER.matcher(headerValue).replaceFirst("")); - } - - public static AuthToken of(String token) { - return new AuthToken(token); - } -} diff --git a/barista/src/main/java/barista/authz/Authz.java b/barista/src/main/java/barista/authz/Authz.java deleted file mode 100644 index 4367fcb..0000000 --- a/barista/src/main/java/barista/authz/Authz.java +++ /dev/null @@ -1,18 +0,0 @@ -package barista.authz; - -import java.time.Clock; -import java.util.Optional; - -public interface Authz { - AuthToken newSession(String userId); - - Optional check(AuthToken token); - - static Authz createDefault(String secret, String issuer, Clock clock) { - return new DefaultAuthz(secret, issuer, clock); - } - - static Authz denyAll() { - return new DenyAllAuthz(); - } -} diff --git a/barista/src/main/java/barista/authz/DenyAllAuthz.java b/barista/src/main/java/barista/authz/DenyAllAuthz.java deleted file mode 100644 index 4c05c36..0000000 --- a/barista/src/main/java/barista/authz/DenyAllAuthz.java +++ /dev/null @@ -1,16 +0,0 @@ -package barista.authz; - -import java.util.Optional; - -final class DenyAllAuthz implements Authz { - - @Override - public AuthToken newSession(String userId) { - throw new UnsupportedOperationException(); - } - - @Override - public Optional check(AuthToken token) { - return Optional.empty(); - } -} diff --git a/barista/src/main/java/barista/authz/VerifiedAuthToken.java b/barista/src/main/java/barista/authz/VerifiedAuthToken.java deleted file mode 100644 index 8626525..0000000 --- a/barista/src/main/java/barista/authz/VerifiedAuthToken.java +++ /dev/null @@ -1,3 +0,0 @@ -package barista.authz; - -public record VerifiedAuthToken(AuthToken token, String userId) {} diff --git a/barista/src/main/java/barista/handlers/DispatchFromIoThreadHandler.java b/barista/src/main/java/barista/handlers/DispatchFromIoThreadHandler.java deleted file mode 100644 index 28dd766..0000000 --- a/barista/src/main/java/barista/handlers/DispatchFromIoThreadHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package barista.handlers; - -import io.undertow.server.HttpHandler; -import io.undertow.server.HttpServerExchange; - -/** An {@link HttpHandler} that ensures work is done off of IO threads. */ -public record DispatchFromIoThreadHandler(HttpHandler delegate) implements HttpHandler { - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception { - if (exchange.isInIoThread()) { - exchange.dispatch(this); - return; - } - delegate.handleRequest(exchange); - } -} diff --git a/barista/src/main/java/com/markelliot/barista/Endpoints.java b/barista/src/main/java/com/markelliot/barista/Endpoints.java new file mode 100644 index 0000000..a09aca2 --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/Endpoints.java @@ -0,0 +1,37 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; + +import com.markelliot.barista.authz.VerifiedAuthToken; + +public final class Endpoints { + private interface Endpoint { + Class requestClass(); + + String path(); + + HttpMethod method(); + } + + public interface VerifiedAuth extends Endpoint { + Response call(VerifiedAuthToken authToken, Request request); + } + + public interface Open extends Endpoint { + Response call(Request request); + } +} diff --git a/barista/src/main/java/com/markelliot/barista/HttpMethod.java b/barista/src/main/java/com/markelliot/barista/HttpMethod.java new file mode 100644 index 0000000..6074e22 --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/HttpMethod.java @@ -0,0 +1,37 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; + +import io.undertow.util.HttpString; +import io.undertow.util.Methods; + +@SuppressWarnings("ImmutableEnumChecker") +public enum HttpMethod { + GET(Methods.GET), + PUT(Methods.PUT), + POST(Methods.POST); + + private final HttpString method; + + HttpMethod(HttpString method) { + this.method = method; + } + + public HttpString method() { + return method; + } +} diff --git a/barista/src/main/java/barista/Logging.java b/barista/src/main/java/com/markelliot/barista/Logging.java similarity index 79% rename from barista/src/main/java/barista/Logging.java rename to barista/src/main/java/com/markelliot/barista/Logging.java index a3c011b..dad71c1 100644 --- a/barista/src/main/java/barista/Logging.java +++ b/barista/src/main/java/com/markelliot/barista/Logging.java @@ -1,4 +1,20 @@ -package barista; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; import java.net.URI; import org.apache.logging.log4j.Level; diff --git a/barista/src/main/java/barista/SerDe.java b/barista/src/main/java/com/markelliot/barista/SerDe.java similarity index 75% rename from barista/src/main/java/barista/SerDe.java rename to barista/src/main/java/com/markelliot/barista/SerDe.java index 96f316d..a9cdfb9 100644 --- a/barista/src/main/java/barista/SerDe.java +++ b/barista/src/main/java/com/markelliot/barista/SerDe.java @@ -1,4 +1,20 @@ -package barista; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/barista/src/main/java/barista/Server.java b/barista/src/main/java/com/markelliot/barista/Server.java similarity index 81% rename from barista/src/main/java/barista/Server.java rename to barista/src/main/java/com/markelliot/barista/Server.java index 1d88fb4..36df082 100644 --- a/barista/src/main/java/barista/Server.java +++ b/barista/src/main/java/com/markelliot/barista/Server.java @@ -1,15 +1,31 @@ -package barista; - -import barista.authz.Authz; -import barista.handlers.CorsHandler; -import barista.handlers.DispatchFromIoThreadHandler; -import barista.handlers.EndpointHandlerBuilder; -import barista.handlers.HandlerChain; -import barista.handlers.TracingHandler; -import barista.tls.TransportLayerSecurity; -import barista.tracing.Spans; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; + import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.markelliot.barista.authz.Authz; +import com.markelliot.barista.handlers.CorsHandler; +import com.markelliot.barista.handlers.DispatchFromIoThreadHandler; +import com.markelliot.barista.handlers.EndpointHandlerBuilder; +import com.markelliot.barista.handlers.HandlerChain; +import com.markelliot.barista.handlers.TracingHandler; +import com.markelliot.barista.tls.TransportLayerSecurity; +import com.markelliot.barista.tracing.Spans; import io.undertow.Undertow; import java.nio.file.Paths; import java.util.LinkedHashSet; diff --git a/barista/src/main/java/com/markelliot/barista/authz/AuthToken.java b/barista/src/main/java/com/markelliot/barista/authz/AuthToken.java new file mode 100644 index 0000000..6c1ed9e --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/authz/AuthToken.java @@ -0,0 +1,20 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; + +/** Type-specific alias for an auth authToken. */ +public record AuthToken(String token) {} diff --git a/barista/src/main/java/com/markelliot/barista/authz/AuthTokens.java b/barista/src/main/java/com/markelliot/barista/authz/AuthTokens.java new file mode 100644 index 0000000..62cf95a --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/authz/AuthTokens.java @@ -0,0 +1,33 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; + +import java.util.regex.Pattern; + +public final class AuthTokens { + private static final Pattern BEARER = Pattern.compile("Bearer\s+"); + + private AuthTokens() {} + + public static AuthToken fromAuthorizationHeader(String headerValue) { + return new AuthToken(BEARER.matcher(headerValue).replaceFirst("")); + } + + public static AuthToken of(String token) { + return new AuthToken(token); + } +} diff --git a/barista/src/main/java/com/markelliot/barista/authz/Authz.java b/barista/src/main/java/com/markelliot/barista/authz/Authz.java new file mode 100644 index 0000000..5148913 --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/authz/Authz.java @@ -0,0 +1,34 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; + +import java.time.Clock; +import java.util.Optional; + +public interface Authz { + AuthToken newSession(String userId); + + Optional check(AuthToken token); + + static Authz createDefault(String secret, String issuer, Clock clock) { + return new DefaultAuthz(secret, issuer, clock); + } + + static Authz denyAll() { + return new DenyAllAuthz(); + } +} diff --git a/barista/src/main/java/barista/authz/DefaultAuthz.java b/barista/src/main/java/com/markelliot/barista/authz/DefaultAuthz.java similarity index 66% rename from barista/src/main/java/barista/authz/DefaultAuthz.java rename to barista/src/main/java/com/markelliot/barista/authz/DefaultAuthz.java index edf0907..c6e76f0 100644 --- a/barista/src/main/java/barista/authz/DefaultAuthz.java +++ b/barista/src/main/java/com/markelliot/barista/authz/DefaultAuthz.java @@ -1,4 +1,20 @@ -package barista.authz; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; import com.auth0.jwt.JWT; import com.auth0.jwt.JWTVerifier; diff --git a/barista/src/main/java/com/markelliot/barista/authz/DenyAllAuthz.java b/barista/src/main/java/com/markelliot/barista/authz/DenyAllAuthz.java new file mode 100644 index 0000000..91b8be2 --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/authz/DenyAllAuthz.java @@ -0,0 +1,32 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; + +import java.util.Optional; + +final class DenyAllAuthz implements Authz { + + @Override + public AuthToken newSession(String userId) { + throw new UnsupportedOperationException(); + } + + @Override + public Optional check(AuthToken token) { + return Optional.empty(); + } +} diff --git a/barista/src/main/java/com/markelliot/barista/authz/VerifiedAuthToken.java b/barista/src/main/java/com/markelliot/barista/authz/VerifiedAuthToken.java new file mode 100644 index 0000000..f6f2fa5 --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/authz/VerifiedAuthToken.java @@ -0,0 +1,19 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.authz; + +public record VerifiedAuthToken(AuthToken token, String userId) {} diff --git a/barista/src/main/java/barista/handlers/CorsHandler.java b/barista/src/main/java/com/markelliot/barista/handlers/CorsHandler.java similarity index 78% rename from barista/src/main/java/barista/handlers/CorsHandler.java rename to barista/src/main/java/com/markelliot/barista/handlers/CorsHandler.java index 975877e..91ebc1e 100644 --- a/barista/src/main/java/barista/handlers/CorsHandler.java +++ b/barista/src/main/java/com/markelliot/barista/handlers/CorsHandler.java @@ -1,4 +1,20 @@ -package barista.handlers; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.handlers; import com.google.common.base.Joiner; import io.undertow.server.HttpHandler; diff --git a/barista/src/main/java/com/markelliot/barista/handlers/DispatchFromIoThreadHandler.java b/barista/src/main/java/com/markelliot/barista/handlers/DispatchFromIoThreadHandler.java new file mode 100644 index 0000000..52a0cdd --- /dev/null +++ b/barista/src/main/java/com/markelliot/barista/handlers/DispatchFromIoThreadHandler.java @@ -0,0 +1,32 @@ +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.handlers; + +import io.undertow.server.HttpHandler; +import io.undertow.server.HttpServerExchange; + +/** An {@link HttpHandler} that ensures work is done off of IO threads. */ +public record DispatchFromIoThreadHandler(HttpHandler delegate) implements HttpHandler { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + if (exchange.isInIoThread()) { + exchange.dispatch(this); + return; + } + delegate.handleRequest(exchange); + } +} diff --git a/barista/src/main/java/barista/handlers/EndpointHandlerBuilder.java b/barista/src/main/java/com/markelliot/barista/handlers/EndpointHandlerBuilder.java similarity index 86% rename from barista/src/main/java/barista/handlers/EndpointHandlerBuilder.java rename to barista/src/main/java/com/markelliot/barista/handlers/EndpointHandlerBuilder.java index a0bcad4..31749c6 100644 --- a/barista/src/main/java/barista/handlers/EndpointHandlerBuilder.java +++ b/barista/src/main/java/com/markelliot/barista/handlers/EndpointHandlerBuilder.java @@ -1,11 +1,27 @@ -package barista.handlers; - -import barista.Endpoints; -import barista.SerDe; -import barista.authz.AuthToken; -import barista.authz.AuthTokens; -import barista.authz.Authz; -import barista.authz.VerifiedAuthToken; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.handlers; + +import com.markelliot.barista.Endpoints; +import com.markelliot.barista.SerDe; +import com.markelliot.barista.authz.AuthToken; +import com.markelliot.barista.authz.AuthTokens; +import com.markelliot.barista.authz.Authz; +import com.markelliot.barista.authz.VerifiedAuthToken; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.server.RoutingHandler; diff --git a/barista/src/main/java/barista/handlers/HandlerChain.java b/barista/src/main/java/com/markelliot/barista/handlers/HandlerChain.java similarity index 68% rename from barista/src/main/java/barista/handlers/HandlerChain.java rename to barista/src/main/java/com/markelliot/barista/handlers/HandlerChain.java index 09237b4..73935f2 100644 --- a/barista/src/main/java/barista/handlers/HandlerChain.java +++ b/barista/src/main/java/com/markelliot/barista/handlers/HandlerChain.java @@ -1,4 +1,20 @@ -package barista.handlers; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista.handlers; import com.google.common.collect.Lists; import io.undertow.server.HttpHandler; diff --git a/barista/src/main/java/barista/handlers/TracingHandler.java b/barista/src/main/java/com/markelliot/barista/handlers/TracingHandler.java similarity index 71% rename from barista/src/main/java/barista/handlers/TracingHandler.java rename to barista/src/main/java/com/markelliot/barista/handlers/TracingHandler.java index a6f43a9..314f467 100644 --- a/barista/src/main/java/barista/handlers/TracingHandler.java +++ b/barista/src/main/java/com/markelliot/barista/handlers/TracingHandler.java @@ -1,9 +1,25 @@ -package barista.handlers; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import barista.tracing.Ids; -import barista.tracing.Span; -import barista.tracing.Trace; -import barista.tracing.Traces; +package com.markelliot.barista.handlers; + +import com.markelliot.barista.tracing.Ids; +import com.markelliot.barista.tracing.Span; +import com.markelliot.barista.tracing.Trace; +import com.markelliot.barista.tracing.Traces; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import java.util.concurrent.ThreadLocalRandom; diff --git a/barista/src/main/java/barista/tls/DefaultCas.java b/barista/src/main/java/com/markelliot/barista/tls/DefaultCas.java similarity index 94% rename from barista/src/main/java/barista/tls/DefaultCas.java rename to barista/src/main/java/com/markelliot/barista/tls/DefaultCas.java index b0c009e..d348257 100644 --- a/barista/src/main/java/barista/tls/DefaultCas.java +++ b/barista/src/main/java/com/markelliot/barista/tls/DefaultCas.java @@ -1,12 +1,5 @@ /* - * This file is directly derived from: - * https://github.com/palantir/conjure-java-runtime/blob/\ - * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/keystores/\ - * src/main/java/com/palantir/conjure/java/config/ssl/DefaultCas.java - * - * Such derivations are subject to the following copyright and license: - * - * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. + * (c) Copyright 2021 Mark Elliot. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* + * This file is directly derived from: + * https://github.com/palantir/conjure-java-runtime/blob/\ + * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/keystores/\ + * src/main/java/com/palantir/conjure/java/config/ssl/DefaultCas.java + */ -package barista.tls; +package com.markelliot.barista.tls; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; diff --git a/barista/src/main/java/barista/tls/Pkcs1PrivateKeyReader.java b/barista/src/main/java/com/markelliot/barista/tls/Pkcs1PrivateKeyReader.java similarity index 97% rename from barista/src/main/java/barista/tls/Pkcs1PrivateKeyReader.java rename to barista/src/main/java/com/markelliot/barista/tls/Pkcs1PrivateKeyReader.java index 244e5db..0ca1bbc 100644 --- a/barista/src/main/java/barista/tls/Pkcs1PrivateKeyReader.java +++ b/barista/src/main/java/com/markelliot/barista/tls/Pkcs1PrivateKeyReader.java @@ -1,12 +1,5 @@ /* - * This file is directly derived from: - * https://github.com/palantir/conjure-java-runtime/blob/\ - * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/\keystores/src/main/java/\ - * com/palantir/conjure/java/config/ssl/pkcs1/Pkcs1PrivateKeyReader.java - * - * Such derivations are subject to the following copyright and license: - * - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. + * (c) Copyright 2021 Mark Elliot. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* + * This file is directly derived from: + * https://github.com/palantir/conjure-java-runtime/blob/\ + * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/\keystores/src/main/java/\ + * com/palantir/conjure/java/config/ssl/pkcs1/Pkcs1PrivateKeyReader.java + */ -package barista.tls; +package com.markelliot.barista.tls; import java.math.BigInteger; import java.nio.ByteBuffer; diff --git a/barista/src/main/java/barista/tls/TransportLayerSecurity.java b/barista/src/main/java/com/markelliot/barista/tls/TransportLayerSecurity.java similarity index 99% rename from barista/src/main/java/barista/tls/TransportLayerSecurity.java rename to barista/src/main/java/com/markelliot/barista/tls/TransportLayerSecurity.java index f5cf8fd..c0de294 100644 --- a/barista/src/main/java/barista/tls/TransportLayerSecurity.java +++ b/barista/src/main/java/com/markelliot/barista/tls/TransportLayerSecurity.java @@ -1,12 +1,5 @@ /* - * Some of the code in this file is directly derived from: - * https://github.com/palantir/conjure-java-runtime/blob/\ - * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/\keystores/src/main/java/\ - * com/palantir/conjure/java/config/ssl/KeyStores.java - * - * Such derivations are subject to the following copyright and license: - * - * (c) Copyright 2017 Palantir Technologies Inc. All rights reserved. + * (c) Copyright 2021 Mark Elliot. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* + * Some of the code in this file is directly derived from: + * https://github.com/palantir/conjure-java-runtime/blob/\ + * 27be7573c5b0e9d09e5b0a4ed10e882f969330a9/\keystores/src/main/java/\ + * com/palantir/conjure/java/config/ssl/KeyStores.java + */ -package barista.tls; +package com.markelliot.barista.tls; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; diff --git a/barista/src/test/java/barista/ServerTests.java b/barista/src/test/java/com/markelliot/barista/ServerTests.java similarity index 83% rename from barista/src/test/java/barista/ServerTests.java rename to barista/src/test/java/com/markelliot/barista/ServerTests.java index 7898392..2d75635 100644 --- a/barista/src/test/java/barista/ServerTests.java +++ b/barista/src/test/java/com/markelliot/barista/ServerTests.java @@ -1,4 +1,20 @@ -package barista; +/* + * (c) Copyright 2021 Mark Elliot. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.markelliot.barista; import static org.assertj.core.api.Assertions.assertThat; diff --git a/build.gradle.kts b/build.gradle.kts index 6ee2b9e..32650ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,7 @@ plugins { id("com.google.cloud.tools.jib") version "3.1.4" apply false id("com.palantir.consistent-versions") version "2.3.0" id("com.markelliot.versions") version "0.1.11" + id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("net.ltgt.errorprone") version "2.0.2" apply false id("org.inferred.processors") version "3.6.0" apply false } @@ -21,7 +22,7 @@ task("printVersion") { } allprojects { - group = "io.github.markelliot.barista" + group = "com.markelliot.barista" version = rootProject.version } @@ -32,13 +33,6 @@ allprojects { // lives in allprojects because of consistent-versions repositories { - maven { - url = uri("https://maven.pkg.github.com/markelliot/barista-tracing") - credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GH_READ_PACKAGES_TOKEN") - } - } mavenCentral() } @@ -104,3 +98,14 @@ fun String.runCommand(): String { proc.waitFor(10, TimeUnit.SECONDS) return proc.inputStream.bufferedReader().readText() } + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username.set(System.getenv("MAVEN_CENTRAL_USER")) + password.set(System.getenv("MAVEN_CENTRAL_PASSWORD")) + } + } +} diff --git a/versions.lock b/versions.lock index e037563..80c37bf 100644 --- a/versions.lock +++ b/versions.lock @@ -15,8 +15,8 @@ com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4) com.google.guava:guava:31.0.1-jre (2 constraints: e21ca4c6) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) com.google.j2objc:j2objc-annotations:1.3 (1 constraints: b809eda0) -com.jakewharton.nopen:nopen-annotations:1.0.1 (2 constraints: e61a7e3d) -io.github.markelliot.barista-tracing:barista-tracing:0.2.0 (1 constraints: 0405f135) +com.jakewharton.nopen:nopen-annotations:1.0.1 (2 constraints: 9d18ae99) +com.markelliot.barista.tracing:barista-tracing:0.3.0 (1 constraints: 0505f435) io.undertow:undertow-core:2.2.14.Final (1 constraints: 53072761) org.apache.logging.log4j:log4j-api:2.14.1 (3 constraints: ea2dae0e) org.apache.logging.log4j:log4j-core:2.14.1 (2 constraints: 0d16b624) diff --git a/versions.props b/versions.props index 315904c..a9c0cab 100644 --- a/versions.props +++ b/versions.props @@ -4,7 +4,7 @@ com.fasterxml.jackson.*:* = 2.13.0 com.google.errorprone:error_prone_core = 2.10.0 com.google.guava:guava = 31.0.1-jre com.jakewharton.nopen:* = 1.0.1 -io.github.markelliot.barista-tracing:barista-tracing = 0.2.0 +com.markelliot.barista.tracing:barista-tracing = 0.3.0 io.undertow:undertow-core = 2.2.14.Final org.apache.logging.log4j:* = 2.14.1 org.assertj:assertj-core = 3.21.0