-
Notifications
You must be signed in to change notification settings - Fork 3
/
stream_imports.go
80 lines (70 loc) · 1.6 KB
/
stream_imports.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package authb
import (
"errors"
"github.com/nats-io/jwt/v2"
)
type streamImports struct {
*AccountData
}
func (s *streamImports) Get(subject string) (StreamImport, error) {
si := s.getStreamImport(subject)
if si != nil {
return si, nil
}
return nil, ErrNotFound
}
func (s *streamImports) AddWithConfig(i StreamImport) error {
if i == nil {
return errors.New("invalid stream import")
}
be, ok := i.(*StreamImportImpl)
if !ok {
return errors.New("invalid stream import")
}
if err := s.addImport(be.in); err != nil {
return err
}
return s.update()
}
func (s *streamImports) Add(name string, account string, subject string) (StreamImport, error) {
if err := s.newImport(name, account, subject, jwt.Stream); err != nil {
return nil, err
}
x := s.getStreamImport(subject)
if x == nil {
return nil, errors.New("could not find stream")
}
return x, nil
}
func (s *streamImports) Set(imports ...StreamImport) error {
var buf []*jwt.Import
for _, e := range s.Claim.Imports {
if e.IsService() {
buf = append(buf, e)
}
}
s.Claim.Imports = buf
for _, e := range imports {
if err := s.AddWithConfig(e); err != nil {
return err
}
}
return s.update()
}
func (s *streamImports) Delete(subject string) (bool, error) {
return s.deleteImport(subject, false)
}
func (a *AccountData) GetByName(name string) (StreamImport, error) {
for _, e := range a.Claim.Imports {
if e.IsStream() && e.Name == name {
se := &StreamImportImpl{}
se.data = a
se.in = e
return se, nil
}
}
return nil, ErrNotFound
}
func (s *streamImports) List() []StreamImport {
return s.getStreamImports()
}