Skip to content

Commit

Permalink
add s2a java client.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Apr 24, 2024
1 parent 8a21afc commit b7b51bc
Show file tree
Hide file tree
Showing 53 changed files with 6,498 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.perfmark:perfmark-api:0.26.0",
"junit:junit:4.13.2",
"org.apache.tomcat:annotations-api:6.0.53",
"org.checkerframework:checker-qual:3.12.0",
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
"org.jcommander:jcommander:1.83",
]
# GRPC_DEPS_END

Expand Down
3 changes: 3 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
"io.perfmark:perfmark-api:0.26.0",
"junit:junit:4.13.2",
"org.apache.tomcat:annotations-api:6.0.53",
"org.checkerframework:checker-qual:3.12.0",
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
"org.jcommander:jcommander:1.83",
]
# GRPC_DEPS_END

Expand Down Expand Up @@ -80,6 +82,7 @@ IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS = {
"io.grpc:grpc-rls": "@io_grpc_grpc_java//rls",
"io.grpc:grpc-services": "@io_grpc_grpc_java//services:services_maven",
"io.grpc:grpc-stub": "@io_grpc_grpc_java//stub",
"io.grpc:grpc-s2a": "@io_grpc_grpc_java//s2a",
"io.grpc:grpc-testing": "@io_grpc_grpc_java//testing",
"io.grpc:grpc-xds": "@io_grpc_grpc_java//xds:xds_maven",
"io.grpc:grpc-util": "@io_grpc_grpc_java//util",
Expand Down
194 changes: 194 additions & 0 deletions s2a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:java_grpc_library.bzl", "java_grpc_library")
load("@rules_jvm_external//:defs.bzl", "artifact")

java_library(
name = "s2a_channel_pool",
srcs = glob([
"src/main/java/io/grpc/s2a/channel/*.java",
]),
deps = [
"//api",
"//core",
"//core:internal",
"//netty",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("org.checkerframework:checker-qual"),
artifact("io.netty:netty-common"),
artifact("io.netty:netty-transport"),
],
)

java_library(
name = "s2a_identity",
srcs = ["src/main/java/io/grpc/s2a/handshaker/S2AIdentity.java"],
deps = [
":common_java_proto",
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
],
)

java_library(
name = "token_fetcher",
srcs = ["src/main/java/io/grpc/s2a/handshaker/tokenmanager/TokenFetcher.java"],
deps = [
":s2a_identity",
],
)

java_library(
name = "access_token_manager",
srcs = [
"src/main/java/io/grpc/s2a/handshaker/tokenmanager/AccessTokenManager.java",
],
deps = [
":s2a_identity",
":token_fetcher",
artifact("com.google.code.findbugs:jsr305"),
],
)

java_library(
name = "single_token_fetcher",
srcs = [
"src/main/java/io/grpc/s2a/handshaker/tokenmanager/SingleTokenFetcher.java",
],
deps = [
":s2a_identity",
":token_fetcher",
artifact("org.jcommander:jcommander"),
],
)

java_library(
name = "s2a_handshaker",
srcs = [
"src/main/java/io/grpc/s2a/handshaker/ConnectionIsClosedException.java",
"src/main/java/io/grpc/s2a/handshaker/GetAuthenticationMechanisms.java",
"src/main/java/io/grpc/s2a/handshaker/ProtoUtil.java",
"src/main/java/io/grpc/s2a/handshaker/S2AConnectionException.java",
"src/main/java/io/grpc/s2a/handshaker/S2APrivateKeyMethod.java",
"src/main/java/io/grpc/s2a/handshaker/S2AProtocolNegotiatorFactory.java",
"src/main/java/io/grpc/s2a/handshaker/S2AStub.java",
"src/main/java/io/grpc/s2a/handshaker/S2ATrustManager.java",
"src/main/java/io/grpc/s2a/handshaker/SslContextFactory.java",
],
deps = [
":access_token_manager",
":common_java_proto",
":s2a_channel_pool",
":s2a_identity",
":s2a_java_proto",
":s2a_java_grpc_proto",
":single_token_fetcher",
"//api",
"//core:internal",
"//netty",
"//stub",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("org.checkerframework:checker-qual"),
"@com_google_protobuf//:protobuf_java",
artifact("io.netty:netty-common"),
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-transport"),
],
)

java_library(
name = "s2av2_credentials",
srcs = ["src/main/java/io/grpc/s2a/S2AChannelCredentials.java"],
visibility = ["//visibility:public"],
deps = [
":s2a_channel_pool",
":s2a_handshaker",
":s2a_identity",
"//api",
"//core:internal",
"//netty",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("org.checkerframework:checker-qual"),
],
)

java_library(
name = "mtls_to_s2av2_credentials",
srcs = ["src/main/java/io/grpc/s2a/MtlsToS2AChannelCredentials.java"],
visibility = ["//visibility:public"],
deps = [
":s2a_channel_pool",
":s2av2_credentials",
"//api",
"//util",
artifact("com.google.guava:guava"),
],
)

# bazel only accepts proto import with absolute path.
genrule(
name = "protobuf_imports",
srcs = glob(["src/main/proto/grpc/gcp/*.proto"]),
outs = [
"protobuf_out/grpc/gcp/s2a.proto",
"protobuf_out/grpc/gcp/s2a_context.proto",
"protobuf_out/grpc/gcp/common.proto",
],
cmd = "for fname in $(SRCS); do " +
"sed 's,import \",import \"s2a/protobuf_out/,g' $$fname > " +
"$(@D)/protobuf_out/grpc/gcp/$$(basename $$fname); done",
)

proto_library(
name = "common_proto",
srcs = [
"protobuf_out/grpc/gcp/common.proto",
],
)

proto_library(
name = "s2a_context_proto",
srcs = [
"protobuf_out/grpc/gcp/s2a_context.proto",
],
deps = [
":common_proto",
],
)

proto_library(
name = "s2a_proto",
srcs = [
"protobuf_out/grpc/gcp/s2a.proto",
],
deps = [
":common_proto",
":s2a_context_proto",
],
)

java_proto_library(
name = "s2a_java_proto",
deps = [":s2a_proto"],
)

java_proto_library(
name = "s2a_context_java_proto",
deps = [":s2a_context_proto"],
)

java_proto_library(
name = "common_java_proto",
deps = [":common_proto"],
)

java_grpc_library(
name = "s2a_java_grpc_proto",
srcs = [":s2a_proto"],
deps = [":s2a_java_proto"],
)
153 changes: 153 additions & 0 deletions s2a/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
buildscript {
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
}
}

