@@ -144,6 +144,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
144
144
private final LazyPropertyMap <String , File > extraConfigFiles = new LazyPropertyMap <>("Extra config files" , this , FileEntry ::new );
145
145
private final LazyPropertyList <FileCollection > extraJarConfigurations = new LazyPropertyList <>("Extra jar files" , this );
146
146
private final List <Map <String , String >> credentials = new ArrayList <>();
147
+ private final List <File > roleFiles = new ArrayList <>();
147
148
final LinkedHashMap <String , String > defaultConfig = new LinkedHashMap <>();
148
149
149
150
private final Path confPathRepo ;
@@ -561,16 +562,7 @@ public synchronized void start() {
561
562
}
562
563
}
563
564
564
- if (credentials .isEmpty () == false ) {
565
- logToProcessStdout ("Setting up " + credentials .size () + " users" );
566
-
567
- credentials .forEach (
568
- paramMap -> runElasticsearchBinScript (
569
- getVersion ().onOrAfter ("6.3.0" ) ? "elasticsearch-users" : "x-pack/users" ,
570
- paramMap .entrySet ().stream ().flatMap (entry -> Stream .of (entry .getKey (), entry .getValue ())).toArray (String []::new )
571
- )
572
- );
573
- }
565
+ configureSecurity ();
574
566
575
567
if (cliSetup .isEmpty () == false ) {
576
568
logToProcessStdout ("Running " + cliSetup .size () + " setup commands" );
@@ -672,6 +664,39 @@ private void copyExtraJars() {
672
664
});
673
665
}
674
666
667
+ private void configureSecurity () {
668
+ if (credentials .isEmpty () == false ) {
669
+ logToProcessStdout ("Setting up " + credentials .size () + " users" );
670
+
671
+ credentials .forEach (
672
+ paramMap -> runElasticsearchBinScript (
673
+ getVersion ().onOrAfter ("6.3.0" ) ? "elasticsearch-users" : "x-pack/users" ,
674
+ paramMap .entrySet ().stream ().flatMap (entry -> Stream .of (entry .getKey (), entry .getValue ())).toArray (String []::new )
675
+ )
676
+ );
677
+ }
678
+ if (roleFiles .isEmpty () == false ) {
679
+ logToProcessStdout ("Setting up roles.yml" );
680
+
681
+ Path dst = configFile .getParent ().resolve ("roles.yml" );
682
+ roleFiles .forEach (from -> {
683
+ if (Files .exists (from .toPath ()) == false ) {
684
+ throw new TestClustersException (
685
+ "Can't create roles.yml config file from " + from + " for " + this + " as it does not exist"
686
+ );
687
+ }
688
+ try {
689
+ final Path source = from .toPath ();
690
+ final String content = Files .readString (source , StandardCharsets .UTF_8 );
691
+ Files .writeString (dst , content + System .lineSeparator (), StandardCharsets .UTF_8 , StandardOpenOption .APPEND );
692
+ LOGGER .info ("Appended roles file {} to {}" , source , dst );
693
+ } catch (IOException e ) {
694
+ throw new UncheckedIOException ("Can't append roles file " + from + " to " + dst , e );
695
+ }
696
+ });
697
+ }
698
+ }
699
+
675
700
private void installModules () {
676
701
logToProcessStdout ("Installing " + modules .size () + " modules" );
677
702
for (Provider <File > module : modules ) {
@@ -730,6 +755,11 @@ public void user(Map<String, String> userSpec) {
730
755
credentials .add (cred );
731
756
}
732
757
758
+ @ Override
759
+ public void rolesFile (File rolesYml ) {
760
+ roleFiles .add (rolesYml );
761
+ }
762
+
733
763
private void runElasticsearchBinScriptWithInput (String input , String tool , CharSequence ... args ) {
734
764
if (Files .exists (getDistroDir ().resolve ("bin" ).resolve (tool )) == false
735
765
&& Files .exists (getDistroDir ().resolve ("bin" ).resolve (tool + ".bat" )) == false ) {
@@ -1373,6 +1403,12 @@ private List<FileTree> getDistributionFiles(Action<PatternFilterable> patternFil
1373
1403
return files ;
1374
1404
}
1375
1405
1406
+ @ InputFiles
1407
+ @ PathSensitive (PathSensitivity .RELATIVE )
1408
+ public List <File > getRoleFiles () {
1409
+ return roleFiles ;
1410
+ }
1411
+
1376
1412
@ Nested
1377
1413
public List <?> getKeystoreSettings () {
1378
1414
return keystoreSettings .getNormalizedCollection ();
0 commit comments