diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097f2..000000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * 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 java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar index 2cc7d4a55..eebc3c18b 100644 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 642d572ce..970a3d02d 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,4 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +wrapperVersion=3.3.4 +distributionType=bin +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar diff --git a/.sops.yaml b/.sops.yaml index 77cbfe524..455dd475f 100644 --- a/.sops.yaml +++ b/.sops.yaml @@ -1,6 +1,6 @@ stores: - yaml: - indent: 2 + yaml: + indent: 2 creation_rules: - - path_regex: .env.shared.yaml - azure_keyvault: "https://sops-master.vault.azure.net/keys/sops-key/" + - path_regex: .env.shared.yaml + azure_keyvault: "https://sops-master.vault.azure.net/keys/sops-key/" diff --git a/Justfile b/Justfile index b8a0bf52f..5020e9359 100644 --- a/Justfile +++ b/Justfile @@ -42,9 +42,9 @@ las-dev *args: lass-dev *args: cd ./internal/leetcode-auth-stealer-service && uv sync && GRPC_REFLECTION=true GRPC_VERBOSITY=ERROR uv run src/server.py -# Generate the leetcode auth stealer gRPC stubs for the main codebloom service -lass-gen *args: - cd ./internal/leetcode-auth-stealer-service && uv sync && uv run src/generate.py +# Generate the leetcode auth service gRPC stubs for the main codebloom service +las-gen *args: + rm -rf lib/leetcode-auth-service/src/main/java && bash ./mvnw -q protobuf:compile protobuf:compile-custom {{args}} # Run the backend Spring server with an exposed debugger at :5005 backend-dev-debug *args: diff --git a/internal/leetcode-auth-stealer-service/src/generate.py b/internal/leetcode-auth-stealer-service/src/generate.py index d49e0eeeb..5d0612a2d 100644 --- a/internal/leetcode-auth-stealer-service/src/generate.py +++ b/internal/leetcode-auth-stealer-service/src/generate.py @@ -8,10 +8,8 @@ python_output = root / "src" / "generated" repo = root.parent.parent -java_output = repo / "lib" / "leetcode-auth-stealer-service" / "src" / "main" / "java" python_output.mkdir(parents=True, exist_ok=True) -java_output.mkdir(parents=True, exist_ok=True) subprocess.run( [ @@ -26,14 +24,3 @@ ], check=True, ) - -subprocess.run( - [ - "protoc", - f"-I{proto_dir}", - f"--java_out={java_output}", - f"--grpc-java_out={java_output}", - str(proto_dir / "LeetcodeAuthStealerService.proto"), - ], - check=True, -) diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequest.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequest.java new file mode 100644 index 000000000..f9fd5fb55 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequest.java @@ -0,0 +1,361 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +/** + * Protobuf type {@code leetcodeauth.GetTokenRequest} + */ +@com.google.protobuf.Generated +public final class GetTokenRequest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:leetcodeauth.GetTokenRequest) + GetTokenRequestOrBuilder { +private static final long serialVersionUID = 0L; + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 36, + /* patch= */ 2, + /* suffix= */ "", + "GetTokenRequest"); + } + // Use GetTokenRequest.newBuilder() to construct. + private GetTokenRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private GetTokenRequest() { + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_descriptor; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.Builder.class); + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getUnknownFields().writeTo(output); + } + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest)) { + return super.equals(obj); + } + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest other = (org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest) obj; + + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code leetcodeauth.GetTokenRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:leetcodeauth.GetTokenRequest) + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.Builder.class); + } + + // Construct using org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenRequest_descriptor; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest getDefaultInstanceForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.getDefaultInstance(); + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest build() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest buildPartial() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest result = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest(this); + onBuilt(); + return result; + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest) { + return mergeFrom((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest other) { + if (other == org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.getDefaultInstance()) return this; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + java.util.Objects.requireNonNull(extensionRegistry); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + // @@protoc_insertion_point(builder_scope:leetcodeauth.GetTokenRequest) + } + + // @@protoc_insertion_point(class_scope:leetcodeauth.GetTokenRequest) + private static final org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest(); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public GetTokenRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequestOrBuilder.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequestOrBuilder.java new file mode 100644 index 000000000..c664906cc --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenRequestOrBuilder.java @@ -0,0 +1,12 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +@com.google.protobuf.Generated +public interface GetTokenRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:leetcodeauth.GetTokenRequest) + com.google.protobuf.MessageOrBuilder { +} diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequest.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponse.java similarity index 60% rename from lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequest.java rename to lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponse.java index 34c505359..fdfe26abf 100644 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequest.java +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponse.java @@ -1,18 +1,18 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // NO CHECKED-IN PROTOBUF GENCODE -// source: LeetcodeAuthStealerService.proto +// source: v1/leetcode_auth.proto // Protobuf Java Version: 4.36.2 -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; /** - * Protobuf type {@code codebloom.leetcode.auth.v1.AuthenticateRequest} + * Protobuf type {@code leetcodeauth.GetTokenResponse} */ @com.google.protobuf.Generated -public final class AuthenticateRequest extends +public final class GetTokenResponse extends com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:codebloom.leetcode.auth.v1.AuthenticateRequest) - AuthenticateRequestOrBuilder { + // @@protoc_insertion_point(message_implements:leetcodeauth.GetTokenResponse) + GetTokenResponseOrBuilder { private static final long serialVersionUID = 0L; static { com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( @@ -21,107 +21,107 @@ public final class AuthenticateRequest extends /* minor= */ 36, /* patch= */ 2, /* suffix= */ "", - "AuthenticateRequest"); + "GetTokenResponse"); } - // Use AuthenticateRequest.newBuilder() to construct. - private AuthenticateRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + // Use GetTokenResponse.newBuilder() to construct. + private GetTokenResponse(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); } - private AuthenticateRequest() { - login_ = ""; - password_ = ""; + private GetTokenResponse() { + token_ = ""; + csrf_ = ""; } public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor; + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_descriptor; } @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor; + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_descriptor; } @java.lang.Override protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_fieldAccessorTable + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.class, org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.Builder.class); + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.Builder.class); } - public static final int LOGIN_FIELD_NUMBER = 1; + public static final int TOKEN_FIELD_NUMBER = 1; @SuppressWarnings("serial") - private volatile java.lang.Object login_ = ""; + private volatile java.lang.Object token_ = ""; /** - * string login = 1; - * @return The login. + * string token = 1; + * @return The token. */ @java.lang.Override - public java.lang.String getLogin() { - java.lang.Object ref = login_; + public java.lang.String getToken() { + java.lang.Object ref = token_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); - login_ = s; + token_ = s; return s; } } /** - * string login = 1; - * @return The bytes for login. + * string token = 1; + * @return The bytes for token. */ @java.lang.Override public com.google.protobuf.ByteString - getLoginBytes() { - java.lang.Object ref = login_; + getTokenBytes() { + java.lang.Object ref = token_; if (ref instanceof java.lang.String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - login_ = b; + token_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } - public static final int PASSWORD_FIELD_NUMBER = 2; + public static final int CSRF_FIELD_NUMBER = 2; @SuppressWarnings("serial") - private volatile java.lang.Object password_ = ""; + private volatile java.lang.Object csrf_ = ""; /** - * string password = 2; - * @return The password. + * string csrf = 2; + * @return The csrf. */ @java.lang.Override - public java.lang.String getPassword() { - java.lang.Object ref = password_; + public java.lang.String getCsrf() { + java.lang.Object ref = csrf_; if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); - password_ = s; + csrf_ = s; return s; } } /** - * string password = 2; - * @return The bytes for password. + * string csrf = 2; + * @return The bytes for csrf. */ @java.lang.Override public com.google.protobuf.ByteString - getPasswordBytes() { - java.lang.Object ref = password_; + getCsrfBytes() { + java.lang.Object ref = csrf_; if (ref instanceof java.lang.String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - password_ = b; + csrf_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; @@ -142,21 +142,21 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(login_)) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, login_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(token_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, token_); } - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(password_)) { - com.google.protobuf.GeneratedMessage.writeString(output, 2, password_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(csrf_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, csrf_); } getUnknownFields().writeTo(output); } private int computeSerializedSize_0() { int size = 0; - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(login_)) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, login_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(token_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, token_); } - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(password_)) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(2, password_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(csrf_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, csrf_); } return size; } @@ -177,15 +177,15 @@ public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } - if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest)) { + if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse)) { return super.equals(obj); } - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest other = (org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest) obj; + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse other = (org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse) obj; - if (!getLogin() - .equals(other.getLogin())) return false; - if (!getPassword() - .equals(other.getPassword())) return false; + if (!getToken() + .equals(other.getToken())) return false; + if (!getCsrf() + .equals(other.getCsrf())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -197,53 +197,53 @@ public int hashCode() { } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + LOGIN_FIELD_NUMBER; - hash = (53 * hash) + getLogin().hashCode(); - hash = (37 * hash) + PASSWORD_FIELD_NUMBER; - hash = (53 * hash) + getPassword().hashCode(); + hash = (37 * hash) + TOKEN_FIELD_NUMBER; + hash = (53 * hash) + getToken().hashCode(); + hash = (37 * hash) + CSRF_FIELD_NUMBER; + hash = (53 * hash) + getCsrf().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( java.nio.ByteBuffer data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom(byte[] data) + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom(java.io.InputStream input) + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { @@ -251,26 +251,26 @@ public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequ .parseWithIOException(PARSER, input, extensionRegistry); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseDelimitedFrom(java.io.InputStream input) + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessage .parseDelimitedWithIOException(PARSER, input); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseDelimitedFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return com.google.protobuf.GeneratedMessage .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest parseFrom( + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { @@ -283,7 +283,7 @@ public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequ public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } - public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest prototype) { + public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } @java.lang.Override @@ -299,26 +299,26 @@ protected Builder newBuilderForType( return builder; } /** - * Protobuf type {@code codebloom.leetcode.auth.v1.AuthenticateRequest} + * Protobuf type {@code leetcodeauth.GetTokenResponse} */ public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:codebloom.leetcode.auth.v1.AuthenticateRequest) - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequestOrBuilder { + // @@protoc_insertion_point(builder_implements:leetcodeauth.GetTokenResponse) + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponseOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor; + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_descriptor; } @java.lang.Override protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_fieldAccessorTable + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.class, org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.Builder.class); + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.Builder.class); } - // Construct using org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.newBuilder() + // Construct using org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.newBuilder() private Builder() { } @@ -332,25 +332,25 @@ private Builder( public Builder clear() { super.clear(); bitField0_ = 0; - login_ = ""; - password_ = ""; + token_ = ""; + csrf_ = ""; return this; } @java.lang.Override public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor; + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_GetTokenResponse_descriptor; } @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest getDefaultInstanceForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.getDefaultInstance(); + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse getDefaultInstanceForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.getDefaultInstance(); } @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest build() { - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest result = buildPartial(); + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse build() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } @@ -358,42 +358,42 @@ public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest bui } @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest buildPartial() { - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest result = new org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest(this); + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse buildPartial() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse result = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse(this); if (bitField0_ != 0) { buildPartial0(result); } onBuilt(); return result; } - private void buildPartial0(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest result) { + private void buildPartial0(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse result) { int from_bitField0_ = bitField0_; if (((from_bitField0_ & 0x00000001) != 0)) { - result.login_ = login_; + result.token_ = token_; } if (((from_bitField0_ & 0x00000002) != 0)) { - result.password_ = password_; + result.csrf_ = csrf_; } } @java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest) { - return mergeFrom((org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest)other); + if (other instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse) { + return mergeFrom((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse)other); } else { super.mergeFrom(other); return this; } } - public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest other) { - if (other == org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.getDefaultInstance()) return this; - if (!other.getLogin().isEmpty()) { - login_ = other.login_; + public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse other) { + if (other == org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.getDefaultInstance()) return this; + if (!other.getToken().isEmpty()) { + token_ = other.token_; bitField0_ |= 0x00000001; onChanged(); } - if (!other.getPassword().isEmpty()) { - password_ = other.password_; + if (!other.getCsrf().isEmpty()) { + csrf_ = other.csrf_; bitField0_ |= 0x00000002; onChanged(); } @@ -422,12 +422,12 @@ public Builder mergeFrom( done = true; break; case 10: { - login_ = input.readStringRequireUtf8(); + token_ = input.readStringRequireUtf8(); bitField0_ |= 0x00000001; break; } // case 10 case 18: { - password_ = input.readStringRequireUtf8(); + csrf_ = input.readStringRequireUtf8(); bitField0_ |= 0x00000002; break; } // case 18 @@ -448,167 +448,167 @@ public Builder mergeFrom( } private int bitField0_; - private java.lang.Object login_ = ""; + private java.lang.Object token_ = ""; /** - * string login = 1; - * @return The login. + * string token = 1; + * @return The token. */ - public java.lang.String getLogin() { - java.lang.Object ref = login_; + public java.lang.String getToken() { + java.lang.Object ref = token_; if (!(ref instanceof java.lang.String)) { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); - login_ = s; + token_ = s; return s; } else { return (java.lang.String) ref; } } /** - * string login = 1; - * @return The bytes for login. + * string token = 1; + * @return The bytes for token. */ public com.google.protobuf.ByteString - getLoginBytes() { - java.lang.Object ref = login_; + getTokenBytes() { + java.lang.Object ref = token_; if (ref instanceof String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - login_ = b; + token_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } /** - * string login = 1; - * @param value The login to set. + * string token = 1; + * @param value The token to set. * @return This builder for chaining. */ - public Builder setLogin( + public Builder setToken( java.lang.String value) { java.util.Objects.requireNonNull(value); - login_ = value; + token_ = value; bitField0_ |= 0x00000001; onChanged(); return this; } /** - * string login = 1; + * string token = 1; * @return This builder for chaining. */ - public Builder clearLogin() { - login_ = getDefaultInstance().getLogin(); + public Builder clearToken() { + token_ = getDefaultInstance().getToken(); bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } /** - * string login = 1; - * @param value The bytes for login to set. + * string token = 1; + * @param value The bytes for token to set. * @return This builder for chaining. */ - public Builder setLoginBytes( + public Builder setTokenBytes( com.google.protobuf.ByteString value) { java.util.Objects.requireNonNull(value); checkByteStringIsUtf8(value); - login_ = value; + token_ = value; bitField0_ |= 0x00000001; onChanged(); return this; } - private java.lang.Object password_ = ""; + private java.lang.Object csrf_ = ""; /** - * string password = 2; - * @return The password. + * string csrf = 2; + * @return The csrf. */ - public java.lang.String getPassword() { - java.lang.Object ref = password_; + public java.lang.String getCsrf() { + java.lang.Object ref = csrf_; if (!(ref instanceof java.lang.String)) { com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); - password_ = s; + csrf_ = s; return s; } else { return (java.lang.String) ref; } } /** - * string password = 2; - * @return The bytes for password. + * string csrf = 2; + * @return The bytes for csrf. */ public com.google.protobuf.ByteString - getPasswordBytes() { - java.lang.Object ref = password_; + getCsrfBytes() { + java.lang.Object ref = csrf_; if (ref instanceof String) { com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8( (java.lang.String) ref); - password_ = b; + csrf_ = b; return b; } else { return (com.google.protobuf.ByteString) ref; } } /** - * string password = 2; - * @param value The password to set. + * string csrf = 2; + * @param value The csrf to set. * @return This builder for chaining. */ - public Builder setPassword( + public Builder setCsrf( java.lang.String value) { java.util.Objects.requireNonNull(value); - password_ = value; + csrf_ = value; bitField0_ |= 0x00000002; onChanged(); return this; } /** - * string password = 2; + * string csrf = 2; * @return This builder for chaining. */ - public Builder clearPassword() { - password_ = getDefaultInstance().getPassword(); + public Builder clearCsrf() { + csrf_ = getDefaultInstance().getCsrf(); bitField0_ = (bitField0_ & ~0x00000002); onChanged(); return this; } /** - * string password = 2; - * @param value The bytes for password to set. + * string csrf = 2; + * @param value The bytes for csrf to set. * @return This builder for chaining. */ - public Builder setPasswordBytes( + public Builder setCsrfBytes( com.google.protobuf.ByteString value) { java.util.Objects.requireNonNull(value); checkByteStringIsUtf8(value); - password_ = value; + csrf_ = value; bitField0_ |= 0x00000002; onChanged(); return this; } - // @@protoc_insertion_point(builder_scope:codebloom.leetcode.auth.v1.AuthenticateRequest) + // @@protoc_insertion_point(builder_scope:leetcodeauth.GetTokenResponse) } - // @@protoc_insertion_point(class_scope:codebloom.leetcode.auth.v1.AuthenticateRequest) - private static final org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest DEFAULT_INSTANCE; + // @@protoc_insertion_point(class_scope:leetcodeauth.GetTokenResponse) + private static final org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse DEFAULT_INSTANCE; static { - DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest(); + DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse(); } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest getDefaultInstance() { + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse getDefaultInstance() { return DEFAULT_INSTANCE; } - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { @java.lang.Override - public AuthenticateRequest parsePartialFrom( + public GetTokenResponse parsePartialFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { @@ -627,17 +627,17 @@ public AuthenticateRequest parsePartialFrom( } }; - public static com.google.protobuf.Parser parser() { + public static com.google.protobuf.Parser parser() { return PARSER; } @java.lang.Override - public com.google.protobuf.Parser getParserForType() { + public com.google.protobuf.Parser getParserForType() { return PARSER; } @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest getDefaultInstanceForType() { + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse getDefaultInstanceForType() { return DEFAULT_INSTANCE; } diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponseOrBuilder.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponseOrBuilder.java new file mode 100644 index 000000000..f44254289 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/GetTokenResponseOrBuilder.java @@ -0,0 +1,36 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +@com.google.protobuf.Generated +public interface GetTokenResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:leetcodeauth.GetTokenResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * string token = 1; + * @return The token. + */ + java.lang.String getToken(); + /** + * string token = 1; + * @return The bytes for token. + */ + com.google.protobuf.ByteString + getTokenBytes(); + + /** + * string csrf = 2; + * @return The csrf. + */ + java.lang.String getCsrf(); + /** + * string csrf = 2; + * @return The bytes for csrf. + */ + com.google.protobuf.ByteString + getCsrfBytes(); +} diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuth.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuth.java new file mode 100644 index 000000000..718ed4411 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuth.java @@ -0,0 +1,103 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +@com.google.protobuf.Generated +public final class LeetcodeAuth extends com.google.protobuf.GeneratedFile { + private LeetcodeAuth() {} + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 36, + /* patch= */ 2, + /* suffix= */ "", + "LeetcodeAuth"); + } + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + static final com.google.protobuf.Descriptors.Descriptor + internal_static_leetcodeauth_GetTokenRequest_descriptor; + static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_leetcodeauth_GetTokenRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_leetcodeauth_GetTokenResponse_descriptor; + static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_leetcodeauth_GetTokenResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_leetcodeauth_RefreshTokenRequest_descriptor; + static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_leetcodeauth_RefreshTokenRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_leetcodeauth_RefreshTokenResponse_descriptor; + static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_leetcodeauth_RefreshTokenResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static final com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\026v1/leetcode_auth.proto\022\014leetcodeauth\"\021" + + "\n\017GetTokenRequest\"/\n\020GetTokenResponse\022\r\n" + + "\005token\030\001 \001(\t\022\014\n\004csrf\030\002 \001(\t\"\025\n\023RefreshTok" + + "enRequest\"\'\n\024RefreshTokenResponse\022\017\n\007sta" + + "rted\030\001 \001(\0102\267\001\n\023LeetcodeAuthService\022I\n\010ge" + + "tToken\022\035.leetcodeauth.GetTokenRequest\032\036." + + "leetcodeauth.GetTokenResponse\022U\n\014refresh" + + "Token\022!.leetcodeauth.RefreshTokenRequest" + + "\032\".leetcodeauth.RefreshTokenResponseBo\n0" + + "org.patinanetwork.codebloom.grpc.leetcod" + + "eauth.v1P\001Z9patinanetwork.org/grpc/leetc" + + "ode-auth-service;leetcodeauthb\006proto3" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }); + internal_static_leetcodeauth_GetTokenRequest_descriptor = + getDescriptor().getMessageType(0); + internal_static_leetcodeauth_GetTokenRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_leetcodeauth_GetTokenRequest_descriptor, + new java.lang.String[] { }); + internal_static_leetcodeauth_GetTokenResponse_descriptor = + getDescriptor().getMessageType(1); + internal_static_leetcodeauth_GetTokenResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_leetcodeauth_GetTokenResponse_descriptor, + new java.lang.String[] { "Token", "Csrf", }); + internal_static_leetcodeauth_RefreshTokenRequest_descriptor = + getDescriptor().getMessageType(2); + internal_static_leetcodeauth_RefreshTokenRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_leetcodeauth_RefreshTokenRequest_descriptor, + new java.lang.String[] { }); + internal_static_leetcodeauth_RefreshTokenResponse_descriptor = + getDescriptor().getMessageType(3); + internal_static_leetcodeauth_RefreshTokenResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_leetcodeauth_RefreshTokenResponse_descriptor, + new java.lang.String[] { "Started", }); + descriptor.resolveAllFeaturesImmutable(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuthServiceGrpc.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuthServiceGrpc.java new file mode 100644 index 000000000..601ff3da4 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/LeetcodeAuthServiceGrpc.java @@ -0,0 +1,450 @@ +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + */ +@io.grpc.stub.annotations.GrpcGenerated +public final class LeetcodeAuthServiceGrpc { + + private LeetcodeAuthServiceGrpc() {} + + public static final java.lang.String SERVICE_NAME = "leetcodeauth.LeetcodeAuthService"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor getGetTokenMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "getToken", + requestType = org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.class, + responseType = org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getGetTokenMethod() { + io.grpc.MethodDescriptor getGetTokenMethod; + if ((getGetTokenMethod = LeetcodeAuthServiceGrpc.getGetTokenMethod) == null) { + synchronized (LeetcodeAuthServiceGrpc.class) { + if ((getGetTokenMethod = LeetcodeAuthServiceGrpc.getGetTokenMethod) == null) { + LeetcodeAuthServiceGrpc.getGetTokenMethod = getGetTokenMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "getToken")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse.getDefaultInstance())) + .setSchemaDescriptor(new LeetcodeAuthServiceMethodDescriptorSupplier("getToken")) + .build(); + } + } + } + return getGetTokenMethod; + } + + private static volatile io.grpc.MethodDescriptor getRefreshTokenMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "refreshToken", + requestType = org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.class, + responseType = org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getRefreshTokenMethod() { + io.grpc.MethodDescriptor getRefreshTokenMethod; + if ((getRefreshTokenMethod = LeetcodeAuthServiceGrpc.getRefreshTokenMethod) == null) { + synchronized (LeetcodeAuthServiceGrpc.class) { + if ((getRefreshTokenMethod = LeetcodeAuthServiceGrpc.getRefreshTokenMethod) == null) { + LeetcodeAuthServiceGrpc.getRefreshTokenMethod = getRefreshTokenMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "refreshToken")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.getDefaultInstance())) + .setSchemaDescriptor(new LeetcodeAuthServiceMethodDescriptorSupplier("refreshToken")) + .build(); + } + } + } + return getRefreshTokenMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static LeetcodeAuthServiceStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public LeetcodeAuthServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceStub(channel, callOptions); + } + }; + return LeetcodeAuthServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports all types of calls on the service + */ + public static LeetcodeAuthServiceBlockingV2Stub newBlockingV2Stub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public LeetcodeAuthServiceBlockingV2Stub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceBlockingV2Stub(channel, callOptions); + } + }; + return LeetcodeAuthServiceBlockingV2Stub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static LeetcodeAuthServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public LeetcodeAuthServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceBlockingStub(channel, callOptions); + } + }; + return LeetcodeAuthServiceBlockingStub.newStub(factory, channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static LeetcodeAuthServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public LeetcodeAuthServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceFutureStub(channel, callOptions); + } + }; + return LeetcodeAuthServiceFutureStub.newStub(factory, channel); + } + + /** + */ + public interface AsyncService { + + /** + *
+     * may return NOT_FOUND until the first refresh succeeds.
+     * 
+ */ + default void getToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetTokenMethod(), responseObserver); + } + + /** + *
+     * Starts a refresh in the background and returns immediately. Calls made
+     * while a refresh is running are ignored. The stored credentials keep being
+     * served until a refresh succeeds.
+     * 
+ */ + default void refreshToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRefreshTokenMethod(), responseObserver); + } + } + + /** + * Base class for the server implementation of the service LeetcodeAuthService. + */ + public static abstract class LeetcodeAuthServiceImplBase + implements io.grpc.BindableService, AsyncService { + + @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { + return LeetcodeAuthServiceGrpc.bindService(this); + } + } + + /** + * A stub to allow clients to do asynchronous rpc calls to service LeetcodeAuthService. + */ + public static final class LeetcodeAuthServiceStub + extends io.grpc.stub.AbstractAsyncStub { + private LeetcodeAuthServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected LeetcodeAuthServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceStub(channel, callOptions); + } + + /** + *
+     * may return NOT_FOUND until the first refresh succeeds.
+     * 
+ */ + public void getToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getGetTokenMethod(), getCallOptions()), request, responseObserver); + } + + /** + *
+     * Starts a refresh in the background and returns immediately. Calls made
+     * while a refresh is running are ignored. The stored credentials keep being
+     * served until a refresh succeeds.
+     * 
+ */ + public void refreshToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getRefreshTokenMethod(), getCallOptions()), request, responseObserver); + } + } + + /** + * A stub to allow clients to do synchronous rpc calls to service LeetcodeAuthService. + */ + public static final class LeetcodeAuthServiceBlockingV2Stub + extends io.grpc.stub.AbstractBlockingStub { + private LeetcodeAuthServiceBlockingV2Stub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected LeetcodeAuthServiceBlockingV2Stub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceBlockingV2Stub(channel, callOptions); + } + + /** + *
+     * may return NOT_FOUND until the first refresh succeeds.
+     * 
+ */ + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse getToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( + getChannel(), getGetTokenMethod(), getCallOptions(), request); + } + + /** + *
+     * Starts a refresh in the background and returns immediately. Calls made
+     * while a refresh is running are ignored. The stored credentials keep being
+     * served until a refresh succeeds.
+     * 
+ */ + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse refreshToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( + getChannel(), getRefreshTokenMethod(), getCallOptions(), request); + } + } + + /** + * A stub to allow clients to do limited synchronous rpc calls to service LeetcodeAuthService. + */ + public static final class LeetcodeAuthServiceBlockingStub + extends io.grpc.stub.AbstractBlockingStub { + private LeetcodeAuthServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected LeetcodeAuthServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceBlockingStub(channel, callOptions); + } + + /** + *
+     * may return NOT_FOUND until the first refresh succeeds.
+     * 
+ */ + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse getToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getGetTokenMethod(), getCallOptions(), request); + } + + /** + *
+     * Starts a refresh in the background and returns immediately. Calls made
+     * while a refresh is running are ignored. The stored credentials keep being
+     * served until a refresh succeeds.
+     * 
+ */ + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse refreshToken(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getRefreshTokenMethod(), getCallOptions(), request); + } + } + + /** + * A stub to allow clients to do ListenableFuture-style rpc calls to service LeetcodeAuthService. + */ + public static final class LeetcodeAuthServiceFutureStub + extends io.grpc.stub.AbstractFutureStub { + private LeetcodeAuthServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected LeetcodeAuthServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new LeetcodeAuthServiceFutureStub(channel, callOptions); + } + + /** + *
+     * may return NOT_FOUND until the first refresh succeeds.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture getToken( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getGetTokenMethod(), getCallOptions()), request); + } + + /** + *
+     * Starts a refresh in the background and returns immediately. Calls made
+     * while a refresh is running are ignored. The stored credentials keep being
+     * served until a refresh succeeds.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture refreshToken( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getRefreshTokenMethod(), getCallOptions()), request); + } + } + + private static final int METHODID_GET_TOKEN = 0; + private static final int METHODID_REFRESH_TOKEN = 1; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final AsyncService serviceImpl; + private final int methodId; + + MethodHandlers(AsyncService serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_GET_TOKEN: + serviceImpl.getToken((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_REFRESH_TOKEN: + serviceImpl.refreshToken((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getGetTokenMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest, + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse>( + service, METHODID_GET_TOKEN))) + .addMethod( + getRefreshTokenMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest, + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse>( + service, METHODID_REFRESH_TOKEN))) + .build(); + } + + private static abstract class LeetcodeAuthServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + LeetcodeAuthServiceBaseDescriptorSupplier() {} + + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.getDescriptor(); + } + + @java.lang.Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("LeetcodeAuthService"); + } + } + + private static final class LeetcodeAuthServiceFileDescriptorSupplier + extends LeetcodeAuthServiceBaseDescriptorSupplier { + LeetcodeAuthServiceFileDescriptorSupplier() {} + } + + private static final class LeetcodeAuthServiceMethodDescriptorSupplier + extends LeetcodeAuthServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final java.lang.String methodName; + + LeetcodeAuthServiceMethodDescriptorSupplier(java.lang.String methodName) { + this.methodName = methodName; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (LeetcodeAuthServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new LeetcodeAuthServiceFileDescriptorSupplier()) + .addMethod(getGetTokenMethod()) + .addMethod(getRefreshTokenMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequest.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequest.java new file mode 100644 index 000000000..5028fd5c9 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequest.java @@ -0,0 +1,361 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +/** + * Protobuf type {@code leetcodeauth.RefreshTokenRequest} + */ +@com.google.protobuf.Generated +public final class RefreshTokenRequest extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:leetcodeauth.RefreshTokenRequest) + RefreshTokenRequestOrBuilder { +private static final long serialVersionUID = 0L; + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 36, + /* patch= */ 2, + /* suffix= */ "", + "RefreshTokenRequest"); + } + // Use RefreshTokenRequest.newBuilder() to construct. + private RefreshTokenRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private RefreshTokenRequest() { + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_descriptor; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.Builder.class); + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getUnknownFields().writeTo(output); + } + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest)) { + return super.equals(obj); + } + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest other = (org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest) obj; + + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code leetcodeauth.RefreshTokenRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:leetcodeauth.RefreshTokenRequest) + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.Builder.class); + } + + // Construct using org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenRequest_descriptor; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest getDefaultInstanceForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.getDefaultInstance(); + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest build() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest buildPartial() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest result = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest(this); + onBuilt(); + return result; + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest) { + return mergeFrom((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest other) { + if (other == org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest.getDefaultInstance()) return this; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + java.util.Objects.requireNonNull(extensionRegistry); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + + // @@protoc_insertion_point(builder_scope:leetcodeauth.RefreshTokenRequest) + } + + // @@protoc_insertion_point(class_scope:leetcodeauth.RefreshTokenRequest) + private static final org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest(); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RefreshTokenRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequestOrBuilder.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequestOrBuilder.java new file mode 100644 index 000000000..0effe3be9 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenRequestOrBuilder.java @@ -0,0 +1,12 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +@com.google.protobuf.Generated +public interface RefreshTokenRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:leetcodeauth.RefreshTokenRequest) + com.google.protobuf.MessageOrBuilder { +} diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponse.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponse.java new file mode 100644 index 000000000..41aba0c19 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponse.java @@ -0,0 +1,456 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +/** + * Protobuf type {@code leetcodeauth.RefreshTokenResponse} + */ +@com.google.protobuf.Generated +public final class RefreshTokenResponse extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:leetcodeauth.RefreshTokenResponse) + RefreshTokenResponseOrBuilder { +private static final long serialVersionUID = 0L; + static { + com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( + com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, + /* major= */ 4, + /* minor= */ 36, + /* patch= */ 2, + /* suffix= */ "", + "RefreshTokenResponse"); + } + // Use RefreshTokenResponse.newBuilder() to construct. + private RefreshTokenResponse(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private RefreshTokenResponse() { + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_descriptor; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.Builder.class); + } + + public static final int STARTED_FIELD_NUMBER = 1; + private boolean started_ = false; + /** + *
+   * false when a refresh was already running and this call was ignored
+   * 
+ * + * bool started = 1; + * @return The started. + */ + @java.lang.Override + public boolean getStarted() { + return started_; + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (started_ != false) { + output.writeBool(1, started_); + } + getUnknownFields().writeTo(output); + } + private int computeSerializedSize_0() { + int size = 0; + if (started_ != false) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(1, started_); + } + return size; + } + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += computeSerializedSize_0(); + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse)) { + return super.equals(obj); + } + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse other = (org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse) obj; + + if (getStarted() + != other.getStarted()) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + STARTED_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( + getStarted()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code leetcodeauth.RefreshTokenResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:leetcodeauth.RefreshTokenResponse) + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.class, org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.Builder.class); + } + + // Construct using org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + started_ = false; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuth.internal_static_leetcodeauth_RefreshTokenResponse_descriptor; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse getDefaultInstanceForType() { + return org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.getDefaultInstance(); + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse build() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse buildPartial() { + org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse result = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.started_ = started_; + } + } + + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse) { + return mergeFrom((org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse other) { + if (other == org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse.getDefaultInstance()) return this; + if (other.getStarted() != false) { + setStarted(other.getStarted()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + java.util.Objects.requireNonNull(extensionRegistry); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + started_ = input.readBool(); + bitField0_ |= 0x00000001; + break; + } // case 8 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private boolean started_ ; + /** + *
+     * false when a refresh was already running and this call was ignored
+     * 
+ * + * bool started = 1; + * @return The started. + */ + @java.lang.Override + public boolean getStarted() { + return started_; + } + /** + *
+     * false when a refresh was already running and this call was ignored
+     * 
+ * + * bool started = 1; + * @param value The started to set. + * @return This builder for chaining. + */ + public Builder setStarted(boolean value) { + + started_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + *
+     * false when a refresh was already running and this call was ignored
+     * 
+ * + * bool started = 1; + * @return This builder for chaining. + */ + public Builder clearStarted() { + bitField0_ = (bitField0_ & ~0x00000001); + started_ = false; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:leetcodeauth.RefreshTokenResponse) + } + + // @@protoc_insertion_point(class_scope:leetcodeauth.RefreshTokenResponse) + private static final org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse(); + } + + public static org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RefreshTokenResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponseOrBuilder.java b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponseOrBuilder.java new file mode 100644 index 000000000..08d1034a4 --- /dev/null +++ b/lib/leetcode-auth-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcodeauth/v1/RefreshTokenResponseOrBuilder.java @@ -0,0 +1,22 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: v1/leetcode_auth.proto +// Protobuf Java Version: 4.36.2 + +package org.patinanetwork.codebloom.grpc.leetcodeauth.v1; + +@com.google.protobuf.Generated +public interface RefreshTokenResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:leetcodeauth.RefreshTokenResponse) + com.google.protobuf.MessageOrBuilder { + + /** + *
+   * false when a refresh was already running and this call was ignored
+   * 
+ * + * bool started = 1; + * @return The started. + */ + boolean getStarted(); +} diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequestOrBuilder.java b/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequestOrBuilder.java deleted file mode 100644 index 3dacf6ebc..000000000 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateRequestOrBuilder.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// NO CHECKED-IN PROTOBUF GENCODE -// source: LeetcodeAuthStealerService.proto -// Protobuf Java Version: 4.36.2 - -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; - -@com.google.protobuf.Generated -public interface AuthenticateRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:codebloom.leetcode.auth.v1.AuthenticateRequest) - com.google.protobuf.MessageOrBuilder { - - /** - * string login = 1; - * @return The login. - */ - java.lang.String getLogin(); - /** - * string login = 1; - * @return The bytes for login. - */ - com.google.protobuf.ByteString - getLoginBytes(); - - /** - * string password = 2; - * @return The password. - */ - java.lang.String getPassword(); - /** - * string password = 2; - * @return The bytes for password. - */ - com.google.protobuf.ByteString - getPasswordBytes(); -} diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponse.java b/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponse.java deleted file mode 100644 index cf72223cd..000000000 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponse.java +++ /dev/null @@ -1,645 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// NO CHECKED-IN PROTOBUF GENCODE -// source: LeetcodeAuthStealerService.proto -// Protobuf Java Version: 4.36.2 - -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; - -/** - * Protobuf type {@code codebloom.leetcode.auth.v1.AuthenticateResponse} - */ -@com.google.protobuf.Generated -public final class AuthenticateResponse extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:codebloom.leetcode.auth.v1.AuthenticateResponse) - AuthenticateResponseOrBuilder { -private static final long serialVersionUID = 0L; - static { - com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( - com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, - /* major= */ 4, - /* minor= */ 36, - /* patch= */ 2, - /* suffix= */ "", - "AuthenticateResponse"); - } - // Use AuthenticateResponse.newBuilder() to construct. - private AuthenticateResponse(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private AuthenticateResponse() { - leetcodeSession_ = ""; - csrfToken_ = ""; - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.class, org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.Builder.class); - } - - public static final int LEETCODE_SESSION_FIELD_NUMBER = 1; - @SuppressWarnings("serial") - private volatile java.lang.Object leetcodeSession_ = ""; - /** - * string leetcode_session = 1; - * @return The leetcodeSession. - */ - @java.lang.Override - public java.lang.String getLeetcodeSession() { - java.lang.Object ref = leetcodeSession_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - leetcodeSession_ = s; - return s; - } - } - /** - * string leetcode_session = 1; - * @return The bytes for leetcodeSession. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getLeetcodeSessionBytes() { - java.lang.Object ref = leetcodeSession_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - leetcodeSession_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int CSRF_TOKEN_FIELD_NUMBER = 2; - @SuppressWarnings("serial") - private volatile java.lang.Object csrfToken_ = ""; - /** - * string csrf_token = 2; - * @return The csrfToken. - */ - @java.lang.Override - public java.lang.String getCsrfToken() { - java.lang.Object ref = csrfToken_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - csrfToken_ = s; - return s; - } - } - /** - * string csrf_token = 2; - * @return The bytes for csrfToken. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getCsrfTokenBytes() { - java.lang.Object ref = csrfToken_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - csrfToken_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(leetcodeSession_)) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, leetcodeSession_); - } - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(csrfToken_)) { - com.google.protobuf.GeneratedMessage.writeString(output, 2, csrfToken_); - } - getUnknownFields().writeTo(output); - } - private int computeSerializedSize_0() { - int size = 0; - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(leetcodeSession_)) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, leetcodeSession_); - } - if (!com.google.protobuf.GeneratedMessage.isStringEmpty(csrfToken_)) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(2, csrfToken_); - } - return size; - } - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - size += computeSerializedSize_0(); - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse)) { - return super.equals(obj); - } - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse other = (org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse) obj; - - if (!getLeetcodeSession() - .equals(other.getLeetcodeSession())) return false; - if (!getCsrfToken() - .equals(other.getCsrfToken())) return false; - if (!getUnknownFields().equals(other.getUnknownFields())) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + LEETCODE_SESSION_FIELD_NUMBER; - hash = (53 * hash) + getLeetcodeSession().hashCode(); - hash = (37 * hash) + CSRF_TOKEN_FIELD_NUMBER; - hash = (53 * hash) + getCsrfToken().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code codebloom.leetcode.auth.v1.AuthenticateResponse} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:codebloom.leetcode.auth.v1.AuthenticateResponse) - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.class, org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.Builder.class); - } - - // Construct using org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.newBuilder() - private Builder() { - - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - - } - @java.lang.Override - public Builder clear() { - super.clear(); - bitField0_ = 0; - leetcodeSession_ = ""; - csrfToken_ = ""; - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor; - } - - @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse getDefaultInstanceForType() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.getDefaultInstance(); - } - - @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse build() { - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse buildPartial() { - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse result = new org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse(this); - if (bitField0_ != 0) { buildPartial0(result); } - onBuilt(); - return result; - } - - private void buildPartial0(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse result) { - int from_bitField0_ = bitField0_; - if (((from_bitField0_ & 0x00000001) != 0)) { - result.leetcodeSession_ = leetcodeSession_; - } - if (((from_bitField0_ & 0x00000002) != 0)) { - result.csrfToken_ = csrfToken_; - } - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse) { - return mergeFrom((org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse other) { - if (other == org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.getDefaultInstance()) return this; - if (!other.getLeetcodeSession().isEmpty()) { - leetcodeSession_ = other.leetcodeSession_; - bitField0_ |= 0x00000001; - onChanged(); - } - if (!other.getCsrfToken().isEmpty()) { - csrfToken_ = other.csrfToken_; - bitField0_ |= 0x00000002; - onChanged(); - } - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - java.util.Objects.requireNonNull(extensionRegistry); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - leetcodeSession_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000001; - break; - } // case 10 - case 18: { - csrfToken_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000002; - break; - } // case 18 - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } finally { - onChanged(); - } // finally - return this; - } - private int bitField0_; - - private java.lang.Object leetcodeSession_ = ""; - /** - * string leetcode_session = 1; - * @return The leetcodeSession. - */ - public java.lang.String getLeetcodeSession() { - java.lang.Object ref = leetcodeSession_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - leetcodeSession_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string leetcode_session = 1; - * @return The bytes for leetcodeSession. - */ - public com.google.protobuf.ByteString - getLeetcodeSessionBytes() { - java.lang.Object ref = leetcodeSession_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - leetcodeSession_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string leetcode_session = 1; - * @param value The leetcodeSession to set. - * @return This builder for chaining. - */ - public Builder setLeetcodeSession( - java.lang.String value) { - java.util.Objects.requireNonNull(value); - leetcodeSession_ = value; - bitField0_ |= 0x00000001; - onChanged(); - return this; - } - /** - * string leetcode_session = 1; - * @return This builder for chaining. - */ - public Builder clearLeetcodeSession() { - leetcodeSession_ = getDefaultInstance().getLeetcodeSession(); - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - * string leetcode_session = 1; - * @param value The bytes for leetcodeSession to set. - * @return This builder for chaining. - */ - public Builder setLeetcodeSessionBytes( - com.google.protobuf.ByteString value) { - java.util.Objects.requireNonNull(value); - checkByteStringIsUtf8(value); - leetcodeSession_ = value; - bitField0_ |= 0x00000001; - onChanged(); - return this; - } - - private java.lang.Object csrfToken_ = ""; - /** - * string csrf_token = 2; - * @return The csrfToken. - */ - public java.lang.String getCsrfToken() { - java.lang.Object ref = csrfToken_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - csrfToken_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string csrf_token = 2; - * @return The bytes for csrfToken. - */ - public com.google.protobuf.ByteString - getCsrfTokenBytes() { - java.lang.Object ref = csrfToken_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - csrfToken_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string csrf_token = 2; - * @param value The csrfToken to set. - * @return This builder for chaining. - */ - public Builder setCsrfToken( - java.lang.String value) { - java.util.Objects.requireNonNull(value); - csrfToken_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - /** - * string csrf_token = 2; - * @return This builder for chaining. - */ - public Builder clearCsrfToken() { - csrfToken_ = getDefaultInstance().getCsrfToken(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - return this; - } - /** - * string csrf_token = 2; - * @param value The bytes for csrfToken to set. - * @return This builder for chaining. - */ - public Builder setCsrfTokenBytes( - com.google.protobuf.ByteString value) { - java.util.Objects.requireNonNull(value); - checkByteStringIsUtf8(value); - csrfToken_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:codebloom.leetcode.auth.v1.AuthenticateResponse) - } - - // @@protoc_insertion_point(class_scope:codebloom.leetcode.auth.v1.AuthenticateResponse) - private static final org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse(); - } - - public static org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public AuthenticateResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - -} - diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponseOrBuilder.java b/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponseOrBuilder.java deleted file mode 100644 index 3fec30fce..000000000 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/AuthenticateResponseOrBuilder.java +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// NO CHECKED-IN PROTOBUF GENCODE -// source: LeetcodeAuthStealerService.proto -// Protobuf Java Version: 4.36.2 - -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; - -@com.google.protobuf.Generated -public interface AuthenticateResponseOrBuilder extends - // @@protoc_insertion_point(interface_extends:codebloom.leetcode.auth.v1.AuthenticateResponse) - com.google.protobuf.MessageOrBuilder { - - /** - * string leetcode_session = 1; - * @return The leetcodeSession. - */ - java.lang.String getLeetcodeSession(); - /** - * string leetcode_session = 1; - * @return The bytes for leetcodeSession. - */ - com.google.protobuf.ByteString - getLeetcodeSessionBytes(); - - /** - * string csrf_token = 2; - * @return The csrfToken. - */ - java.lang.String getCsrfToken(); - /** - * string csrf_token = 2; - * @return The bytes for csrfToken. - */ - com.google.protobuf.ByteString - getCsrfTokenBytes(); -} diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceGrpc.java b/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceGrpc.java deleted file mode 100644 index 2013a8363..000000000 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceGrpc.java +++ /dev/null @@ -1,329 +0,0 @@ -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; - -import static io.grpc.MethodDescriptor.generateFullMethodName; - -/** - */ -@io.grpc.stub.annotations.GrpcGenerated -public final class LeetcodeAuthStealerServiceGrpc { - - private LeetcodeAuthStealerServiceGrpc() {} - - public static final java.lang.String SERVICE_NAME = "codebloom.leetcode.auth.v1.LeetcodeAuthStealerService"; - - // Static method descriptors that strictly reflect the proto. - private static volatile io.grpc.MethodDescriptor getAuthenticateMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "Authenticate", - requestType = org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.class, - responseType = org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getAuthenticateMethod() { - io.grpc.MethodDescriptor getAuthenticateMethod; - if ((getAuthenticateMethod = LeetcodeAuthStealerServiceGrpc.getAuthenticateMethod) == null) { - synchronized (LeetcodeAuthStealerServiceGrpc.class) { - if ((getAuthenticateMethod = LeetcodeAuthStealerServiceGrpc.getAuthenticateMethod) == null) { - LeetcodeAuthStealerServiceGrpc.getAuthenticateMethod = getAuthenticateMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Authenticate")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse.getDefaultInstance())) - .setSchemaDescriptor(new LeetcodeAuthStealerServiceMethodDescriptorSupplier("Authenticate")) - .build(); - } - } - } - return getAuthenticateMethod; - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static LeetcodeAuthStealerServiceStub newStub(io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public LeetcodeAuthStealerServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceStub(channel, callOptions); - } - }; - return LeetcodeAuthStealerServiceStub.newStub(factory, channel); - } - - /** - * Creates a new blocking-style stub that supports all types of calls on the service - */ - public static LeetcodeAuthStealerServiceBlockingV2Stub newBlockingV2Stub( - io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public LeetcodeAuthStealerServiceBlockingV2Stub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceBlockingV2Stub(channel, callOptions); - } - }; - return LeetcodeAuthStealerServiceBlockingV2Stub.newStub(factory, channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static LeetcodeAuthStealerServiceBlockingStub newBlockingStub( - io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public LeetcodeAuthStealerServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceBlockingStub(channel, callOptions); - } - }; - return LeetcodeAuthStealerServiceBlockingStub.newStub(factory, channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static LeetcodeAuthStealerServiceFutureStub newFutureStub( - io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public LeetcodeAuthStealerServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceFutureStub(channel, callOptions); - } - }; - return LeetcodeAuthStealerServiceFutureStub.newStub(factory, channel); - } - - /** - */ - public interface AsyncService { - - /** - */ - default void authenticate(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getAuthenticateMethod(), responseObserver); - } - } - - /** - * Base class for the server implementation of the service LeetcodeAuthStealerService. - */ - public static abstract class LeetcodeAuthStealerServiceImplBase - implements io.grpc.BindableService, AsyncService { - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return LeetcodeAuthStealerServiceGrpc.bindService(this); - } - } - - /** - * A stub to allow clients to do asynchronous rpc calls to service LeetcodeAuthStealerService. - */ - public static final class LeetcodeAuthStealerServiceStub - extends io.grpc.stub.AbstractAsyncStub { - private LeetcodeAuthStealerServiceStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected LeetcodeAuthStealerServiceStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceStub(channel, callOptions); - } - - /** - */ - public void authenticate(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getAuthenticateMethod(), getCallOptions()), request, responseObserver); - } - } - - /** - * A stub to allow clients to do synchronous rpc calls to service LeetcodeAuthStealerService. - */ - public static final class LeetcodeAuthStealerServiceBlockingV2Stub - extends io.grpc.stub.AbstractBlockingStub { - private LeetcodeAuthStealerServiceBlockingV2Stub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected LeetcodeAuthStealerServiceBlockingV2Stub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceBlockingV2Stub(channel, callOptions); - } - - /** - */ - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse authenticate(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest request) throws io.grpc.StatusException { - return io.grpc.stub.ClientCalls.blockingV2UnaryCall( - getChannel(), getAuthenticateMethod(), getCallOptions(), request); - } - } - - /** - * A stub to allow clients to do limited synchronous rpc calls to service LeetcodeAuthStealerService. - */ - public static final class LeetcodeAuthStealerServiceBlockingStub - extends io.grpc.stub.AbstractBlockingStub { - private LeetcodeAuthStealerServiceBlockingStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected LeetcodeAuthStealerServiceBlockingStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceBlockingStub(channel, callOptions); - } - - /** - */ - public org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse authenticate(org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( - getChannel(), getAuthenticateMethod(), getCallOptions(), request); - } - } - - /** - * A stub to allow clients to do ListenableFuture-style rpc calls to service LeetcodeAuthStealerService. - */ - public static final class LeetcodeAuthStealerServiceFutureStub - extends io.grpc.stub.AbstractFutureStub { - private LeetcodeAuthStealerServiceFutureStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected LeetcodeAuthStealerServiceFutureStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new LeetcodeAuthStealerServiceFutureStub(channel, callOptions); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture authenticate( - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest request) { - return io.grpc.stub.ClientCalls.futureUnaryCall( - getChannel().newCall(getAuthenticateMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_AUTHENTICATE = 0; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final AsyncService serviceImpl; - private final int methodId; - - MethodHandlers(AsyncService serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_AUTHENTICATE: - serviceImpl.authenticate((org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getAuthenticateMethod(), - io.grpc.stub.ServerCalls.asyncUnaryCall( - new MethodHandlers< - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest, - org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse>( - service, METHODID_AUTHENTICATE))) - .build(); - } - - private static abstract class LeetcodeAuthStealerServiceBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { - LeetcodeAuthStealerServiceBaseDescriptorSupplier() {} - - @java.lang.Override - public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceOuterClass.getDescriptor(); - } - - @java.lang.Override - public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { - return getFileDescriptor().findServiceByName("LeetcodeAuthStealerService"); - } - } - - private static final class LeetcodeAuthStealerServiceFileDescriptorSupplier - extends LeetcodeAuthStealerServiceBaseDescriptorSupplier { - LeetcodeAuthStealerServiceFileDescriptorSupplier() {} - } - - private static final class LeetcodeAuthStealerServiceMethodDescriptorSupplier - extends LeetcodeAuthStealerServiceBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final java.lang.String methodName; - - LeetcodeAuthStealerServiceMethodDescriptorSupplier(java.lang.String methodName) { - this.methodName = methodName; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { - return getServiceDescriptor().findMethodByName(methodName); - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (LeetcodeAuthStealerServiceGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .setSchemaDescriptor(new LeetcodeAuthStealerServiceFileDescriptorSupplier()) - .addMethod(getAuthenticateMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceOuterClass.java b/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceOuterClass.java deleted file mode 100644 index e56ef60d7..000000000 --- a/lib/leetcode-auth-stealer-service/src/main/java/org/patinanetwork/codebloom/grpc/leetcode/auth/v1/LeetcodeAuthStealerServiceOuterClass.java +++ /dev/null @@ -1,79 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// NO CHECKED-IN PROTOBUF GENCODE -// source: LeetcodeAuthStealerService.proto -// Protobuf Java Version: 4.36.2 - -package org.patinanetwork.codebloom.grpc.leetcode.auth.v1; - -@com.google.protobuf.Generated -public final class LeetcodeAuthStealerServiceOuterClass extends com.google.protobuf.GeneratedFile { - private LeetcodeAuthStealerServiceOuterClass() {} - static { - com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( - com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, - /* major= */ 4, - /* minor= */ 36, - /* patch= */ 2, - /* suffix= */ "", - "LeetcodeAuthStealerServiceOuterClass"); - } - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - static final com.google.protobuf.Descriptors.Descriptor - internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor; - static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_fieldAccessorTable; - static final com.google.protobuf.Descriptors.Descriptor - internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor; - static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static final com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n LeetcodeAuthStealerService.proto\022\032code" + - "bloom.leetcode.auth.v1\"6\n\023AuthenticateRe" + - "quest\022\r\n\005login\030\001 \001(\t\022\020\n\010password\030\002 \001(\t\"D" + - "\n\024AuthenticateResponse\022\030\n\020leetcode_sessi" + - "on\030\001 \001(\t\022\022\n\ncsrf_token\030\002 \001(\t2\217\001\n\032Leetcod" + - "eAuthStealerService\022q\n\014Authenticate\022/.co" + - "debloom.leetcode.auth.v1.AuthenticateReq" + - "uest\0320.codebloom.leetcode.auth.v1.Authen" + - "ticateResponseB5\n1org.patinanetwork.code" + - "bloom.grpc.leetcode.auth.v1P\001b\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }); - internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor = - getDescriptor().getMessageType(0); - internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_codebloom_leetcode_auth_v1_AuthenticateRequest_descriptor, - new java.lang.String[] { "Login", "Password", }); - internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor = - getDescriptor().getMessageType(1); - internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_codebloom_leetcode_auth_v1_AuthenticateResponse_descriptor, - new java.lang.String[] { "LeetcodeSession", "CsrfToken", }); - descriptor.resolveAllFeaturesImmutable(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/mvnw b/mvnw index 41c0f0c23..1ddd97b9e 100755 --- a/mvnw +++ b/mvnw @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven Start Up Batch script +# Apache Maven Wrapper startup batch script, version 3.3.4 # # Required ENV vars: # ------------------ @@ -27,284 +27,312 @@ # # Optional ENV vars # ----------------- -# M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- -if [ -z "$MAVEN_SKIP_RC" ] ; then +if [ -z "$MAVEN_SKIP_RC" ]; then - if [ -f /etc/mavenrc ] ; then + if [ -f /usr/local/etc/mavenrc ]; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ]; then . /etc/mavenrc fi - if [ -f "$HOME/.mavenrc" ] ; then + if [ -f "$HOME/.mavenrc" ]; then . "$HOME/.mavenrc" fi fi # OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; +cygwin=false +darwin=false mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi +case "$(uname)" in +CYGWIN*) cygwin=true ;; +MINGW*) mingw=true ;; +Darwin*) + darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)" + export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home" + export JAVA_HOME fi - ;; + fi + ;; esac -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` +if [ -z "$JAVA_HOME" ]; then + if [ -r /etc/gentoo-release ]; then + JAVA_HOME=$(java-config --jre-home) fi fi -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - # For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +if $cygwin; then + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --unix "$CLASSPATH") fi # For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +if $mingw; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] \ + && JAVA_HOME="$( + cd "$JAVA_HOME" || ( + echo "cannot cd into $JAVA_HOME." >&2 + exit 1 + ) + pwd + )" fi if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin; then + javaHome="$(dirname "$javaExecutable")" + javaExecutable="$(cd "$javaHome" && pwd -P)/javac" else - javaExecutable="`readlink -f \"$javaExecutable\"`" + javaExecutable="$(readlink -f "$javaExecutable")" fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` + javaHome="$(dirname "$javaExecutable")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') JAVA_HOME="$javaHome" export JAVA_HOME fi fi fi -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +if [ -z "$JAVACMD" ]; then + if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD="`which java`" + JAVACMD="$( + \unset -f command 2>/dev/null + \command -v java + )" fi fi -if [ ! -x "$JAVACMD" ] ; then +if [ ! -x "$JAVACMD" ]; then echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute $JAVACMD" >&2 exit 1 fi -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." +if [ -z "$JAVA_HOME" ]; then + echo "Warning: JAVA_HOME environment variable is not set." >&2 fi -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" + if [ -z "$1" ]; then + echo "Path not specified to find_maven_basedir" >&2 return 1 fi basedir="$1" wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then + while [ "$wdir" != '/' ]; do + if [ -d "$wdir"/.mvn ]; then basedir=$wdir break fi # workaround for JBEAP-8937 (on Solaris 10/Sparc) if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` + wdir=$( + cd "$wdir/.." || exit 1 + pwd + ) fi # end of workaround done - echo "${basedir}" + printf '%s' "$( + cd "$basedir" || exit 1 + pwd + )" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' <"$1" fi } -BASE_DIR=`find_maven_basedir "$(pwd)"` +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") if [ -z "$BASE_DIR" ]; then - exit 1; + exit 1 fi +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + ########################################################################################## # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central # This allows using the maven wrapper in projects that prohibit checking in binary data. ########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar" + fi + while IFS="=" read -r key value; do + case "$key" in wrapperUrl) + wrapperUrl=$(trim "${value-}") + break + ;; + esac + done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget >/dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget ${QUIET:+"$QUIET"} "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + wget ${QUIET:+"$QUIET"} --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" + elif command -v curl >/dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl ${QUIET:+"$QUIET"} -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl ${QUIET:+"$QUIET"} --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi fi + fi fi ########################################################################################## # End of extension ########################################################################################## -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in wrapperSha256Sum) + wrapperSha256Sum=$(trim "${value-}") + break + ;; + esac +done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c - >/dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c >/dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi fi + MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] \ + && MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") fi # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +# shellcheck disable=SC2086 # safe args exec "$JAVACMD" \ $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd index 86115719e..c453424c6 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,182 +1,206 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. >&2 +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. >&2 +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash;"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Error 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Error 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Error 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index dcc657e7c..82fac982c 100644 --- a/pom.xml +++ b/pom.xml @@ -235,7 +235,28 @@ true + + + kr.motd.maven + os-maven-plugin + 1.7.1 + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + + ${project.basedir}/internal/leetcode-auth-service/proto + com.google.protobuf:protoc:4.36.2:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:1.84.1:exe:${os.detected.classifier} + ${project.basedir}/lib/leetcode-auth-service/src/main/java + false + + org.codehaus.mojo build-helper-maven-plugin @@ -249,7 +270,7 @@ - lib/leetcode-auth-stealer-service/src/main/java + lib/leetcode-auth-service/src/main/java diff --git a/src/main/java/org/patinanetwork/codebloom/api/admin/AdminController.java b/src/main/java/org/patinanetwork/codebloom/api/admin/AdminController.java index 796ea1154..d58d47831 100644 --- a/src/main/java/org/patinanetwork/codebloom/api/admin/AdminController.java +++ b/src/main/java/org/patinanetwork/codebloom/api/admin/AdminController.java @@ -32,10 +32,10 @@ import org.patinanetwork.codebloom.common.dto.autogen.UnsafeGenericFailureResponse; import org.patinanetwork.codebloom.common.dto.question.QuestionWithUserDto; import org.patinanetwork.codebloom.common.dto.user.UserDto; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.patinanetwork.codebloom.common.security.AuthenticationObject; import org.patinanetwork.codebloom.common.security.annotation.Protected; import org.patinanetwork.codebloom.common.time.StandardizedOffsetDateTime; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -54,7 +54,7 @@ public class AdminController { private final DiscordClubManager discordClubManager; private final LeaderboardManager leaderboardManager; private final DiscordClubRepository discordClubRepository; - private final LeetcodeAuthStealer leetcodeAuthStealer; + private final LeetcodeAuthenticationService leetcodeAuthenticationService; private final IncompleteQuestionRequeuer incompleteQuestionRequeuer; public AdminController( @@ -65,7 +65,7 @@ public AdminController( final DiscordClubManager discordClubManager, final LeaderboardManager leaderboardManager, final DiscordClubRepository discordClubRepository, - final LeetcodeAuthStealer leetcodeAuthStealer, + final LeetcodeAuthenticationService leetcodeAuthenticationService, final IncompleteQuestionRequeuer incompleteQuestionRequeuer) { this.leaderboardRepository = leaderboardRepository; this.userRepository = userRepository; @@ -74,7 +74,7 @@ public AdminController( this.discordClubManager = discordClubManager; this.leaderboardManager = leaderboardManager; this.discordClubRepository = discordClubRepository; - this.leetcodeAuthStealer = leetcodeAuthStealer; + this.leetcodeAuthenticationService = leetcodeAuthenticationService; this.incompleteQuestionRequeuer = incompleteQuestionRequeuer; } @@ -351,7 +351,7 @@ public ResponseEntity> sendDiscordAnnouncement( @PostMapping("/leetcode/token") public ResponseEntity> refreshLeetcodeToken( @Protected(admin = true) final AuthenticationObject authenticationObject) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); return ResponseEntity.ok(ApiResponder.success("LeetCode token refresh triggered.", Empty.of())); } diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientImpl.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientImpl.java index db125de88..e9e3b0d2e 100644 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientImpl.java +++ b/src/main/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientImpl.java @@ -24,6 +24,7 @@ import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.patinanetwork.codebloom.common.db.models.question.QuestionDifficulty; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.patinanetwork.codebloom.common.leetcode.models.Lang; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeDetailedQuestion; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeQuestion; @@ -38,7 +39,6 @@ import org.patinanetwork.codebloom.common.leetcode.queries.GetUserProfile; import org.patinanetwork.codebloom.common.leetcode.queries.SelectAcceptedSubmisisonsQuery; import org.patinanetwork.codebloom.common.leetcode.queries.SelectProblemQuery; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @@ -51,6 +51,7 @@ public class LeetcodeClientImpl implements LeetcodeClient { private static final String GRAPHQL_ENDPOINT = "https://leetcode.com/graphql"; private static final String ERROR_COUNT_METRIC_NAME = "leetcode.client.exception"; + private static final String EMPTY_COOKIE = ""; private final ObjectMapper mapper; @@ -59,14 +60,15 @@ public class LeetcodeClientImpl implements LeetcodeClient { @VisibleForTesting HttpClient client; - private final LeetcodeAuthStealer leetcodeAuthStealer; + private final LeetcodeAuthenticationService leetcodeAuthenticationService; - public LeetcodeClientImpl(final MeterRegistry meterRegistry, final LeetcodeAuthStealer leetcodeAuthStealer) { + public LeetcodeClientImpl( + final MeterRegistry meterRegistry, final LeetcodeAuthenticationService leetcodeAuthenticationService) { this.meterRegistry = meterRegistry; this.client = HttpClient.newHttpClient(); this.mapper = new ObjectMapper(); - this.leetcodeAuthStealer = leetcodeAuthStealer; + this.leetcodeAuthenticationService = leetcodeAuthenticationService; } private Counter errorCounter() { @@ -86,16 +88,19 @@ private Counter errorCounter() { private String buildCookieHeader() { List cookies = new ArrayList<>(); + var authCreds = leetcodeAuthenticationService.getAuthenticationCredentials(); - String session = leetcodeAuthStealer.getCookie(); - cookies.add("LEETCODE_SESSION=" + session); + var session = authCreds.token(); + session.ifPresent(s -> { + cookies.add("LEETCODE_SESSION=" + s); + }); - String csrf = leetcodeAuthStealer.getCsrf(); - if (csrf != null) { - cookies.add("csrftoken=" + csrf); - } + var csrf = authCreds.csrf(); + csrf.ifPresent(c -> { + cookies.add("csrftoken=" + c); + }); - return String.join("; ", cookies); + return cookies.isEmpty() ? EMPTY_COOKIE : String.join("; ", cookies); } /** @@ -152,7 +157,7 @@ public LeetcodeQuestion findQuestionBySlug(final String slug) { if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException("API Returned status " + statusCode + ": " + body); } @@ -244,7 +249,7 @@ public ArrayList findSubmissionsByUsername(final String user if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException("API Returned status " + statusCode + ": " + body); } @@ -304,7 +309,7 @@ public LeetcodeDetailedQuestion findSubmissionDetailBySubmissionId(final long su if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException("API Returned status " + statusCode + ": " + body); } @@ -318,7 +323,7 @@ public LeetcodeDetailedQuestion findSubmissionDetailBySubmissionId(final long su long memory = baseNode.path("memory").asLong(); String memoryDisplay = baseNode.path("memoryDisplay").asText(); float memoryPercentile = (float) baseNode.path("memoryPercentile").asDouble(); - String code = baseNode.path("code").asText(); + String code = baseNode.path("code").asText(null); String langName = baseNode.path("lang").path("name").asText(); String langVerboseName = baseNode.path("lang").path("verboseName").asText(); Lang lang = (Strings.isNullOrEmpty(langName) || Strings.isNullOrEmpty(langVerboseName)) @@ -327,7 +332,7 @@ public LeetcodeDetailedQuestion findSubmissionDetailBySubmissionId(final long su // if any of these are empty, then extremely likely that we're throttled. if (Strings.isNullOrEmpty(runtimeDisplay) || Strings.isNullOrEmpty(memoryDisplay)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } LeetcodeDetailedQuestion question = new LeetcodeDetailedQuestion( @@ -366,7 +371,7 @@ public POTD getPotd() { if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException("API Returned status " + statusCode + ": " + body); } @@ -413,7 +418,7 @@ public UserProfile getUserProfile(final String username) { if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException("API Returned status " + statusCode + ": " + body); } @@ -453,7 +458,7 @@ public Set getAllTopicTags() { if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException( "Non-successful response getting topics from Leetcode API. Status code: " + statusCode); @@ -501,7 +506,7 @@ public List getAllProblems() { String body = response.body(); if (statusCode != 200) { if (isThrottled(statusCode)) { - leetcodeAuthStealer.reloadCookie(); + leetcodeAuthenticationService.refresh(); } throw new LeetcodeClientException( "Non-successful response getting all questions from Leetcode API. Status code: " + statusCode); diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/AuthenticationCredentials.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/AuthenticationCredentials.java index 21b5fdc18..3d30f5329 100644 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/AuthenticationCredentials.java +++ b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/AuthenticationCredentials.java @@ -1,3 +1,5 @@ package org.patinanetwork.codebloom.common.leetcode.auth; -public record AuthenticationCredentials(String token, String csrf) {} +import java.util.Optional; + +public record AuthenticationCredentials(Optional token, Optional csrf) {} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/CiLeetcodeAuthenticationService.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/CiLeetcodeAuthenticationService.java new file mode 100644 index 000000000..7c8597356 --- /dev/null +++ b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/CiLeetcodeAuthenticationService.java @@ -0,0 +1,18 @@ +package org.patinanetwork.codebloom.common.leetcode.auth; + +import java.util.Optional; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +@Service +@Profile("ci") +public class CiLeetcodeAuthenticationService implements LeetcodeAuthenticationService { + + @Override + public AuthenticationCredentials getAuthenticationCredentials() { + return new AuthenticationCredentials(Optional.empty(), Optional.empty()); + } + + @Override + public void refresh() {} +} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationService.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationService.java new file mode 100644 index 000000000..d8095ef80 --- /dev/null +++ b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationService.java @@ -0,0 +1,39 @@ +package org.patinanetwork.codebloom.common.leetcode.auth; + +import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuthServiceGrpc.LeetcodeAuthServiceBlockingStub; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest; +import org.springframework.context.annotation.Profile; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +@AllArgsConstructor +@Profile("!ci") +public class DefaultLeetcodeAuthenticationService implements LeetcodeAuthenticationService { + + private final LeetcodeAuthServiceBlockingStub leetcodeAuthGrpcService; + + public AuthenticationCredentials getAuthenticationCredentials() { + try { + + var tokenResponse = leetcodeAuthGrpcService.getToken( + GetTokenRequest.newBuilder().build()); + + return new AuthenticationCredentials( + Optional.ofNullable(tokenResponse.getToken()), Optional.ofNullable(tokenResponse.getCsrf())); + } catch (Exception e) { + log.error("LeetcodeAuthenticationService.getAuthenticationCredentials failed", e); + return new AuthenticationCredentials(Optional.empty(), Optional.empty()); + } + } + + @Async + public void refresh() { + leetcodeAuthGrpcService.refreshToken(RefreshTokenRequest.newBuilder().build()); + } +} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClient.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClient.java deleted file mode 100644 index e2c183c9a..000000000 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClient.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import java.util.Optional; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceGrpc.LeetcodeAuthStealerServiceBlockingStub; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -@Component -@Primary -@EnableConfigurationProperties(DirectLeetcodeAuthenticationClientProperties.class) -@ConditionalOnProperty(name = "leetcode.auth.strategy", havingValue = "direct") -@AllArgsConstructor -@Slf4j -public class DirectLeetcodeAuthenticationClient implements LeetcodeAuthenticationClient { - private final LeetcodeAuthStealerServiceBlockingStub lassService; - private final DirectLeetcodeAuthenticationClientProperties properties; - - @Override - public Optional getLeetcodeCookie() { - try { - return Optional.of(lassService.authenticate(AuthenticateRequest.newBuilder() - .setLogin(properties.username()) - .setPassword(properties.password()) - .build())) - .map(r -> new AuthenticationCredentials(r.getLeetcodeSession(), r.getCsrfToken())); - } catch (Exception e) { - log.error("failed to get leetcode cookie from LASS service", e); - return Optional.empty(); - } - } -} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientProperties.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientProperties.java deleted file mode 100644 index 8dcf3a776..000000000 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientProperties.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties("leetcode.auth.direct") -@ConditionalOnProperty(name = "leetcode.auth.strategy", havingValue = "direct") -public record DirectLeetcodeAuthenticationClientProperties(String username, String password) {} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClient.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClient.java deleted file mode 100644 index 94824be55..000000000 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClient.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import java.util.Optional; -import lombok.AllArgsConstructor; -import org.patinanetwork.codebloom.playwright.PlaywrightClient; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.stereotype.Component; - -@Component -@EnableConfigurationProperties(GitHubLeetcodeAuthenticationClientProperties.class) -@ConditionalOnProperty(name = "leetcode.auth.strategy", havingValue = "github") -@AllArgsConstructor -public class GitHubLeetcodeAuthenticationClient implements LeetcodeAuthenticationClient { - private final PlaywrightClient playwrightClient; - private final GitHubLeetcodeAuthenticationClientProperties properties; - - @Override - public Optional getLeetcodeCookie() { - return playwrightClient - .getLeetcodeCookie(properties.username(), properties.password()) - .map(a -> - new AuthenticationCredentials(a.getToken(), a.getCsrf().orElse(null))); - } -} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientProperties.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientProperties.java deleted file mode 100644 index 424ca8ea5..000000000 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientProperties.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties("leetcode.auth.github") -@ConditionalOnProperty(name = "leetcode.auth.strategy", havingValue = "github") -public record GitHubLeetcodeAuthenticationClientProperties(String username, String password) {} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationClient.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationClient.java deleted file mode 100644 index 890bf939e..000000000 --- a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationClient.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import java.util.Optional; - -public interface LeetcodeAuthenticationClient { - Optional getLeetcodeCookie(); -} diff --git a/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationService.java b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationService.java new file mode 100644 index 000000000..626ab4fa3 --- /dev/null +++ b/src/main/java/org/patinanetwork/codebloom/common/leetcode/auth/LeetcodeAuthenticationService.java @@ -0,0 +1,8 @@ +package org.patinanetwork.codebloom.common.leetcode.auth; + +public interface LeetcodeAuthenticationService { + + AuthenticationCredentials getAuthenticationCredentials(); + + void refresh(); +} diff --git a/src/main/java/org/patinanetwork/codebloom/config/GrpcClientConfiguration.java b/src/main/java/org/patinanetwork/codebloom/config/GrpcClientConfiguration.java index c87ecf9bd..5be1c7253 100644 --- a/src/main/java/org/patinanetwork/codebloom/config/GrpcClientConfiguration.java +++ b/src/main/java/org/patinanetwork/codebloom/config/GrpcClientConfiguration.java @@ -7,15 +7,15 @@ import io.micrometer.observation.ObservationRegistry; import java.time.Duration; import lombok.AllArgsConstructor; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceGrpc; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceGrpc.LeetcodeAuthStealerServiceBlockingStub; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuthServiceGrpc; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuthServiceGrpc.LeetcodeAuthServiceBlockingStub; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @AllArgsConstructor -@EnableConfigurationProperties(LeetcodeAuthStealerGrpcClientConfiguration.class) +@EnableConfigurationProperties(LeetcodeAuthServiceGrpcClientConfiguration.class) public class GrpcClientConfiguration { private final ObservationRegistry observationRegistry; @@ -41,20 +41,20 @@ private ClientInterceptor[] interceptors( } @Bean - ManagedChannel lassServiceChannel( - LeetcodeAuthStealerGrpcClientConfiguration authStealerProps, + ManagedChannel lasServiceChannel( + LeetcodeAuthServiceGrpcClientConfiguration authProps, GrpcRequestIdInterceptor requestIdInterceptor, ObservationGrpcClientInterceptor observationInterceptor) { - var builder = ManagedChannelBuilder.forTarget(authStealerProps.host()) - .intercept(interceptors(authStealerProps.timeout(), requestIdInterceptor, observationInterceptor)); + var builder = ManagedChannelBuilder.forTarget(authProps.host()) + .intercept(interceptors(authProps.timeout(), requestIdInterceptor, observationInterceptor)); - return (authStealerProps.tls() ? builder.useTransportSecurity() : builder.usePlaintext()).build(); + return (authProps.tls() ? builder.useTransportSecurity() : builder.usePlaintext()).build(); } @Bean - LeetcodeAuthStealerServiceBlockingStub lassServiceBlockingStub(ManagedChannel lassServiceChannel) { + LeetcodeAuthServiceBlockingStub lasServiceBlockingStub(ManagedChannel lasServiceChannel) { - return LeetcodeAuthStealerServiceGrpc.newBlockingStub(lassServiceChannel); + return LeetcodeAuthServiceGrpc.newBlockingStub(lasServiceChannel); } } diff --git a/src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthStealerGrpcClientConfiguration.java b/src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthServiceGrpcClientConfiguration.java similarity index 59% rename from src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthStealerGrpcClientConfiguration.java rename to src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthServiceGrpcClientConfiguration.java index e1fe7479e..6dbbbfc1a 100644 --- a/src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthStealerGrpcClientConfiguration.java +++ b/src/main/java/org/patinanetwork/codebloom/config/LeetcodeAuthServiceGrpcClientConfiguration.java @@ -3,5 +3,5 @@ import java.time.Duration; import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties("grpc.leetcode-auth-stealer-service") -public record LeetcodeAuthStealerGrpcClientConfiguration(String host, boolean tls, Duration timeout) {} +@ConfigurationProperties("grpc.leetcode-auth-service") +public record LeetcodeAuthServiceGrpcClientConfiguration(String host, boolean tls, Duration timeout) {} diff --git a/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java b/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java index 188789b4e..efa680af4 100644 --- a/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java +++ b/src/main/java/org/patinanetwork/codebloom/playwright/PlaywrightClient.java @@ -1,21 +1,12 @@ package org.patinanetwork.codebloom.playwright; -import com.microsoft.playwright.ElementHandle; import com.microsoft.playwright.Page; -import com.microsoft.playwright.options.LoadState; import com.microsoft.playwright.options.ScreenshotType; -import java.util.List; -import java.util.Optional; import java.util.function.Function; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.patinanetwork.codebloom.common.db.models.auth.Auth; import org.patinanetwork.codebloom.common.db.models.usertag.Tag; -import org.patinanetwork.codebloom.common.email.EmailClient; -import org.patinanetwork.codebloom.common.email.Message; import org.patinanetwork.codebloom.common.email.client.github.GithubOAuthEmailClient; import org.patinanetwork.codebloom.common.url.ServerUrlUtils; -import org.patinanetwork.codebloom.scheduled.auth.CodeExtractor; import org.springframework.stereotype.Component; @Component @@ -26,7 +17,6 @@ public class PlaywrightClient { "Mozilla/5.0 (Linux; U; Android 4.4.1; SAMSUNG SM-J210G Build/KTU84P) AppleWebKit/536.31 (KHTML, like Gecko) Chrome/48.0.2090.359 Mobile Safari/601.9"; private final ServerUrlUtils serverUrlUtils; - private final EmailClient emailClient; private final PlaywrightProvider playwrightProvider; public PlaywrightClient( @@ -34,7 +24,6 @@ public PlaywrightClient( final GithubOAuthEmailClient githubOAuthEmailClient, final PlaywrightProvider playwrightProvider) { this.serverUrlUtils = serverUrlUtils; - this.emailClient = githubOAuthEmailClient; this.playwrightProvider = playwrightProvider; } @@ -53,94 +42,4 @@ public byte[] getCodebloomLeaderboardScreenshot(final int page, final Tag tag) { return screenshot; }); } - - public Optional getLeetcodeCookie(String githubUsername, String githubPassword) { - return withPage((p) -> { - p.navigate("https://leetcode.com/accounts/github/login/?next=%2F"); - - log.info("Navigated to leetcode.com login"); - - p.waitForLoadState(LoadState.NETWORKIDLE); - - p.fill("#login_field", githubUsername); - p.fill("#password", githubPassword); - - log.info("Filled in credentials, clicking login..."); - - p.click("input[name=\"commit\"]"); - - if (p.isVisible("#device-verification-prompt") || p.isVisible("#session-otp-input-description")) { - log.info("2FA Required"); - List messages; - - p.waitForTimeout(10000); - - try { - messages = emailClient.getPastMessages(); - } catch (Exception e) { - log.info("Failed to retrieve past messages"); - throw new RuntimeException("Failed to retrieve past messages", e); - } - - Message target = null; - for (Message m : messages) { - // Don't break so we can get the newest available code. - if (m.getSubject().equals("[GitHub] Please verify your device")) { - log.info("Found verification email"); - target = m; - } - } - - if (target == null) { - throw new RuntimeException( - "Something went wrong when parsing the inbox. Manual intervention required"); - } - - String code = CodeExtractor.extractCode(target.getMessage()); - - log.info("Found code in email, will fill now..."); - - if (code == null) { - throw new RuntimeException("Code was not found in the email. Manual intervention required."); - } - - p.fill("input[name='otp']", code); - - log.info("Page filled!"); - } - - if (p.isVisible("button[name=\"authorize\"]")) { - List buttons = p.querySelectorAll("button[name=\"authorize\"]"); - if (buttons.size() > 1) { - // Click the second button (which is the actual authorize button) - buttons.get(1).click(); - } - log.info("Authorization button clicked"); - } - - p.waitForURL("https://leetcode.com/"); - - log.info("Back to leetcode.com!"); - - if (p.url().equals("https://leetcode.com/")) { - var cookieMap = p.context().cookies().stream() - .filter(cookie -> cookie.name.equals("LEETCODE_SESSION") || cookie.name.equals("csrftoken")) - .collect(Collectors.toMap(cookie -> cookie.name, cookie -> cookie.value)); - - String sessionToken = cookieMap.get("LEETCODE_SESSION"); - String csrf = cookieMap.get("csrftoken"); - if (sessionToken != null) { - log.info("Cookie found!"); - return Optional.of(Auth.builder() - .token(sessionToken) - .csrf(Optional.ofNullable(csrf)) - .build()); - } - } else { - log.info("Should be authenticated but not authenticated."); - } - - return Optional.empty(); - }); - } } diff --git a/src/main/java/org/patinanetwork/codebloom/scheduled/auth/CodeExtractor.java b/src/main/java/org/patinanetwork/codebloom/scheduled/auth/CodeExtractor.java deleted file mode 100644 index b1d4b9fb1..000000000 --- a/src/main/java/org/patinanetwork/codebloom/scheduled/auth/CodeExtractor.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.patinanetwork.codebloom.scheduled.auth; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CodeExtractor { - - public static String extractCode(final String content) { - Pattern pattern = Pattern.compile("Verification code:\\s*(\\d{6})"); - Matcher matcher = pattern.matcher(content); - - if (matcher.find()) { - return matcher.group(1); - } - - return null; - } -} diff --git a/src/main/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealer.java b/src/main/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealer.java deleted file mode 100644 index 2baf14c47..000000000 --- a/src/main/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealer.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.patinanetwork.codebloom.scheduled.auth; - -import com.google.common.annotations.VisibleForTesting; -import io.micrometer.core.annotation.Timed; -import java.time.temporal.ChronoUnit; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import lombok.extern.slf4j.Slf4j; -import org.patinanetwork.codebloom.common.db.models.auth.Auth; -import org.patinanetwork.codebloom.common.db.repos.auth.AuthRepository; -import org.patinanetwork.codebloom.common.env.Env; -import org.patinanetwork.codebloom.common.leetcode.auth.AuthenticationCredentials; -import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationClient; -import org.patinanetwork.codebloom.common.redis.RedisClient; -import org.patinanetwork.codebloom.common.reporter.Reporter; -import org.patinanetwork.codebloom.common.reporter.report.Report; -import org.patinanetwork.codebloom.common.reporter.report.location.Location; -import org.patinanetwork.codebloom.common.time.StandardizedOffsetDateTime; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -@Slf4j -@Timed(value = "leetcode.client.execution") -public class LeetcodeAuthStealer { - - @VisibleForTesting - // CHECKSTYLE:OFF - final ReentrantReadWriteLock LOCK = new ReentrantReadWriteLock(); - // CHECKSTYLE:ON - - private volatile String cookie; - private volatile String csrf; - - /** So we don't report that a csrf token is missing more than once per machine lifecycle. */ - private boolean reported = false; - - private final RedisClient redisClient; - private final AuthRepository authRepository; - private final Reporter reporter; - private final Env env; - private final LeetcodeAuthenticationClient leetcodeAuthenticationClient; - - public LeetcodeAuthStealer( - final RedisClient redisClient, - final AuthRepository authRepository, - final Reporter reporter, - final Env env, - final LeetcodeAuthenticationClient leetcodeAuthenticationClient) { - this.redisClient = redisClient; - this.authRepository = authRepository; - this.reporter = reporter; - this.env = env; - this.leetcodeAuthenticationClient = leetcodeAuthenticationClient; - } - - /** - * DO NOT RETURN THE TOKEN IN ANY API ENDPOINT.
This function utilizes Playwright in order to get an - * authentication key from Leetcode. That code is stored in the database and can then be used to run authenticated - * queries such as being used to retrieve code from our user submissions. - */ - @Scheduled(initialDelay = 0, fixedDelay = 15, timeUnit = TimeUnit.MINUTES) - public void stealAuthCookie() { - boolean acquired = LOCK.writeLock().tryLock(); - if (!acquired) { - log.info("Lock failed to be acquired, bouncing..."); - return; - } - - try { - var mostRecentAuth = authRepository.getMostRecentAuth().filter(auth -> auth.getCreatedAt() - .isAfter(StandardizedOffsetDateTime.now().minus(4, ChronoUnit.HOURS))); - - // The auth token should be refreshed every 4 hours. - if (mostRecentAuth.isPresent()) { - log.info("Auth token already exists, using token from database."); - cookie = mostRecentAuth.get().getToken(); - csrf = mostRecentAuth.get().getCsrf().orElse(null); - return; - } - - log.info("falling back to checking redis client..."); - Optional authToken = redisClient.getAuth(); - - log.info("auth token in redis = {}", authToken.isPresent()); - - if (authToken.isPresent()) { - log.info("auth token found in redis client"); - cookie = authToken.get(); - csrf = null; // don't care in ci. - return; - } - - log.info("auth token not found in redis client"); - log.info("Auth token is missing/expired. Attempting to receive token..."); - - stealCookieImpl(); - } finally { - LOCK.writeLock().unlock(); - } - } - - /** - * There are some cases where leetcode.com may not respect the token anymore. If that is the case, it is best to try - * to steal a new cookie and replace the current one. - * - *

You may await the `CompletableFuture` and receive the brand new token, or call-and-forget. - */ - @Async - public CompletableFuture> reloadCookie() { - boolean acquired = LOCK.writeLock().tryLock(); - if (!acquired) { - log.info("Lock failed to be acquired, bouncing..."); - return CompletableFuture.completedFuture(Optional.empty()); - } - - try { - return CompletableFuture.completedFuture(Optional.ofNullable(stealCookieImpl())); - } finally { - LOCK.writeLock().unlock(); - } - } - - public String getCookie() { - LOCK.readLock().lock(); - try { - return cookie; - } finally { - LOCK.readLock().unlock(); - } - } - - /** - * It's fine if this is null for some requests; it isn't a requirement to fetch data from the GraphQL layer of - * leetcode.com - */ - public String getCsrf() { - if (csrf == null && !reported) { - reported = true; - reporter.log( - "getCsrf", - Report.builder() - .environments(env.getActiveProfiles()) - .location(Location.BACKEND) - .data( - "CSRF token is missing inside of LeetcodeAuthStealer. This may be something to look into.") - .build()); - } - - return csrf; - } - - @VisibleForTesting - String stealCookieImpl() { - Optional auth = leetcodeAuthenticationClient.getLeetcodeCookie(); - if (auth.isPresent()) { - var a = auth.get(); - var csrf = a.csrf(); - var token = a.token(); - - this.csrf = csrf; - this.cookie = token; - redisClient.setAuth(token, 4, ChronoUnit.HOURS); - log.info("auth token stored in redis"); - this.authRepository.createAuth(Auth.builder() - .csrf(Optional.of(csrf)) - .token(token) - .createdAt(StandardizedOffsetDateTime.now()) - .build()); - return cookie; - } - - return null; - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9d0a8dc1c..5dd1aa054 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -66,10 +66,11 @@ springdoc: version: OPENAPI_3_0 grpc: - leetcode-auth-stealer-service: - host: ${GRPC_LASS_HOST:localhost:50051} - tls: ${GRPC_LASS_TLS:false} - timeout: ${GRPC_LASS_TIMEOUT:2m} # extremely long running, give it time to breathe in local + leetcode-auth-service: + host: ${GRPC_LAS_HOST:localhost:50052} + tls: ${GRPC_LAS_TLS:false} + # both RPCs answer from Redis in milliseconds; refreshToken returns before the login runs + timeout: ${GRPC_LAS_TIMEOUT:1s} leetcode: auth: diff --git a/src/test/java/org/patinanetwork/codebloom/api/admin/AdminControllerTest.java b/src/test/java/org/patinanetwork/codebloom/api/admin/AdminControllerTest.java index 3be65b20c..ccba4cb7b 100644 --- a/src/test/java/org/patinanetwork/codebloom/api/admin/AdminControllerTest.java +++ b/src/test/java/org/patinanetwork/codebloom/api/admin/AdminControllerTest.java @@ -30,8 +30,8 @@ import org.patinanetwork.codebloom.common.dto.ApiResponder; import org.patinanetwork.codebloom.common.dto.Empty; import org.patinanetwork.codebloom.common.dto.question.QuestionWithUserDto; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.patinanetwork.codebloom.common.time.StandardizedOffsetDateTime; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; import org.patinanetwork.codebloom.utilities.exception.ValidationException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -46,7 +46,8 @@ public class AdminControllerTest { private final DiscordClubManager discordClubManager = mock(DiscordClubManager.class); private final LeaderboardManager leaderboardManager = mock(LeaderboardManager.class); private final DiscordClubRepository discordClubRepository = mock(DiscordClubRepository.class); - private final LeetcodeAuthStealer leetcodeAuthStealer = mock(LeetcodeAuthStealer.class); + private final LeetcodeAuthenticationService leetcodeAuthenticationService = + mock(LeetcodeAuthenticationService.class); private final IncompleteQuestionRequeuer incompleteQuestionRequeuer = mock(IncompleteQuestionRequeuer.class); private final AdminController adminController; @@ -60,7 +61,7 @@ public AdminControllerTest() { discordClubManager, leaderboardManager, discordClubRepository, - leetcodeAuthStealer, + leetcodeAuthenticationService, incompleteQuestionRequeuer)); } @@ -73,7 +74,7 @@ void setUp() { questionRepository, discordClubManager, leaderboardManager, - leetcodeAuthStealer, + leetcodeAuthenticationService, incompleteQuestionRequeuer); } @@ -468,7 +469,7 @@ void testRefreshLeetcodeTokenTriggersReload() { assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); assertTrue(response.getBody().isSuccess()); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } @Test diff --git a/src/test/java/org/patinanetwork/codebloom/common/db/repos/BaseRepositoryTest.java b/src/test/java/org/patinanetwork/codebloom/common/db/repos/BaseRepositoryTest.java index 08325667a..1bd33fe24 100644 --- a/src/test/java/org/patinanetwork/codebloom/common/db/repos/BaseRepositoryTest.java +++ b/src/test/java/org/patinanetwork/codebloom/common/db/repos/BaseRepositoryTest.java @@ -2,9 +2,9 @@ import org.patinanetwork.codebloom.common.email.client.codebloom.OfficialCodebloomEmailClient; import org.patinanetwork.codebloom.common.email.client.github.GithubOAuthEmailClient; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.patinanetwork.codebloom.jda.JDAClientManager; import org.patinanetwork.codebloom.jda.command.JDASlashCommandInitializer; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; import org.patinanetwork.codebloom.scheduled.submission.SubmissionScheduler; import org.springframework.test.context.bean.override.mockito.MockitoBean; @@ -31,5 +31,5 @@ public class BaseRepositoryTest { private SubmissionScheduler submissionScheduler; @MockitoBean - private LeetcodeAuthStealer leetcodeAuthStealer; + private LeetcodeAuthenticationService leetcodeAuthenticationService; } diff --git a/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientCircuitBreakerTest.java b/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientCircuitBreakerTest.java index 094803b0c..9b83cdd79 100644 --- a/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientCircuitBreakerTest.java +++ b/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientCircuitBreakerTest.java @@ -10,9 +10,11 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; +import org.patinanetwork.codebloom.common.leetcode.auth.AuthenticationCredentials; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -39,7 +41,7 @@ class LeetcodeClientCircuitBreakerTest { private LeetcodeClientImpl leetcodeClient; @MockitoBean - private LeetcodeAuthStealer leetcodeAuthStealer; + private LeetcodeAuthenticationService leetcodeAuthenticationService; @MockitoBean private HttpClient httpClient; @@ -59,8 +61,8 @@ void setUp() throws Exception { Object target = AopTestUtils.getTargetObject(leetcodeClient); ReflectionTestUtils.setField(target, "client", httpClient); - when(leetcodeAuthStealer.getCookie()).thenReturn("test-cookie"); - when(leetcodeAuthStealer.getCsrf()).thenReturn(null); + when(leetcodeAuthenticationService.getAuthenticationCredentials()) + .thenReturn(new AuthenticationCredentials(Optional.of("test-cookie"), Optional.empty())); when(httpClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))) .thenThrow(new RuntimeException("boom")); diff --git a/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientTest.java b/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientTest.java index 6f491f35e..b0e44195c 100644 --- a/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientTest.java +++ b/src/test/java/org/patinanetwork/codebloom/common/leetcode/LeetcodeClientTest.java @@ -12,31 +12,34 @@ import java.net.http.HttpResponse; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.patinanetwork.codebloom.common.db.models.question.QuestionDifficulty; +import org.patinanetwork.codebloom.common.leetcode.auth.AuthenticationCredentials; +import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationService; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeDetailedQuestion; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeQuestion; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeSubmission; import org.patinanetwork.codebloom.common.leetcode.models.LeetcodeTopicTag; import org.patinanetwork.codebloom.common.leetcode.models.POTD; import org.patinanetwork.codebloom.common.leetcode.models.UserProfile; -import org.patinanetwork.codebloom.scheduled.auth.LeetcodeAuthStealer; public class LeetcodeClientTest { private final MeterRegistry meterRegistry = new SimpleMeterRegistry(); - private final LeetcodeAuthStealer leetcodeAuthStealer = mock(LeetcodeAuthStealer.class); + private final LeetcodeAuthenticationService leetcodeAuthenticationService = + mock(LeetcodeAuthenticationService.class); private final HttpClient httpClient = mock(HttpClient.class); private final HttpResponse httpResponse = mock(HttpResponse.class); private final LeetcodeClientImpl leetcodeClient; public LeetcodeClientTest() throws Exception { - leetcodeClient = new LeetcodeClientImpl(meterRegistry, leetcodeAuthStealer); + leetcodeClient = new LeetcodeClientImpl(meterRegistry, leetcodeAuthenticationService); setupMockHttpClient(leetcodeClient, httpClient); } @@ -46,8 +49,8 @@ void setupMockHttpClient(LeetcodeClientImpl leetcodeClient, HttpClient httpClien @BeforeEach void setup() { - when(leetcodeAuthStealer.getCookie()).thenReturn("test-session-cookie"); - when(leetcodeAuthStealer.getCsrf()).thenReturn(null); + when(leetcodeAuthenticationService.getAuthenticationCredentials()) + .thenReturn(new AuthenticationCredentials(Optional.of("test-session-cookie"), Optional.empty())); } @Test @@ -109,7 +112,7 @@ void testFindQuestionBySlugThrottledAndTriggersReloadCookie(int statusCode) thro fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -171,7 +174,7 @@ void testFindSubmissionsByUsernameThrottledAndTriggersReloadCookie(int statusCod fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -295,7 +298,7 @@ void testFindSubmissionDetailBySubmissionIdThrottledAndTriggersReloadCookie(int fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -348,7 +351,7 @@ void testGetPotdThrottledAndTriggersReloadCookie(int statusCode) throws Exceptio fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -405,7 +408,7 @@ void testGetUserProfileThrottledAndTriggersReloadCookie(int statusCode) throws E fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -465,7 +468,7 @@ void testGetAllTopicTagsThrottledAndTriggersReloadCookie(int statusCode) throws fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } @@ -572,7 +575,7 @@ void testGetAllProblemsThrottledAndTriggersReloadCookie(int statusCode) throws E fail("Exception expected"); } catch (RuntimeException e) { assertTrue(e.getCause().getMessage().contains(String.valueOf(statusCode))); - verify(leetcodeAuthStealer, times(1)).reloadCookie(); + verify(leetcodeAuthenticationService, times(1)).refresh(); } } diff --git a/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationServiceTest.java b/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationServiceTest.java new file mode 100644 index 000000000..7e89fd155 --- /dev/null +++ b/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DefaultLeetcodeAuthenticationServiceTest.java @@ -0,0 +1,53 @@ +package org.patinanetwork.codebloom.common.leetcode.auth; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.grpc.Status; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenRequest; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.GetTokenResponse; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.LeetcodeAuthServiceGrpc.LeetcodeAuthServiceBlockingStub; +import org.patinanetwork.codebloom.grpc.leetcodeauth.v1.RefreshTokenRequest; + +class DefaultLeetcodeAuthenticationServiceTest { + + private final LeetcodeAuthServiceBlockingStub stub = mock(LeetcodeAuthServiceBlockingStub.class); + private final DefaultLeetcodeAuthenticationService service = new DefaultLeetcodeAuthenticationService(stub); + + @Test + void returnsStoredCredentials() { + when(stub.getToken(any(GetTokenRequest.class))) + .thenReturn(GetTokenResponse.newBuilder() + .setToken("session") + .setCsrf("csrf") + .build()); + + AuthenticationCredentials credentials = service.getAuthenticationCredentials(); + + assertEquals(Optional.of("session"), credentials.token()); + assertEquals(Optional.of("csrf"), credentials.csrf()); + } + + @Test + void returnsEmptyCredentialsWhenAuthServiceFails() { + when(stub.getToken(any(GetTokenRequest.class))).thenThrow(Status.NOT_FOUND.asRuntimeException()); + + AuthenticationCredentials credentials = service.getAuthenticationCredentials(); + + assertTrue(credentials.token().isEmpty()); + assertTrue(credentials.csrf().isEmpty()); + } + + @Test + void refreshRequestsTokenRefresh() { + service.refresh(); + + verify(stub).refreshToken(any(RefreshTokenRequest.class)); + } +} diff --git a/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientTest.java b/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientTest.java deleted file mode 100644 index ca5763532..000000000 --- a/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/DirectLeetcodeAuthenticationClientTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.grpc.Status; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateRequest; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.AuthenticateResponse; -import org.patinanetwork.codebloom.grpc.leetcode.auth.v1.LeetcodeAuthStealerServiceGrpc.LeetcodeAuthStealerServiceBlockingStub; - -public class DirectLeetcodeAuthenticationClientTest { - - private final LeetcodeAuthStealerServiceBlockingStub lassService = - mock(LeetcodeAuthStealerServiceBlockingStub.class); - private final DirectLeetcodeAuthenticationClient client = new DirectLeetcodeAuthenticationClient( - lassService, new DirectLeetcodeAuthenticationClientProperties("user@example.com", "hunter2")); - - @Test - void mapsSessionAndCsrfFromLassResponse() { - when(lassService.authenticate(any(AuthenticateRequest.class))) - .thenReturn(AuthenticateResponse.newBuilder() - .setLeetcodeSession("session-token") - .setCsrfToken("csrf-token") - .build()); - - Optional result = client.getLeetcodeCookie(); - - assertEquals(Optional.of(new AuthenticationCredentials("session-token", "csrf-token")), result); - verify(lassService) - .authenticate(AuthenticateRequest.newBuilder() - .setLogin("user@example.com") - .setPassword("hunter2") - .build()); - } - - @Test - void returnsEmptyWhenLassCallFails() { - when(lassService.authenticate(any(AuthenticateRequest.class))) - .thenThrow(Status.UNAVAILABLE.asRuntimeException()); - - assertTrue(client.getLeetcodeCookie().isEmpty()); - } -} diff --git a/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientTest.java b/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientTest.java deleted file mode 100644 index 30bf8e2c7..000000000 --- a/src/test/java/org/patinanetwork/codebloom/common/leetcode/auth/GitHubLeetcodeAuthenticationClientTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.patinanetwork.codebloom.common.leetcode.auth; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.patinanetwork.codebloom.common.db.models.auth.Auth; -import org.patinanetwork.codebloom.playwright.PlaywrightClient; - -public class GitHubLeetcodeAuthenticationClientTest { - - private final PlaywrightClient playwrightClient = mock(PlaywrightClient.class); - private final GitHubLeetcodeAuthenticationClient client = new GitHubLeetcodeAuthenticationClient( - playwrightClient, new GitHubLeetcodeAuthenticationClientProperties("gh-user", "gh-pass")); - - @Test - void mapsTokenAndCsrfFromPlaywrightAuth() { - when(playwrightClient.getLeetcodeCookie("gh-user", "gh-pass")) - .thenReturn(Optional.of(Auth.builder() - .token("session-token") - .csrf(Optional.of("csrf-token")) - .build())); - - assertEquals( - Optional.of(new AuthenticationCredentials("session-token", "csrf-token")), client.getLeetcodeCookie()); - } - - @Test - void returnsEmptyWhenPlaywrightFindsNoCookie() { - when(playwrightClient.getLeetcodeCookie("gh-user", "gh-pass")).thenReturn(Optional.empty()); - - assertTrue(client.getLeetcodeCookie().isEmpty()); - } -} diff --git a/src/test/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealerTest.java b/src/test/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealerTest.java deleted file mode 100644 index 6eb4c680c..000000000 --- a/src/test/java/org/patinanetwork/codebloom/scheduled/auth/LeetcodeAuthStealerTest.java +++ /dev/null @@ -1,704 +0,0 @@ -package org.patinanetwork.codebloom.scheduled.auth; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.Mockito.*; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; -import java.time.temporal.ChronoUnit; -import java.util.Optional; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; -import org.patinanetwork.codebloom.common.db.models.auth.Auth; -import org.patinanetwork.codebloom.common.db.repos.auth.AuthRepository; -import org.patinanetwork.codebloom.common.env.Env; -import org.patinanetwork.codebloom.common.lag.FakeLag; -import org.patinanetwork.codebloom.common.leetcode.auth.AuthenticationCredentials; -import org.patinanetwork.codebloom.common.leetcode.auth.LeetcodeAuthenticationClient; -import org.patinanetwork.codebloom.common.redis.RedisClient; -import org.patinanetwork.codebloom.common.reporter.Reporter; -import org.patinanetwork.codebloom.common.time.StandardizedOffsetDateTime; -import org.slf4j.LoggerFactory; - -public class LeetcodeAuthStealerTest { - private LeetcodeAuthStealer leetcodeAuthStealer; - - private RedisClient redisClient; - private AuthRepository authRepository; - private Reporter reporter; - private Env env; - private LeetcodeAuthenticationClient leetcodeAuthenticationClient; - - private ListAppender logWatcher; - - public LeetcodeAuthStealerTest() { - redisClient = mock(RedisClient.class); - authRepository = mock(AuthRepository.class); - reporter = mock(Reporter.class); - env = mock(Env.class); - leetcodeAuthenticationClient = mock(LeetcodeAuthenticationClient.class); - } - - @BeforeEach - void setup() { - leetcodeAuthStealer = - spy(new LeetcodeAuthStealer(redisClient, authRepository, reporter, env, leetcodeAuthenticationClient)); - - logWatcher = new ListAppender<>(); - logWatcher.start(); - ((Logger) LoggerFactory.getLogger(leetcodeAuthStealer.getClass())).addAppender(logWatcher); - - when(env.isCi()).thenReturn(false); - playwrightClientResolvesSlowly(Auth.builder().build()); - } - - @AfterEach - void teardown() { - ((Logger) LoggerFactory.getLogger(leetcodeAuthStealer.getClass())).detachAndStopAllAppenders(); - } - - private void playwrightClientResolvesSlowly(Auth authToReturn) { - when(leetcodeAuthenticationClient.getLeetcodeCookie()).thenAnswer(invocation -> { - FakeLag.sleep(1000); - return Optional.ofNullable(authToReturn); - }); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies multiple threads can acquire read locks concurrently across the same thread pool - Auth Repository") - void testReadLockConcurrentAccessSameThreadPoolAuthRepo() throws InterruptedException { - Auth mockAuth = Auth.builder() - .token("test-token") - .csrf(Optional.of("test-csrf")) - .createdAt(StandardizedOffsetDateTime.now()) - .build(); - when(authRepository.getMostRecentAuth()).thenReturn(Optional.of(mockAuth)); - - leetcodeAuthStealer.stealAuthCookie(); - - ExecutorService pool = Executors.newFixedThreadPool(5); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(5); - AtomicInteger concurrentReads = new AtomicInteger(0); - AtomicInteger maxConcurrentReads = new AtomicInteger(0); - - for (int i = 0; i < 5; i++) { - pool.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - verify(leetcodeAuthStealer, never()).stealCookieImpl(); - - startLatch.countDown(); - assertTrue(doneLatch.await(5, TimeUnit.SECONDS)); - pool.shutdown(); - - assertTrue(maxConcurrentReads.get() > 1, "Multiple read locks should be acquired concurrently"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies multiple threads can acquire read locks concurrently across the same thread pool - New cookie fetched") - void testReadLockConcurrentAccessSameThreadPoolNewCookieFetched() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - doReturn("cookie").when(leetcodeAuthStealer).stealCookieImpl(); - doReturn("cookie").when(leetcodeAuthStealer).getCookie(); - - leetcodeAuthStealer.stealAuthCookie(); - - ExecutorService executor = Executors.newFixedThreadPool(5); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(5); - AtomicInteger concurrentReads = new AtomicInteger(0); - AtomicInteger maxConcurrentReads = new AtomicInteger(0); - - for (int i = 0; i < 5; i++) { - executor.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(5, TimeUnit.SECONDS)); - executor.shutdown(); - - assertTrue(maxConcurrentReads.get() > 1, "Multiple read locks should be acquired concurrently"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies multiple threads can acquire read locks concurrently across different thread pools - Auth Repository") - void testReadLockConcurrentAccessDifferentThreadPoolsAuthRepository() throws InterruptedException { - Auth mockAuth = Auth.builder() - .token("test-token") - .csrf(Optional.of("test-csrf")) - .createdAt(StandardizedOffsetDateTime.now()) - .build(); - when(authRepository.getMostRecentAuth()).thenReturn(Optional.of(mockAuth)); - - leetcodeAuthStealer.stealAuthCookie(); - - ExecutorService pool1 = Executors.newFixedThreadPool(3); - ExecutorService pool2 = Executors.newFixedThreadPool(3); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(6); - AtomicInteger concurrentReads = new AtomicInteger(0); - AtomicInteger maxConcurrentReads = new AtomicInteger(0); - - for (int i = 0; i < 3; i++) { - pool1.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - for (int i = 0; i < 3; i++) { - pool2.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(5, TimeUnit.SECONDS)); - pool1.shutdown(); - - assertTrue( - maxConcurrentReads.get() > 1, - "Multiple read locks should be acquired concurrently across different thread pools"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies multiple threads can acquire read locks concurrently across different thread pools - New cookie fetched") - void testReadLockConcurrentAccessDifferentThreadPoolsFetchedNewCookie() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - doReturn("string").when(leetcodeAuthStealer).stealCookieImpl(); - doReturn("string").when(leetcodeAuthStealer).getCookie(); - - leetcodeAuthStealer.stealAuthCookie(); - - ExecutorService pool1 = Executors.newFixedThreadPool(3); - ExecutorService pool2 = Executors.newFixedThreadPool(3); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(6); - AtomicInteger concurrentReads = new AtomicInteger(0); - AtomicInteger maxConcurrentReads = new AtomicInteger(0); - - for (int i = 0; i < 3; i++) { - pool1.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - for (int i = 0; i < 3; i++) { - pool2.submit(() -> { - try { - startLatch.await(); - int current = concurrentReads.incrementAndGet(); - maxConcurrentReads.updateAndGet(max -> Math.max(max, current)); - - String cookie = leetcodeAuthStealer.getCookie(); - assertNotNull(cookie); - assertEquals("test-token", cookie); - - Thread.sleep(100); - concurrentReads.decrementAndGet(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(5, TimeUnit.SECONDS)); - pool1.shutdown(); - - assertTrue( - maxConcurrentReads.get() > 1, - "Multiple read locks should be acquired concurrently across different thread pools"); - } - - @Test - @Timeout(15) - @DisplayName("Verifies that only one thread can try to steal cookie at a time across the same thread pool") - void testWriteLockExclusiveAccessSameThreadPool() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - - ExecutorService pool = Executors.newFixedThreadPool(3); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(3); - AtomicBoolean isOneWriteBlockingOtherWrites = new AtomicBoolean(false); - - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.stealAuthCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.writeLock().tryLock()) { - isOneWriteBlockingOtherWrites.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(10, TimeUnit.SECONDS)); - pool.shutdown(); - - assertTrue( - isOneWriteBlockingOtherWrites.get(), - "Write locks should be exclusive within the same thread pool - only one at a time"); - } - - @Test - @Timeout(15) - @DisplayName("Verifies that only one thread can try to steal cookie at a time across different thread pools") - void testWriteLockExclusiveAccessDifferentThreadPools() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - - ExecutorService pool1 = Executors.newFixedThreadPool(2); - ExecutorService pool2 = Executors.newFixedThreadPool(2); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(3); - AtomicBoolean isOneWriteBlockingOtherWrites = new AtomicBoolean(false); - - pool1.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.stealAuthCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - pool2.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.writeLock().tryLock()) { - isOneWriteBlockingOtherWrites.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(10, TimeUnit.SECONDS)); - pool1.shutdown(); - pool2.shutdown(); - - assertTrue( - isOneWriteBlockingOtherWrites.get(), - "Write locks should be exclusive across different thread pools - only one at a time"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies that no read operations can happen when stealing authentication cookie in the same thread pool") - void testReadWriteLockInteractionSameThreadPool() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - - ExecutorService pool = Executors.newFixedThreadPool(4); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(4); - AtomicBoolean readBlockedByWrite = new AtomicBoolean(false); - - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.stealAuthCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.readLock().tryLock()) { - readBlockedByWrite.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(8, TimeUnit.SECONDS)); - pool.shutdown(); - - assertTrue(readBlockedByWrite.get(), "Read operations should be blocked when write lock is held"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies that no read operations can happen when stealing authentication cookie in different thread pools") - void testReadWriteLockInteractionDifferentThreadPools() throws InterruptedException { - when(authRepository.getMostRecentAuth()).thenReturn(Optional.empty()); - - ExecutorService writePool = Executors.newFixedThreadPool(1); - ExecutorService readPool = Executors.newFixedThreadPool(3); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(4); - AtomicBoolean readBlockedByWrite = new AtomicBoolean(false); - - writePool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.stealAuthCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - readPool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.readLock().tryLock()) { - readBlockedByWrite.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(8, TimeUnit.SECONDS)); - writePool.shutdown(); - readPool.shutdown(); - - assertTrue( - readBlockedByWrite.get(), - "Read operations from different thread pool should wait for write lock to be released"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies that no read operations can happen when reloading authentication cookie in the same thread pool") - void testReloadCookieReadWriteLockInteractionSameThreadPool() throws InterruptedException { - ExecutorService pool = Executors.newFixedThreadPool(4); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(4); - AtomicBoolean readBlockedByWrite = new AtomicBoolean(false); - - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.reloadCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - pool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.readLock().tryLock()) { - readBlockedByWrite.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(8, TimeUnit.SECONDS)); - pool.shutdown(); - - assertTrue(readBlockedByWrite.get(), "Read operations should be blocked when write lock is held"); - } - - @Test - @Timeout(10) - @DisplayName( - "Verifies that no read operations can happen when reloading authentication cookie in different thread pools") - void testReloadCookieReadWriteLockInteractionDifferentThreadPools() throws InterruptedException { - ExecutorService writePool = Executors.newFixedThreadPool(1); - ExecutorService readPool = Executors.newFixedThreadPool(3); - CountDownLatch startLatch = new CountDownLatch(1); - CountDownLatch doneLatch = new CountDownLatch(4); - AtomicBoolean readBlockedByWrite = new AtomicBoolean(false); - - writePool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(100); - leetcodeAuthStealer.reloadCookie(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - - for (int i = 0; i < 3; i++) { - readPool.submit(() -> { - try { - startLatch.await(); - Thread.sleep(200); - - if (!leetcodeAuthStealer.LOCK.readLock().tryLock()) { - readBlockedByWrite.set(true); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - doneLatch.countDown(); - } - }); - } - - startLatch.countDown(); - assertTrue(doneLatch.await(8, TimeUnit.SECONDS)); - writePool.shutdown(); - readPool.shutdown(); - - assertTrue( - readBlockedByWrite.get(), - "Read operations from different thread pool should wait for write lock to be released"); - } - - @Test - @Timeout(10) - @DisplayName("reloadCookie - If one thread is stealing cookie, other thread will bounce") - void testReloadCookieIfOneThreadIsStealingCookieOtherThreadWillBounce() throws InterruptedException { - ExecutorService writePool = Executors.newFixedThreadPool(2); - CountDownLatch latch = new CountDownLatch(1); - - writePool.execute(() -> { - leetcodeAuthStealer.reloadCookie(); - }); - - AtomicReference> ref = new AtomicReference<>(); - writePool.execute(() -> { - try { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - ref.set(leetcodeAuthStealer.reloadCookie().join()); - } finally { - latch.countDown(); - } - }); - - latch.await(2, TimeUnit.SECONDS); - - assertTrue(ref.get().isEmpty()); - } - - @Test - @Timeout(10) - @DisplayName("stealAuthCookie - If one thread is stealing cookie, other thread will bounce") - void testStealAuthCookieIfOneThreadIsStealingCookieOtherThreadWillBounce() throws InterruptedException { - ExecutorService writePool = Executors.newFixedThreadPool(2); - CountDownLatch latch = new CountDownLatch(1); - - writePool.execute(() -> { - leetcodeAuthStealer.stealAuthCookie(); - }); - - writePool.execute(() -> { - try { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - leetcodeAuthStealer.stealAuthCookie(); - } finally { - latch.countDown(); - } - }); - - latch.await(2, TimeUnit.SECONDS); - - assertTrue(logWatcher.list.stream() - .anyMatch(log -> log.getLevel().equals(Level.INFO) - && log.getFormattedMessage().contains("Lock failed to be acquired, bouncing..."))); - } - - @Test - @DisplayName("stealCookieImpl - Stores fetched credentials in memory, redis, and the auth repository") - void testStealCookieImplPersistsCredentials() { - when(leetcodeAuthenticationClient.getLeetcodeCookie()) - .thenReturn(Optional.of(new AuthenticationCredentials("new-token", "new-csrf"))); - - assertEquals("new-token", leetcodeAuthStealer.stealCookieImpl()); - - assertEquals("new-token", leetcodeAuthStealer.getCookie()); - assertEquals("new-csrf", leetcodeAuthStealer.getCsrf()); - verify(redisClient).setAuth("new-token", 4, ChronoUnit.HOURS); - verify(authRepository) - .createAuth(argThat(a -> "new-token".equals(a.getToken()) - && Optional.of("new-csrf").equals(a.getCsrf()))); - } - - @Test - @DisplayName("stealCookieImpl - Persists nothing when no credentials are returned") - void testStealCookieImplWithoutCredentials() { - when(leetcodeAuthenticationClient.getLeetcodeCookie()).thenReturn(Optional.empty()); - - assertNull(leetcodeAuthStealer.stealCookieImpl()); - - verify(redisClient, never()).setAuth(anyString(), anyLong(), any()); - verify(authRepository, never()).createAuth(any()); - } -}