-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map extension routes to permission-able action names #622
Changes from all commits
daf3b2c
9c49d95
97d2a22
b5703ae
36b67cc
9238527
a9325d2
0a1425b
0b634be
38baa81
d504ed8
6826fef
0825b74
5afe8c8
ef085ce
4966514
b287fe5
ff158f6
a80cae7
636bcdc
b08d018
1c23d9c
e45ea0e
10127c4
1eeafe6
f4ab756
66654ba
df30efd
03025e4
09a84a3
9830335
f7697b1
6d7ec26
8576654
8a93770
bdea4ea
ee09450
a989151
af084b4
0b37c06
c04bda1
fb4f0bc
15c82db
54d057c
5fb6497
81c25ce
0c5ce25
b880d93
ecf51e4
59f316c
93b6daf
326422c
a926392
f42db71
06f8e98
024aace
9658efe
7aeef67
786f01b
70d9088
80ba90c
1e06d01
e0df300
058f12a
433a42a
20885c0
ba60cb7
f460699
6d2ee04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,12 @@ | |
public class ExtensionSettings { | ||
|
||
private String extensionName; | ||
private String shortExtensionName; | ||
private String hostAddress; | ||
private String hostPort; | ||
private String opensearchAddress; | ||
private String opensearchPort; | ||
private Map<String, String> securitySettings; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also be |
||
|
||
/** | ||
* A set of keys for security settings related to SSL transport, keystore and truststore files, and hostname verification. | ||
|
@@ -83,8 +85,6 @@ public class ExtensionSettings { | |
SSL_TRANSPORT_TRUSTSTORE_TYPE | ||
); | ||
|
||
private Map<String, String> securitySettings; | ||
|
||
/** | ||
* Jackson requires a no-arg constructor. | ||
*/ | ||
|
@@ -97,14 +97,23 @@ private ExtensionSettings() { | |
* Instantiate this class using the specified parameters. | ||
* | ||
* @param extensionName The extension name. Provided to OpenSearch as a response to initialization query. Must match the defined extension name in OpenSearch. | ||
* @param shortExtensionName The shortened name for the extension | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need more documentation here on what purpose a shortened name has. How is this distinct from the unique ID? What happens if two different extensions both choose the same shortened name? Would Anomaly Detection (ad) permissions apply to the Action Dispatcher (ad) extension or Auto Deletion (ad) extension (I really want one that does auto rolling index deletion on a capacity trigger) or Awesome Dan (ad) extension that bolds my name everywhere? |
||
* @param hostAddress The IP Address to bind this extension to. | ||
* @param hostPort The port to bind this extension to. | ||
* @param opensearchAddress The IP Address on which OpenSearch is running. | ||
* @param opensearchPort The port on which OpenSearch is running. | ||
*/ | ||
public ExtensionSettings(String extensionName, String hostAddress, String hostPort, String opensearchAddress, String opensearchPort) { | ||
public ExtensionSettings( | ||
String extensionName, | ||
String shortExtensionName, | ||
String hostAddress, | ||
String hostPort, | ||
String opensearchAddress, | ||
String opensearchPort | ||
) { | ||
super(); | ||
this.extensionName = extensionName; | ||
this.shortExtensionName = shortExtensionName; | ||
this.hostAddress = hostAddress; | ||
this.hostPort = hostPort; | ||
this.opensearchAddress = opensearchAddress; | ||
|
@@ -116,6 +125,7 @@ public ExtensionSettings(String extensionName, String hostAddress, String hostPo | |
* Instantiate this class using the specified parameters. | ||
* | ||
* @param extensionName The extension name. Provided to OpenSearch as a response to initialization query. Must match the defined extension name in OpenSearch. | ||
* @param shortExtensionName The shortened name for the extension | ||
* @param hostAddress The IP Address to bind this extension to. | ||
* @param hostPort The port to bind this extension to. | ||
* @param opensearchAddress The IP Address on which OpenSearch is running. | ||
|
@@ -124,13 +134,14 @@ public ExtensionSettings(String extensionName, String hostAddress, String hostPo | |
*/ | ||
public ExtensionSettings( | ||
String extensionName, | ||
String shortExtensionName, | ||
String hostAddress, | ||
String hostPort, | ||
String opensearchAddress, | ||
String opensearchPort, | ||
Map<String, String> securitySettings | ||
) { | ||
this(extensionName, hostAddress, hostPort, opensearchAddress, opensearchPort); | ||
this(extensionName, shortExtensionName, hostAddress, hostPort, opensearchAddress, opensearchPort); | ||
this.securitySettings = securitySettings; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor overloading seems off somehow. Setting something and also calling another constructor seems unusual. Is there a way we can make this the primary constructor (that sets All The Things) and have all the other constructors delegate to it with defaults for the missing parameters? |
||
} | ||
|
||
|
@@ -142,6 +153,10 @@ public String getExtensionName() { | |
return extensionName; | ||
} | ||
|
||
public String getShortExtensionName() { | ||
return shortExtensionName; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This getter should have a test in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been added to a few different tests to verify its behavior |
||
|
||
/** | ||
* Returns the host address associated with this object. | ||
* @return The host address as a string. | ||
|
@@ -203,6 +218,8 @@ public Map<String, String> getSecuritySettings() { | |
public String toString() { | ||
return "ExtensionSettings{extensionName=" | ||
+ extensionName | ||
+ ", shortName=" | ||
+ shortExtensionName | ||
+ ", hostAddress=" | ||
+ hostAddress | ||
+ ", hostPort=" | ||
|
@@ -242,6 +259,7 @@ public static ExtensionSettings readSettingsFromYaml(String extensionSettingsPat | |
} | ||
return new ExtensionSettings( | ||
extensionMap.get("extensionName").toString(), | ||
extensionMap.get("shortExtensionName").toString(), | ||
extensionMap.get("hostAddress").toString(), | ||
extensionMap.get("hostPort").toString(), | ||
extensionMap.get("opensearchAddress").toString(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,12 @@ | |
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.opensearch.common.Nullable; | ||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.path.PathTrie; | ||
import org.opensearch.extensions.rest.RouteHandler; | ||
import org.opensearch.rest.RestRequest.Method; | ||
import org.opensearch.rest.RestUtils; | ||
import org.opensearch.sdk.rest.BaseExtensionRestHandler.ExtensionDeprecationRestHandler; | ||
|
@@ -38,7 +40,13 @@ public class ExtensionRestPathRegistry { | |
* @param restHandler The RestHandler to register routes. | ||
*/ | ||
public void registerHandler(ExtensionRestHandler restHandler) { | ||
restHandler.routes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler)); | ||
restHandler.routes().forEach(route -> { | ||
Optional<String> routeActionName = Optional.empty(); | ||
if (route instanceof RouteHandler && ((RouteHandler) route).name() != null) { | ||
routeActionName = Optional.of(((RouteHandler) route).name()); | ||
} | ||
registerHandler(route.getMethod(), route.getPath(), routeActionName, restHandler); | ||
}); | ||
restHandler.deprecatedRoutes() | ||
.forEach(route -> registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage())); | ||
restHandler.replacedRoutes() | ||
|
@@ -57,20 +65,21 @@ public void registerHandler(ExtensionRestHandler restHandler) { | |
* Registers a REST handler to be executed when one of the provided methods and path match the request. | ||
* | ||
* @param path Path to handle (e.g., "/{index}/{type}/_bulk") | ||
* @param handler The handler to actually execute | ||
* @param extensionRestHandler The handler to actually execute | ||
* @param name The name corresponding to this handler | ||
* @param method GET, POST, etc. | ||
*/ | ||
private void registerHandler(Method method, String path, ExtensionRestHandler extensionRestHandler) { | ||
public void registerHandler(Method method, String path, Optional<String> name, ExtensionRestHandler extensionRestHandler) { | ||
pathTrie.insertOrUpdate( | ||
path, | ||
new SDKMethodHandlers(path, extensionRestHandler, method), | ||
(mHandlers, newMHandler) -> mHandlers.addMethods(extensionRestHandler, method) | ||
); | ||
if (extensionRestHandler instanceof ExtensionDeprecationRestHandler) { | ||
registeredDeprecatedPaths.add(restPathToString(method, path)); | ||
registeredDeprecatedPaths.add(restPathToString(method, path, name)); | ||
registeredDeprecatedPaths.add(((ExtensionDeprecationRestHandler) extensionRestHandler).getDeprecationMessage()); | ||
} else { | ||
registeredPaths.add(restPathToString(method, path)); | ||
registeredPaths.add(restPathToString(method, path, name)); | ||
} | ||
} | ||
|
||
|
@@ -85,7 +94,12 @@ private void registerHandler(Method method, String path, ExtensionRestHandler ex | |
private void registerAsDeprecatedHandler(Method method, String path, ExtensionRestHandler handler, String deprecationMessage) { | ||
assert (handler instanceof ExtensionDeprecationRestHandler) == false; | ||
|
||
registerHandler(method, path, new ExtensionDeprecationRestHandler(handler, deprecationMessage, deprecationLogger)); | ||
registerHandler( | ||
method, | ||
path, | ||
Optional.empty(), | ||
new ExtensionDeprecationRestHandler(handler, deprecationMessage, deprecationLogger) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -129,7 +143,7 @@ private void registerWithDeprecatedHandler( | |
+ path | ||
+ "] instead."; | ||
|
||
registerHandler(method, path, handler); | ||
registerHandler(method, path, Optional.empty(), handler); | ||
registerAsDeprecatedHandler(deprecatedMethod, deprecatedPath, handler, deprecationMessage); | ||
} | ||
|
||
|
@@ -171,9 +185,13 @@ public List<String> getRegisteredDeprecatedPaths() { | |
* | ||
* @param method the method. | ||
* @param path the path. | ||
* @param name the name corresponding to this route. | ||
* @return A string appending the method and path. | ||
*/ | ||
public static String restPathToString(Method method, String path) { | ||
public static String restPathToString(Method method, String path, Optional<String> name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally this was a more important method but I think it's been reduced to a cosmetic/logging/exception-message method as the rest paths are stored in the |
||
if (name.isPresent()) { | ||
return method.name() + " " + path + " " + name.get(); | ||
} | ||
return method.name() + " " + path; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is used for singleton security setup later, should it be
final
?