plugins {
id "java-library"
id "maven-publish"

id "com.github.johnrengelman.shadow"
id "com.google.protobuf"
id "ru.vyarus.animalsniffer"
}

description = "gRPC: S2A"

apply plugin: "com.google.osdetector"

dependencies {

api project(':grpc-api')
implementation project(':grpc-stub'),
project(':grpc-protobuf'),
project(':grpc-core'),
libraries.protobuf.java,
libraries.conscrypt,
libraries.guava.jre // JRE required by protobuf-java-util from grpclb
compileOnly 'org.jcommander:jcommander:1.83'
def nettyDependency = implementation project(':grpc-netty')
compileOnly libraries.javax.annotation

shadow configurations.implementation.getDependencies().minus(nettyDependency)
shadow project(path: ':grpc-netty-shaded', configuration: 'shadow')

testImplementation project(':grpc-benchmarks'),
project(':grpc-testing'),
project(':grpc-testing-proto'),
testFixtures(project(':grpc-core')),
libraries.guava,
libraries.junit,
libraries.mockito.core,
libraries.truth,
libraries.conscrypt,
libraries.netty.transport.epoll

testImplementation 'org.jcommander:jcommander:1.83'
testImplementation 'com.google.truth:truth:1.4.2'
testImplementation 'com.google.truth.extensions:truth-proto-extension:1.4.2'
testImplementation libraries.guava.testlib

testRuntimeOnly libraries.netty.tcnative,
libraries.netty.tcnative.classes
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "linux-x86_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "linux-aarch_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "osx-x86_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "osx-aarch_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "windows-x86_64"
}
}
testRuntimeOnly (libraries.netty.transport.epoll) {
artifact {
classifier = "linux-x86_64"
}
}

signature libraries.signature.java
}

tasks.named("compileJava") {
dependsOn(tasks.named("generateProto"))
//dependsOn(tasks.named("syncGeneratedSourcesmain"))
}


tasks.named("sourcesJar") {
dependsOn(tasks.named("generateProto"))
//dependsOn(tasks.named("syncGeneratedSourcesmain"))
}

sourceSets {
main {
//java.srcDirs += "src/generated/main/java"
//java.srcDirs += "src/generated/main/grpc"
}
}
//println sourceSets.main.java.srcDirs
//println sourceSets.test.resources.srcDirs

configureProtoCompilation()

tasks.named("javadoc").configure {
exclude 'io/grpc/s2a/**'
}

tasks.named("jar").configure {
// Must use a different archiveClassifier to avoid conflicting with shadowJar
archiveClassifier = 'original'
manifest {
attributes('Automatic-Module-Name': 'io.grpc.s2a')
}
}

// We want to use grpc-netty-shaded instead of grpc-netty. But we also want our
// source to work with Bazel, so we rewrite the code as part of the build.
tasks.named("shadowJar").configure {
archiveClassifier = null
dependencies {
exclude(dependency {true})
}
relocate 'io.grpc.netty', 'io.grpc.netty.shaded.io.grpc.netty'
relocate 'io.netty', 'io.grpc.netty.shaded.io.netty'
}

publishing {
publications {
maven(MavenPublication) {
// We want this to throw an exception if it isn't working
def originalJar = artifacts.find { dep -> dep.classifier == 'original'}
artifacts.remove(originalJar)

pom.withXml {
def dependenciesNode = new Node(null, 'dependencies')
project.configurations.shadow.allDependencies.each { dep ->
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', 'compile')
}
asNode().dependencies[0].replaceNode(dependenciesNode)
}
}
}
}
Loading

0 comments on commit b7b51bc

Please sign in to comment.