Browse Source

[Refactor] Remove nearly-redundant method from SystemIndices (#87093)

The getProductSystemIndexMetadataPredicate was only used once, and could be
replaced by the very similar method getProductSystemIndexNamePredicate. This
not only simplifies the public API, but removes the cognitive load of
understanding how the two methods differed.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
William Brafford 3 years ago
parent
commit
d0b9f00596

+ 4 - 4
server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java

@@ -159,11 +159,11 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction<Get
         SystemIndexAccessLevel systemIndexAccessLevel,
         ThreadContext threadContext
     ) {
-        final Predicate<IndexMetadata> systemIndexAccessAllowPredicate;
+        final Predicate<String> systemIndexAccessAllowPredicate;
         if (systemIndexAccessLevel == SystemIndexAccessLevel.NONE) {
-            systemIndexAccessAllowPredicate = indexMetadata -> false;
+            systemIndexAccessAllowPredicate = indexName -> false;
         } else if (systemIndexAccessLevel == SystemIndexAccessLevel.RESTRICTED) {
-            systemIndexAccessAllowPredicate = systemIndices.getProductSystemIndexMetadataPredicate(threadContext);
+            systemIndexAccessAllowPredicate = systemIndices.getProductSystemIndexNamePredicate(threadContext);
         } else {
             throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel);
         }
@@ -173,7 +173,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction<Get
         aliasesMap.keySet().forEach(indexName -> {
             IndexMetadata index = state.metadata().index(indexName);
             if (index != null && index.isSystem()) {
-                if (systemIndexAccessAllowPredicate.test(index) == false) {
+                if (systemIndexAccessAllowPredicate.test(indexName) == false) {
                     if (systemIndices.isNetNewSystemIndex(indexName)) {
                         netNewSystemIndices.add(indexName);
                     } else {

+ 0 - 19
server/src/main/java/org/elasticsearch/indices/SystemIndices.java

@@ -20,7 +20,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
 import org.elasticsearch.action.support.master.AcknowledgedResponse;
 import org.elasticsearch.client.internal.Client;
-import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.Strings;
@@ -307,24 +306,6 @@ public class SystemIndices {
         return dataStreamDescriptors.get(name);
     }
 
-    /**
-     * Builds a predicate that tests if a system index should be accessible based on the provided product name
-     * contained in headers.
-     * @param threadContext the threadContext containing headers used for system index access
-     * @return Predicate to check external system index metadata with
-     */
-    public Predicate<IndexMetadata> getProductSystemIndexMetadataPredicate(ThreadContext threadContext) {
-        final String product = threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY);
-        if (product == null) {
-            return indexMetadata -> false;
-        }
-        final CharacterRunAutomaton automaton = productToSystemIndicesMatcher.get(product);
-        if (automaton == null) {
-            return indexMetadata -> false;
-        }
-        return indexMetadata -> automaton.run(indexMetadata.getIndex().getName());
-    }
-
     /**
      * Builds a predicate that tests if a system index name should be accessible based on the provided product name
      * contained in headers.