You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2022/02/28 08:59:06 UTC

[GitHub] [drill] jnturton commented on a change in pull request #2473: DRILL-8148: Add REST Endpoints to Update OAuth Tokens

jnturton commented on a change in pull request #2473:
URL: https://github.com/apache/drill/pull/2473#discussion_r815689882



##########
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();
+    }
+  }

Review comment:
       ```suggestion
     }
     
   ```




-- 
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: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org