Merge pull request #2248 from nats-io/js-mappings

[fixed] deletion of js mappings on account jwt update
This commit is contained in:
Matthias Hanel
2021-05-24 16:53:42 -04:00
committed by GitHub
3 changed files with 27 additions and 17 deletions

View File

@@ -3178,7 +3178,7 @@ func (s *Server) updateAccountClaimsWithRefresh(a *Account, ac *jwt.AccountClaim
// We do not have JS enabled for this server, but the account has it enabled so setup
// our imports properly. This allows this server to proxy JS traffic correctly.
s.checkJetStreamExports()
a.enableAllJetStreamServiceImports()
a.enableAllJetStreamServiceImportsAndMappings()
}
for i, c := range clients {

View File

@@ -477,8 +477,8 @@ func (s *Server) enableJetStreamAccounts() error {
return nil
}
// enableAllJetStreamServiceImports turns on all service imports for jetstream for this account.
func (a *Account) enableAllJetStreamServiceImports() error {
// enableAllJetStreamServiceImportsAndMappings turns on all service imports and mappings for jetstream for this account.
func (a *Account) enableAllJetStreamServiceImportsAndMappings() error {
a.mu.RLock()
s := a.srv
a.mu.RUnlock()
@@ -493,6 +493,26 @@ func (a *Account) enableAllJetStreamServiceImports() error {
}
}
// Check if we have a Domain specified.
// If so add in a subject mapping that will allow local connected clients to reach us here as well.
if opts := s.getOpts(); opts.JetStreamDomain != _EMPTY_ {
src := fmt.Sprintf(jsDomainAPI, opts.JetStreamDomain)
found := false
a.mu.RLock()
for _, m := range a.mappings {
if src == m.src {
found = true
break
}
}
a.mu.RUnlock()
if !found {
if err := a.AddMapping(src, jsAllAPI); err != nil {
s.Errorf("Error adding JetStream domain mapping: %v", err)
}
}
}
return nil
}
@@ -505,7 +525,7 @@ func (a *Account) enableJetStreamInfoServiceImportOnly() error {
return nil
}
return a.enableAllJetStreamServiceImports()
return a.enableAllJetStreamServiceImportsAndMappings()
}
func (s *Server) configJetStream(acc *Account) error {
@@ -515,7 +535,7 @@ func (s *Server) configJetStream(acc *Account) error {
if acc.jsLimits != nil {
// Check if already enabled. This can be during a reload.
if acc.JetStreamEnabled() {
if err := acc.enableAllJetStreamServiceImports(); err != nil {
if err := acc.enableAllJetStreamServiceImportsAndMappings(); err != nil {
return err
}
if err := acc.UpdateJetStreamLimits(acc.jsLimits); err != nil {
@@ -843,7 +863,7 @@ func (a *Account) EnableJetStream(limits *JetStreamAccountLimits) error {
a.mu.Unlock()
// Create the proper imports here.
if err := a.enableAllJetStreamServiceImports(); err != nil {
if err := a.enableAllJetStreamServiceImportsAndMappings(); err != nil {
return err
}
@@ -851,16 +871,6 @@ func (a *Account) EnableJetStream(limits *JetStreamAccountLimits) error {
s.Debugf(" Max Memory: %s", friendlyBytes(limits.MaxMemory))
s.Debugf(" Max Storage: %s", friendlyBytes(limits.MaxStore))
// Check if we have a Domain specified.
// If so add in a subject mapping that will allow local connected clients to reach us here as well.
opts := s.getOpts()
if opts.JetStreamDomain != _EMPTY_ {
src := fmt.Sprintf(jsDomainAPI, opts.JetStreamDomain)
if err := a.AddMapping(src, jsAllAPI); err != nil {
s.Debugf("Error adding JetStream domain mapping: %v", err)
}
}
// Clean up any old snapshots that were orphaned while staging.
os.RemoveAll(path.Join(js.config.StoreDir, snapStagingDir))

View File

@@ -1613,7 +1613,7 @@ func (s *Server) Start() {
acc.mu.RUnlock()
if hasJs {
s.checkJetStreamExports()
acc.enableAllJetStreamServiceImports()
acc.enableAllJetStreamServiceImportsAndMappings()
}
return true
})