Skip to content

Commit 4f56129

Browse files
committed
Fix: Update
1 parent 37c4a89 commit 4f56129

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

dbos/workflow.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,27 @@ func withWorkflowName(name string) WorkflowOption {
549549
}
550550
}
551551

552+
// Sets the authenticated user for the workflow
553+
func WithAutheticatedUser(user string) WorkflowOption {
554+
return func(p *workflowOptions) {
555+
p.authenticated_user = user
556+
}
557+
}
558+
559+
// Sets the assumed role for the workflow
560+
func WithAssumedRole(role string) WorkflowOption {
561+
return func(p *workflowOptions) {
562+
p.assumed_role = role
563+
}
564+
}
565+
566+
// Sets the authenticated role for the workflow
567+
func WithAuthenticatedRoles(roles []string) WorkflowOption {
568+
return func(p *workflowOptions) {
569+
p.authenticated_roles = roles
570+
}
571+
}
572+
552573
// RunWorkflow executes a workflow function with type safety and durability guarantees.
553574
// The workflow can be executed immediately or enqueued for later execution based on options.
554575
// Returns a typed handle that can be used to wait for completion and retrieve results.

dbos/workflows_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,3 +4131,31 @@ func TestSpecialSteps(t *testing.T) {
41314131
require.Equal(t, "success", result, "workflow should return success")
41324132
})
41334133
}
4134+
func TestWorkflowIdentity(t *testing.T) {
4135+
dbosCtx := setupDBOS(t, true, true)
4136+
handle, err := RunWorkflow(
4137+
dbosCtx,
4138+
simpleWorkflow,
4139+
"test",
4140+
WithWorkflowID("my-workflow-id"),
4141+
WithAutheticatedUser("user123"),
4142+
WithAssumedRole("admin"),
4143+
WithAuthenticatedRoles([]string{"reader", "writer"}))
4144+
require.NoError(t, err, "failed to start workflow")
4145+
4146+
// Retrieve the workflow's status.
4147+
status, err := handle.GetStatus()
4148+
require.NoError(t, err)
4149+
4150+
t.Run("CheckAuthenticatedUser", func(t *testing.T) {
4151+
assert.Equal(t, "user123", status.AuthenticatedUser)
4152+
})
4153+
4154+
t.Run("CheckAssumedRole", func(t *testing.T) {
4155+
assert.Equal(t, "admin", status.AssumedRole)
4156+
})
4157+
4158+
t.Run("CheckAuthenticatedRoles", func(t *testing.T) {
4159+
assert.Equal(t, []string{"reader", "writer"}, status.AuthenticatedRoles)
4160+
})
4161+
}

0 commit comments

Comments
 (0)