[
https://issues.apache.org/jira/browse/DRILL-8148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17498786#comment-17498786
]
ASF GitHub Bot commented on DRILL-8148:
---------------------------------------
jnturton commented on a change in pull request #2473:
URL: https://github.com/apache/drill/pull/2473#discussion_r815691049
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
##########
@@ -200,6 +202,100 @@ public Response enablePlugin(@PathParam("name") String
name, @PathParam("val") B
}
}
+ @POST
+ @Path("/storage/{name}/update_refresh_token")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateRefreshToken(@PathParam("name") String name,
+ @FormParam("refresh_token") String
refreshToken) {
+ try {
+ if (storage.getPlugin(name).getConfig() instanceof
AbstractSecuredStoragePluginConfig) {
+ DrillbitContext context = ((AbstractStoragePlugin)
storage.getPlugin(name)).getContext();
+ OAuthTokenProvider tokenProvider = context.getoAuthTokenProvider();
+ PersistentTokenTable tokenTable =
tokenProvider.getOauthTokenRegistry().getTokenTable(name);
+
+ // Set the access token
+ tokenTable.setRefreshToken(refreshToken);
+
+ return Response.status(Status.OK)
+ .entity("Refresh token have been updated.")
+ .build();
+ } else {
+ logger.error("{} is not a HTTP plugin. You can only add access tokens
to HTTP plugins.", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", name))
+ .build();
+ }
+ } catch (PluginException e) {
+ logger.error("Error when adding tokens to {}", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", e.getMessage()))
+ .build();
+ }
+ }
+ @POST
+ @Path("/storage/{name}/update_access_token")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateAccessToken(@PathParam("name") String name,
+ @FormParam("access_token") String
accessToken) {
+ try {
+ if (storage.getPlugin(name).getConfig() instanceof
AbstractSecuredStoragePluginConfig) {
+ DrillbitContext context = ((AbstractStoragePlugin)
storage.getPlugin(name)).getContext();
+ OAuthTokenProvider tokenProvider = context.getoAuthTokenProvider();
+ PersistentTokenTable tokenTable =
tokenProvider.getOauthTokenRegistry().getTokenTable(name);
+
+ // Set the access token
+ tokenTable.setAccessToken(accessToken);
+
+ return Response.status(Status.OK)
+ .entity("Access tokens have been updated.")
+ .build();
+ } else {
+ logger.error("{} is not a HTTP plugin. You can only add access tokens
to HTTP plugins.", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", name))
+ .build();
+ }
+ } catch (PluginException e) {
+ logger.error("Error when adding tokens to {}", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", e.getMessage()))
+ .build();
+ }
+ }
+
+ @POST
+ @Path("/storage/{name}/update_oauth_tokens")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateOAuthTokens(@PathParam("name") String name,
+ @FormParam("access_token") String
accessToken,
+ @FormParam("refresh_token") String
refreshToken) {
+ try {
+ if (storage.getPlugin(name).getConfig() instanceof
AbstractSecuredStoragePluginConfig) {
+ DrillbitContext context = ((AbstractStoragePlugin)
storage.getPlugin(name)).getContext();
+ OAuthTokenProvider tokenProvider = context.getoAuthTokenProvider();
+ PersistentTokenTable tokenTable =
tokenProvider.getOauthTokenRegistry().getTokenTable(name);
+
+ // Set the access and refresh token
+ tokenTable.setAccessToken(accessToken);
+ tokenTable.setRefreshToken(refreshToken);
+
+ return Response.status(Status.OK)
+ .entity("Access tokens have been updated.")
+ .build();
+ } else {
+ logger.error("{} is not a HTTP plugin. You can only add access tokens
to HTTP plugins.", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", name))
+ .build();
+ }
+ } catch (PluginException e) {
+ logger.error("Error when adding tokens to {}", name);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message("Unable to add tokens: %s", e.getMessage()))
+ .build();
+ }
+ }
+
@GET
@Path("/storage/{name}/update_oath2_authtoken")
Review comment:
```suggestion
@Path("/storage/{name}/update_oauth2_authtoken")
```
##########
File path:
contrib/storage-http/src/test/java/org/apache/drill/exec/store/http/TestOAuthTokenUpdate.java
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.drill.exec.store.http;
+
+import okhttp3.Call;
+import okhttp3.FormBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import org.apache.drill.common.logical.security.CredentialsProvider;
+import org.apache.drill.common.logical.security.PlainCredentialsProvider;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.oauth.PersistentTokenTable;
+import org.apache.drill.exec.store.StoragePluginRegistry.PluginException;
+import org.apache.drill.exec.store.security.oauth.OAuthTokenCredentials;
+import org.apache.drill.test.ClusterFixtureBuilder;
+import org.apache.drill.test.ClusterTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestOAuthTokenUpdate extends ClusterTest {
+
+ private static final String CONNECTION_NAME = "localOauth";
+ private static final int MOCK_SERVER_PORT = 47770;
+ private static final int TIMEOUT = 30;
+ private static String hostname;
+
+ private final OkHttpClient httpClient = new OkHttpClient.Builder()
+ .connectTimeout(TIMEOUT, TimeUnit.SECONDS)
+ .writeTimeout(TIMEOUT, TimeUnit.SECONDS)
+ .readTimeout(TIMEOUT, TimeUnit.SECONDS).build();
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ ClusterFixtureBuilder builder = new ClusterFixtureBuilder(dirTestWatcher)
+ .configProperty(ExecConstants.HTTP_ENABLE, true)
+ .configProperty(ExecConstants.HTTP_PORT_HUNT, true);
+ startCluster(builder);
+ int portNumber = cluster.drillbit().getWebServerPort();
+ hostname = "http://localhost:" + portNumber + "/storage/" +
CONNECTION_NAME;
+
+ Map<String, String> creds = new HashMap<>();
+ creds.put("clientID", "12345");
+ creds.put("clientSecret", "54321");
+ creds.put("accessToken", null);
+ creds.put("refreshToken", null);
+ creds.put(OAuthTokenCredentials.TOKEN_URI, "http://localhost:" +
MOCK_SERVER_PORT + "/get_access_token");
+
+ CredentialsProvider credentialsProvider = new
PlainCredentialsProvider(creds);
+
+ HttpApiConfig connectionConfig = HttpApiConfig.builder()
+ .url("http://localhost:" + MOCK_SERVER_PORT + "/getdata")
+ .method("get")
+ .requireTail(false)
+ .inputType("json")
+ .build();
+
+ HttpOAuthConfig oAuthConfig = HttpOAuthConfig.builder()
+ .callbackURL(hostname + "/update_oath2_authtoken")
Review comment:
```suggestion
.callbackURL(hostname + "/update_oauth2_authtoken")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Add REST Endpoints to Update OAuth Tokens
> -----------------------------------------
>
> Key: DRILL-8148
> URL: https://issues.apache.org/jira/browse/DRILL-8148
> Project: Apache Drill
> Issue Type: Improvement
> Affects Versions: 1.20.0
> Reporter: Charles Givre
> Assignee: Charles Givre
> Priority: Major
> Fix For: Future
>
>
> See attached PR
--
This message was sent by Atlassian Jira
(v8.20.1#820001)