...
1
2
3
4
5
6
7
8
9
10
11
12
13 package memorydb
14
15 import (
16 "context"
17 "errors"
18 "net/http"
19
20 "github.com/go-kivik/kivik/v4/driver"
21 )
22
23 func cloneSecurity(in *driver.Security) *driver.Security {
24 return &driver.Security{
25 Admins: driver.Members{
26 Names: in.Admins.Names,
27 Roles: in.Admins.Roles,
28 },
29 Members: driver.Members{
30 Names: in.Members.Names,
31 Roles: in.Members.Roles,
32 },
33 }
34 }
35
36 func (d *db) Security(ctx context.Context) (*driver.Security, error) {
37 if exists, _ := d.DBExists(ctx, d.dbName, nil); !exists {
38 return nil, statusError{status: http.StatusNotFound, error: errors.New("database does not exist")}
39 }
40 d.db.mu.RLock()
41 defer d.db.mu.RUnlock()
42 if d.db.deleted {
43 return nil, statusError{status: http.StatusNotFound, error: errors.New("missing")}
44 }
45 return cloneSecurity(d.db.security), nil
46 }
47
48 func (d *db) SetSecurity(_ context.Context, sec *driver.Security) error {
49 d.db.mu.Lock()
50 defer d.db.mu.Unlock()
51 if d.db.deleted {
52 return statusError{status: http.StatusNotFound, error: errors.New("missing")}
53 }
54 d.db.security = cloneSecurity(sec)
55 return nil
56 }
57
View as plain text