Skip to content

Commit

Permalink
support local subject of import rule
Browse files Browse the repository at this point in the history
  • Loading branch information
licheng5625 committed May 11, 2022
1 parent 427916a commit c36ffd6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main/java/natsTest/NatsAccountJwtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ public static String issueAccountJWT(String operatorSigningKey, String operatorS
if (importRule.account != null) {
rule.put("account", importRule.account);
}
if (importRule.local_subject != null) {
rule.put("local_subject", importRule.local_subject);
}
rule.put("name", importRule.name);
rule.put("subject", importRule.subject);
NatsImportRule.Types sd = importRule.type;
String sd2 = sd.toString();
rule.put("type", importRule.type.toString());
importRules.put(rule);
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/natsTest/NatsImportRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class NatsImportRule {
public String name = "default";
public String subject = ">";
public String account = null;
public String local_subject = null;
public Types type = Types.STREAM;
public enum Types {
STREAM{
Expand All @@ -17,7 +18,7 @@ public String toString() {
SERVICE{
@Override
public String toString() {
return super.toString().toLowerCase(Locale.ROOT) ;
return super.toString().toLowerCase() ;
}
}
}
Expand All @@ -30,12 +31,16 @@ public NatsImportRule(String account, String subject) {
this(account);
this.subject = subject;
}
public NatsImportRule(String account , String subject, String name ){
this(account,subject);
public NatsImportRule(String account, String subject, String local_subject) {
this(account, subject);
this.local_subject = local_subject;
}
public NatsImportRule(String account , String subject, String local_subject, String name ){
this(account,subject,local_subject);
this.name = name;
}
public NatsImportRule(String account , String subject, String name, NatsImportRule.Types type){
this(account,subject, name);
public NatsImportRule(String account , String subject, String local_subject, String name, NatsImportRule.Types type){
this(account,subject,local_subject,name);
this.type = type;
}
}
4 changes: 2 additions & 2 deletions src/test/java/natsTest/NatsCreateUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public void issueUserJWTSuccessMinimal() throws Exception {
String importedAccountId = "AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

NatsAccount account = new NatsAccount( "ACOUNT_NAME" );
account.addImportRule(new NatsImportRule(importedAccountId, "*.dts.>", "receiving"));
account.addImportRule(new NatsImportRule(importedAccountId,"*.dts.>", "sending", NatsImportRule.Types.SERVICE));
account.addImportRule(new NatsImportRule(importedAccountId, "*.dts.>", null,"receiving"));
account.addImportRule(new NatsImportRule(importedAccountId,"*.dts.>", "API.PREFIX.dts.*","sending", NatsImportRule.Types.SERVICE));
System.out.println(account.getJWT());

account.pushToServer("nats://localhost:4222");
Expand Down

0 comments on commit c36ffd6

Please sign in to comment.