refact(bsr): Rename const to denote when interpolation is needed
This commit is contained in:
4 files changed
+50
-50
No files matched your search
+30
-30
@@ -19,18 +19,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
bsrFile = "%s.bsr"
|
||||
connectionFile = "%s.connection"
|
||||
channelFile = "%s.channel"
|
||||
messagesFile = "messages-%s.data"
|
||||
requestsFile = "requests-%s.data"
|
||||
sessionMetaFile = "session-meta.json"
|
||||
bsrFileNameTemplate = "%s.bsr"
|
||||
connectionFileNameTemplate = "%s.connection"
|
||||
channelFileNameTemplate = "%s.channel"
|
||||
messagesFileNameTemplate = "messages-%s.data"
|
||||
requestsFileNameTemplate = "requests-%s.data"
|
||||
sessionMetaFileName = "session-meta.json"
|
||||
|
||||
bsrPubKeyFile = "bsrKey.pub"
|
||||
wrappedBsrKeyFile = "wrappedBsrKey"
|
||||
wrappedPrivKeyFile = "wrappedPrivKey"
|
||||
pubKeyBsrSignatureFile = "pubKeyBsrSignature.sign"
|
||||
pubKeySelfSignatureFile = "pubKeySelfSignature.sign"
|
||||
bsrPubKeyFileName = "bsrKey.pub"
|
||||
wrappedBsrKeyFileName = "wrappedBsrKey"
|
||||
wrappedPrivKeyFileName = "wrappedPrivKey"
|
||||
pubKeyBsrSignatureFileName = "pubKeyBsrSignature.sign"
|
||||
pubKeySelfSignatureFileName = "pubKeySelfSignature.sign"
|
||||
)
|
||||
|
||||
// Session is the top level container in a bsr that contains the files for
|
||||
@@ -74,7 +74,7 @@ func NewSession(ctx context.Context, meta *SessionRecordingMeta, sessionMeta *Se
|
||||
|
||||
opts := getOpts(options...)
|
||||
|
||||
c, err := f.New(ctx, fmt.Sprintf(bsrFile, meta.Id))
|
||||
c, err := f.New(ctx, fmt.Sprintf(bsrFileNameTemplate, meta.Id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func NewSession(ctx context.Context, meta *SessionRecordingMeta, sessionMeta *Se
|
||||
return nil, errors.Join(err, fmt.Errorf("%s: %w", op, ErrBsrKeyPersistenceFailure))
|
||||
}
|
||||
|
||||
sm, err := nc.create(ctx, sessionMetaFile)
|
||||
sm, err := nc.create(ctx, sessionMetaFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -145,11 +145,11 @@ func persistBsrSessionKeys(ctx context.Context, keys *kms.Keys, c *container) er
|
||||
}
|
||||
|
||||
keyFiles := map[string]proto.Message{
|
||||
bsrPubKeyFile: keys.PubKey,
|
||||
wrappedBsrKeyFile: keys.WrappedBsrKey,
|
||||
wrappedPrivKeyFile: keys.WrappedPrivKey,
|
||||
pubKeyBsrSignatureFile: keys.PubKeyBsrSignature,
|
||||
pubKeySelfSignatureFile: keys.PubKeySelfSignature,
|
||||
bsrPubKeyFileName: keys.PubKey,
|
||||
wrappedBsrKeyFileName: keys.WrappedBsrKey,
|
||||
wrappedPrivKeyFileName: keys.WrappedPrivKey,
|
||||
pubKeyBsrSignatureFileName: keys.PubKeyBsrSignature,
|
||||
pubKeySelfSignatureFileName: keys.PubKeySelfSignature,
|
||||
}
|
||||
for f, k := range keyFiles {
|
||||
b, err := proto.Marshal(k)
|
||||
@@ -181,7 +181,7 @@ func OpenSession(ctx context.Context, sessionRecordingId string, f storage.FS, k
|
||||
return nil, fmt.Errorf("%s: missing key unwrap function: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
c, err := f.Open(ctx, fmt.Sprintf(bsrFile, sessionRecordingId))
|
||||
c, err := f.Open(ctx, fmt.Sprintf(bsrFileNameTemplate, sessionRecordingId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func OpenSession(ctx context.Context, sessionRecordingId string, f storage.FS, k
|
||||
}
|
||||
|
||||
sessionMeta := &SessionMeta{}
|
||||
if err := cc.decodeJsonFile(ctx, sessionMetaFile, sessionMeta); err != nil {
|
||||
if err := cc.decodeJsonFile(ctx, sessionMetaFileName, sessionMeta); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func (s *Session) NewConnection(ctx context.Context, meta *ConnectionRecordingMe
|
||||
return nil, fmt.Errorf("%s: missing connection id: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
name := fmt.Sprintf(connectionFile, meta.Id)
|
||||
name := fmt.Sprintf(connectionFileNameTemplate, meta.Id)
|
||||
sc, err := s.container.container.SubContainer(ctx, name, storage.WithCreateFile(), storage.WithFileAccessMode(storage.WriteOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -278,7 +278,7 @@ func (s *Session) OpenConnection(ctx context.Context, connId string) (*Connectio
|
||||
return nil, fmt.Errorf("%s: missing connection id: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
name := fmt.Sprintf(connectionFile, connId)
|
||||
name := fmt.Sprintf(connectionFileNameTemplate, connId)
|
||||
|
||||
switch {
|
||||
case !s.Meta.connections[name]:
|
||||
@@ -335,7 +335,7 @@ func (c *Connection) NewChannel(ctx context.Context, meta *ChannelRecordingMeta)
|
||||
return nil, fmt.Errorf("%s: missing channel id: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
name := fmt.Sprintf(channelFile, meta.Id)
|
||||
name := fmt.Sprintf(channelFileNameTemplate, meta.Id)
|
||||
sc, err := c.container.container.SubContainer(ctx, name, storage.WithCreateFile(), storage.WithFileAccessMode(storage.WriteOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -367,7 +367,7 @@ func (c *Connection) OpenChannel(ctx context.Context, chanId string) (*Channel,
|
||||
return nil, fmt.Errorf("%s: missing channel id: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
name := fmt.Sprintf(channelFile, chanId)
|
||||
name := fmt.Sprintf(channelFileNameTemplate, chanId)
|
||||
switch {
|
||||
case !c.Meta.channels[name]:
|
||||
return nil, fmt.Errorf("%s: channel id does not exist within this connection: %w", op, ErrInvalidParameter)
|
||||
@@ -417,7 +417,7 @@ func (c *Connection) NewMessagesWriter(ctx context.Context, dir Direction) (io.W
|
||||
return nil, fmt.Errorf("%s: invalid direction: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
messagesName := fmt.Sprintf(messagesFile, dir.String())
|
||||
messagesName := fmt.Sprintf(messagesFileNameTemplate, dir.String())
|
||||
_, err := c.container.WriteMeta(ctx, "messages", dir.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -439,7 +439,7 @@ func (c *Connection) NewRequestsWriter(ctx context.Context, dir Direction) (io.W
|
||||
return nil, fmt.Errorf("%s: invalid direction: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
requestName := fmt.Sprintf(requestsFile, dir.String())
|
||||
requestName := fmt.Sprintf(requestsFileNameTemplate, dir.String())
|
||||
_, err := c.container.WriteMeta(ctx, "requests", dir.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -479,7 +479,7 @@ func (c *Channel) NewMessagesWriter(ctx context.Context, dir Direction) (io.Writ
|
||||
return nil, fmt.Errorf("%s: invalid direction: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
messagesName := fmt.Sprintf(messagesFile, dir.String())
|
||||
messagesName := fmt.Sprintf(messagesFileNameTemplate, dir.String())
|
||||
_, err := c.container.WriteMeta(ctx, "messages", dir.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -501,7 +501,7 @@ func (c *Channel) NewRequestsWriter(ctx context.Context, dir Direction) (io.Writ
|
||||
return nil, fmt.Errorf("%s: invalid direction: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
requestName := fmt.Sprintf(requestsFile, dir.String())
|
||||
requestName := fmt.Sprintf(requestsFileNameTemplate, dir.String())
|
||||
_, err := c.container.WriteMeta(ctx, "requests", dir.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -518,7 +518,7 @@ func (c *Channel) NewRequestsWriter(ctx context.Context, dir Direction) (io.Writ
|
||||
func (c *Channel) OpenMessageScanner(ctx context.Context, dir Direction) (*ChunkScanner, error) {
|
||||
const op = "bsr.(Channel).OpenMessageScanner"
|
||||
|
||||
messagesName := fmt.Sprintf(messagesFile, dir.String())
|
||||
messagesName := fmt.Sprintf(messagesFileNameTemplate, dir.String())
|
||||
m, err := c.container.container.OpenFile(ctx, messagesName, storage.WithFileAccessMode(storage.ReadOnly))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", op, err)
|
||||
@@ -534,7 +534,7 @@ func (c *Channel) OpenMessageScanner(ctx context.Context, dir Direction) (*Chunk
|
||||
func (c *Channel) OpenRequestScanner(ctx context.Context, dir Direction) (*ChunkScanner, error) {
|
||||
const op = "bsr.(Channel).OpenRequestScanner"
|
||||
|
||||
requestName := fmt.Sprintf(requestsFile, dir.String())
|
||||
requestName := fmt.Sprintf(requestsFileNameTemplate, dir.String())
|
||||
m, err := c.container.container.OpenFile(ctx, requestName, storage.WithFileAccessMode(storage.ReadOnly))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", op, err)
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestPopulateMeta(t *testing.T) {
|
||||
require.Equal(t, s.Meta.Protocol, srm.Protocol)
|
||||
|
||||
gotSessionMeta := &SessionMeta{}
|
||||
r, err := s.container.container.OpenFile(ctx, sessionMetaFile)
|
||||
r, err := s.container.container.OpenFile(ctx, sessionMetaFileName)
|
||||
require.NoError(t, err)
|
||||
dec := json.NewDecoder(r)
|
||||
err = dec.Decode(gotSessionMeta)
|
||||
|
||||
+18
-18
@@ -23,11 +23,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
metaFile = "%s-recording.meta"
|
||||
summaryFile = "%s-recording-summary.json"
|
||||
checksumFile = "SHA256SUM"
|
||||
sigFile = "SHA256SUM.sig"
|
||||
journalFile = ".journal"
|
||||
metaFileNameTemplate = "%s-recording.meta"
|
||||
summaryFileNameTemplate = "%s-recording-summary.json"
|
||||
checksumFileName = "SHA256SUM"
|
||||
sigFileName = "SHA256SUM.sig"
|
||||
journalFileName = ".journal"
|
||||
)
|
||||
|
||||
// ContainerType defines the type of container.
|
||||
@@ -65,7 +65,7 @@ type container struct {
|
||||
|
||||
// newContainer creates a container for the given type backed by the provide storage.Container.
|
||||
func newContainer(ctx context.Context, t containerType, c storage.Container, keys *kms.Keys) (*container, error) {
|
||||
j, err := c.OpenFile(ctx, journalFile,
|
||||
j, err := c.OpenFile(ctx, journalFileName,
|
||||
storage.WithCreateFile(),
|
||||
storage.WithFileAccessMode(storage.WriteOnly),
|
||||
storage.WithCloseSyncMode(storage.NoSync))
|
||||
@@ -82,12 +82,12 @@ func newContainer(ctx context.Context, t containerType, c storage.Container, key
|
||||
keys: keys,
|
||||
}
|
||||
|
||||
cc.sigs, err = cc.create(ctx, sigFile)
|
||||
cc.sigs, err = cc.create(ctx, sigFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cs, err := cc.create(ctx, checksumFile)
|
||||
cs, err := cc.create(ctx, checksumFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func newContainer(ctx context.Context, t containerType, c storage.Container, key
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cc.metaName = fmt.Sprintf(metaFile, t)
|
||||
cc.metaName = fmt.Sprintf(metaFileNameTemplate, t)
|
||||
meta, err := cc.create(ctx, cc.metaName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,7 +106,7 @@ func newContainer(ctx context.Context, t containerType, c storage.Container, key
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cc.sumName = fmt.Sprintf(summaryFile, t)
|
||||
cc.sumName = fmt.Sprintf(summaryFileNameTemplate, t)
|
||||
sum, err := cc.create(ctx, cc.sumName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -151,7 +151,7 @@ func openContainer(ctx context.Context, t containerType, c storage.Container, ke
|
||||
}
|
||||
|
||||
// Load the meta file
|
||||
cc.metaName = fmt.Sprintf(metaFile, t)
|
||||
cc.metaName = fmt.Sprintf(metaFileNameTemplate, t)
|
||||
mFile, err := cc.container.OpenFile(ctx, cc.metaName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -165,7 +165,7 @@ func (c *container) loadChecksums(ctx context.Context) error {
|
||||
const op = "bsr.(container).loadChecksums"
|
||||
|
||||
// Open and extract checksum signature
|
||||
checksumsSigFile, err := c.container.OpenFile(ctx, sigFile)
|
||||
checksumsSigFile, err := c.container.OpenFile(ctx, sigFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (c *container) loadChecksums(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Open and extract checksum file bytes
|
||||
checksumsFile, err := c.container.OpenFile(ctx, checksumFile)
|
||||
checksumsFile, err := c.container.OpenFile(ctx, checksumFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -266,27 +266,27 @@ func (c *container) loadKeys(ctx context.Context, keyUnwrapFn kms.KeyUnwrapCallb
|
||||
return nil, fmt.Errorf("%s: missing key unwrap function: %w", op, ErrInvalidParameter)
|
||||
}
|
||||
|
||||
bsrPubKey, err := c.loadKey(ctx, bsrPubKeyFile)
|
||||
bsrPubKey, err := c.loadKey(ctx, bsrPubKeyFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wrappedBsrKey, err := c.loadKey(ctx, wrappedBsrKeyFile)
|
||||
wrappedBsrKey, err := c.loadKey(ctx, wrappedBsrKeyFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wrappedPrivKey, err := c.loadKey(ctx, wrappedPrivKeyFile)
|
||||
wrappedPrivKey, err := c.loadKey(ctx, wrappedPrivKeyFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pubKeyBsrSignature, err := c.loadSignature(ctx, pubKeyBsrSignatureFile)
|
||||
pubKeyBsrSignature, err := c.loadSignature(ctx, pubKeyBsrSignatureFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pubKeySelfSignature, err := c.loadSignature(ctx, pubKeySelfSignatureFile)
|
||||
pubKeySelfSignature, err := c.loadSignature(ctx, pubKeySelfSignatureFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestSyncBsrKeys(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
f := &fstest.MemFS{}
|
||||
|
||||
fc, err := f.New(ctx, fmt.Sprintf(bsrFile, "session-id"))
|
||||
fc, err := f.New(ctx, fmt.Sprintf(bsrFileNameTemplate, "session-id"))
|
||||
require.NoError(t, err)
|
||||
|
||||
c, err := newContainer(ctx, sessionContainer, fc, keys)
|
||||
|
||||
Reference in new issue
Block a user