Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 7f185a6

Browse files
committed
move actor ID fetching up
1 parent 64b9c06 commit 7f185a6

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

internal/database/executor_secret_access_logs.go

-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/keegancsmith/sqlf"
1010

11-
"github.com/sourcegraph/sourcegraph/internal/actor"
1211
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
1312
)
1413

@@ -110,11 +109,6 @@ func (s *executorSecretAccessLogStore) Transact(ctx context.Context) (ExecutorSe
110109
}
111110

112111
func (s *executorSecretAccessLogStore) Create(ctx context.Context, log *ExecutorSecretAccessLog) error {
113-
// Set the current actor as the creator.
114-
if log.UserID != nil && *log.UserID == 0 {
115-
log.UserID = &actor.FromContext(ctx).UID
116-
}
117-
118112
q := sqlf.Sprintf(
119113
executorSecretAccessLogCreateQueryFmtstr,
120114
log.ExecutorSecretID,

internal/database/executor_secret_access_logs_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ func TestExecutorSecretAccessLogs_Create(t *testing.T) {
4242
if log.CreatedAt.IsZero() {
4343
t.Fatal("created_at time not set")
4444
}
45-
46-
t.Run("uses actor user if user ID is not set", func(t *testing.T) {
47-
log := &ExecutorSecretAccessLog{
48-
ExecutorSecretID: secret.ID,
49-
}
50-
if err := store.Create(actor.WithActor(ctx, actor.FromUser(user.ID)), log); err != nil {
51-
t.Fatal(err)
52-
}
53-
if *log.UserID != user.ID {
54-
t.Fatal("wrong user_id set on access log record")
55-
}
56-
})
5745
})
5846
}
5947

internal/database/executor_secrets.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ type ExecutorSecretAccessLogCreator interface {
4747
// multiple times will not require another decryption call, but will create an
4848
// additional access log entry.
4949
func (e ExecutorSecret) Value(ctx context.Context, s ExecutorSecretAccessLogCreator) (string, error) {
50+
var userID *int32
51+
if uid := actor.FromContext(ctx).UID; uid != 0 {
52+
userID = &uid
53+
}
5054
if err := s.Create(ctx, &ExecutorSecretAccessLog{
51-
// user is set automatically from the context actor.
5255
ExecutorSecretID: e.ID,
56+
UserID: userID,
5357
}); err != nil {
5458
return "", errors.Wrap(err, "creating secret access log entry")
5559
}
@@ -488,7 +492,8 @@ RETURNING %s
488492
// ExecutorSecret.
489493
func scanExecutorSecret(secret *ExecutorSecret, key encryption.Key, s interface {
490494
Scan(...any) error
491-
}) error {
495+
},
496+
) error {
492497
var (
493498
value []byte
494499
keyID string

0 commit comments

Comments
 (0)