|
2 | 2 |
|
3 | 3 | import com.google.gson.JsonObject;
|
4 | 4 | import com.google.gson.reflect.TypeToken;
|
5 |
| -import io.netty.handler.codec.http.FullHttpRequest; |
6 | 5 | import io.netty.handler.ssl.SslContext;
|
7 | 6 | import io.netty.handler.ssl.SslContextBuilder;
|
8 | 7 | import io.netty.handler.ssl.util.SelfSignedCertificate;
|
|
46 | 45 | import org.apache.commons.cli.Option;
|
47 | 46 | import org.apache.commons.cli.Options;
|
48 | 47 | import org.apache.commons.io.IOUtils;
|
49 |
| -import org.pytorch.serve.archive.model.InvalidKeyException; |
50 |
| -import org.pytorch.serve.archive.model.ModelException; |
51 | 48 | import org.pytorch.serve.metrics.MetricBuilder;
|
52 | 49 | import org.pytorch.serve.servingsdk.snapshot.SnapshotSerializer;
|
53 | 50 | import org.pytorch.serve.snapshot.SnapshotSerializerFactory;
|
@@ -850,95 +847,15 @@ public boolean isSnapshotDisabled() {
|
850 | 847 | return snapshotDisabled;
|
851 | 848 | }
|
852 | 849 |
|
853 |
| - // Imports the token class and sets the expiration time either default or custom |
854 |
| - // calls generate key file in token api to create 3 keys and logs the result |
855 |
| - public void setupTokenClass() { |
856 |
| - try { |
857 |
| - tokenClass = Class.forName("org.pytorch.serve.plugins.endpoint.Token"); |
858 |
| - tokenObject = tokenClass.getDeclaredConstructor().newInstance(); |
859 |
| - Method method = tokenClass.getMethod("setTime", Integer.class); |
860 |
| - if (prop.getProperty(TS_TOKEN_EXPIRATION_TIME) != null) { |
861 |
| - timeToExpiration = Integer.valueOf(prop.getProperty(TS_TOKEN_EXPIRATION_TIME)); |
862 |
| - } |
863 |
| - method.invoke(tokenObject, timeToExpiration); |
864 |
| - method = tokenClass.getMethod("generateKeyFile", Integer.class); |
865 |
| - if ((boolean) method.invoke(tokenObject, 0)) { |
866 |
| - System.out.println("TOKEN CLASS IMPORTED SUCCESSFULLY"); |
867 |
| - dumpKeyLogs(); |
868 |
| - } |
869 |
| - } catch (ClassNotFoundException e) { |
870 |
| - e.printStackTrace(); |
871 |
| - } catch (NoSuchMethodException |
872 |
| - | IllegalAccessException |
873 |
| - | InstantiationException |
874 |
| - | InvocationTargetException e) { |
875 |
| - e.printStackTrace(); |
876 |
| - } |
877 |
| - tokenAuthorizationEnabled = true; |
878 |
| - } |
879 |
| - |
880 |
| - public void dumpKeyLogs() { |
881 |
| - String managementKey = ""; |
882 |
| - String inferenceKey = ""; |
883 |
| - String apiKey = ""; |
884 |
| - try { |
885 |
| - Method method = tokenClass.getMethod("getManagementKey"); |
886 |
| - managementKey = (String) method.invoke(tokenObject); |
887 |
| - method = tokenClass.getMethod("getInferenceKey"); |
888 |
| - inferenceKey = (String) method.invoke(tokenObject); |
889 |
| - method = tokenClass.getMethod("getKey"); |
890 |
| - apiKey = (String) method.invoke(tokenObject); |
891 |
| - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
892 |
| - e.printStackTrace(); |
893 |
| - } |
894 |
| - |
895 |
| - logger.info("KEY FILE PATH: " + System.getProperty("user.dir") + "/key_file.txt"); |
896 |
| - logger.info("MANAGEMENT KEY: " + managementKey); |
897 |
| - logger.info("INFERNCE KEY: " + inferenceKey); |
898 |
| - logger.info("API KEY: " + apiKey); |
899 |
| - logger.info( |
900 |
| - "MANAGEMENT API Example: curl http://localhost:8081/models/<model> -H \"Authorization: Bearer " |
901 |
| - + managementKey |
902 |
| - + "\""); |
903 |
| - logger.info( |
904 |
| - "INFERNCE API Example: curl http://127.0.0.1:8080/predictions/<model> -T <examples/image_classifier/kitten.jpg> -H \"Authorization: Bearer " |
905 |
| - + inferenceKey |
906 |
| - + "\""); |
907 |
| - logger.info( |
908 |
| - "API API Example: curl localhost:8081/token?type=management -H \"Authorization: Bearer " |
909 |
| - + apiKey |
910 |
| - + "\""); |
911 |
| - } |
912 |
| - |
913 | 850 | public boolean isTokenEnabled() {
|
914 | 851 | return tokenAuthorizationEnabled;
|
915 | 852 | }
|
916 | 853 |
|
917 |
| - // Calls the checkTokenAuthorization function in the token plugin |
918 |
| - // expects two inputs: the fullhttpRequest and an integer which is associated with the type |
919 |
| - // 0: token api |
920 |
| - // 1: management api |
921 |
| - // 2: inference api |
922 |
| - public void checkTokenAuthorization(FullHttpRequest req, Integer requestType) |
923 |
| - throws ModelException { |
924 |
| - |
925 |
| - if (tokenAuthorizationEnabled) { |
926 |
| - try { |
927 |
| - Method method = |
928 |
| - tokenClass.getMethod( |
929 |
| - "checkTokenAuthorization", |
930 |
| - io.netty.handler.codec.http.FullHttpRequest.class, |
931 |
| - Integer.class); |
932 |
| - boolean result = (boolean) (method.invoke(tokenObject, req, requestType)); |
933 |
| - if (!result) { |
934 |
| - throw new InvalidKeyException( |
935 |
| - "Token Authenticaation failed. Token either incorrect, expired, or not provided correctly"); |
936 |
| - } |
937 |
| - System.out.println("TOKEN AUTHORIZATION WORKED"); |
938 |
| - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
939 |
| - e.printStackTrace(); |
940 |
| - } |
| 854 | + public Integer getTimeToExpiration() { |
| 855 | + if (prop.getProperty(TS_TOKEN_EXPIRATION_TIME) != null) { |
| 856 | + return Integer.valueOf(prop.getProperty(TS_TOKEN_EXPIRATION_TIME)); |
941 | 857 | }
|
| 858 | + return 0; |
942 | 859 | }
|
943 | 860 |
|
944 | 861 | public boolean isSSLEnabled(ConnectorType connectorType) {
|
|
0 commit comments