master
go 63 lines 1.14 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package secretstore
4
5 import (
6 "maps"
7 "time"
8 )
9
10 type publishedRecord struct {
11 published PublishedStore
12 }
13
14 type Snapshot struct {
15 generation uint64
16 publishedAt time.Time
17 stores map[string]publishedRecord
18 }
19
20 func (s *Snapshot) Generation() uint64 {
21 if s == nil {
22 return 0
23 }
24 return s.generation
25 }
26
27 func (s *Snapshot) PublishedAt() time.Time {
28 if s == nil {
29 return time.Time{}
30 }
31 return s.publishedAt
32 }
33
34 func (s *Snapshot) lookupStore(key string) (publishedRecord, bool) {
35 if s == nil {
36 return publishedRecord{}, false
37 }
38 store, ok := s.stores[key]
39 if !ok {
40 return publishedRecord{}, false
41 }
42 return store, true
43 }
44
45 func cloneSnapshot(s *Snapshot) *Snapshot {
46 if s == nil {
47 return &Snapshot{stores: map[string]publishedRecord{}}
48 }
49 return &Snapshot{
50 generation: s.generation,
51 publishedAt: s.publishedAt,
52 stores: clonePublishedRecords(s.stores),
53 }
54 }
55
56 func clonePublishedRecords(in map[string]publishedRecord) map[string]publishedRecord {
57 if len(in) == 0 {
58 return map[string]publishedRecord{}
59 }
60 out := make(map[string]publishedRecord, len(in))
61 maps.Copy(out, in)
62 return out
63 }