MCPcopy Index your code
hub / github.com/coder/coder / New

Function New

enterprise/dbcrypt/dbcrypt.go:36–54  ·  view source on GitHub ↗

New creates a database.Store wrapper that encrypts/decrypts values stored at rest in the database.

(ctx context.Context, db database.Store, ciphers ...Cipher)

Source from the content-addressed store, hash-verified

34// New creates a database.Store wrapper that encrypts/decrypts values
35// stored at rest in the database.
36func New(ctx context.Context, db database.Store, ciphers ...Cipher) (database.Store, error) {
37 cm := make(map[string]Cipher)
38 for _, c := range ciphers {
39 cm[c.HexDigest()] = c
40 }
41 dbc := &dbCrypt{
42 ciphers: cm,
43 Store: db,
44 }
45 if len(ciphers) > 0 {
46 dbc.primaryCipherDigest = ciphers[0].HexDigest()
47 }
48 // nolint: gocritic // This is allowed.
49 authCtx := dbauthz.AsSystemRestricted(ctx)
50 if err := dbc.ensureEncryptedWithRetry(authCtx); err != nil {
51 return nil, xerrors.Errorf("ensure encrypted database fields: %w", err)
52 }
53 return dbc, nil
54}
55
56type dbCrypt struct {
57 // primaryCipherDigest is the digest of the primary cipher used for encrypting data.

Callers 9

NewFunction · 0.92
TestServerDBCryptFunction · 0.92
RotateFunction · 0.70
DecryptFunction · 0.70
TestNewFunction · 0.70
setupFunction · 0.70
setupNoCiphersFunction · 0.70

Calls 4

AsSystemRestrictedFunction · 0.92
HexDigestMethod · 0.65
ErrorfMethod · 0.45

Tested by 6

TestServerDBCryptFunction · 0.74
TestNewFunction · 0.56
setupFunction · 0.56
setupNoCiphersFunction · 0.56