Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
corteza
corteza-server
Commits
80e7356f
Commit
80e7356f
authored
3 years ago
by
Denis Arh
Browse files
Options
Download
Email Patches
Plain Diff
Implement invoker and runner wf scope vars
parent
b89f9b37
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
159 additions
and
6 deletions
+159
-6
automation/service/service.go
automation/service/service.go
+2
-2
automation/service/workflow.go
automation/service/workflow.go
+20
-3
tests/workflows/invoker_and_runner_in_scope_test.go
tests/workflows/invoker_and_runner_in_scope_test.go
+84
-0
tests/workflows/main_test.go
tests/workflows/main_test.go
+12
-1
tests/workflows/testdata/invoker_and_runner_in_scope/users.yaml
...workflows/testdata/invoker_and_runner_in_scope/users.yaml
+8
-0
tests/workflows/testdata/invoker_and_runner_in_scope/workflow.yaml
...kflows/testdata/invoker_and_runner_in_scope/workflow.yaml
+33
-0
No files found.
automation/service/service.go
View file @
80e7356f
...
...
@@ -13,7 +13,7 @@ import (
"github.com/cortezaproject/corteza-server/pkg/options"
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/cortezaproject/corteza-server/store"
"github.com/cortezaproject/corteza-server/system/types"
sysTypes
"github.com/cortezaproject/corteza-server/system/types"
"go.uber.org/zap"
)
...
...
@@ -30,7 +30,7 @@ type (
}
userService
interface
{
FindByAny
(
ctx
context
.
Context
,
identifier
interface
{})
(
*
t
ypes
.
User
,
error
)
FindByAny
(
ctx
context
.
Context
,
identifier
interface
{})
(
*
sysT
ypes
.
User
,
error
)
}
)
...
...
This diff is collapsed.
Click to expand it.
automation/service/workflow.go
View file @
80e7356f
...
...
@@ -18,6 +18,8 @@ import (
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/cortezaproject/corteza-server/pkg/wfexec"
"github.com/cortezaproject/corteza-server/store"
sysAutoTypes
"github.com/cortezaproject/corteza-server/system/automation"
sysTypes
"github.com/cortezaproject/corteza-server/system/types"
"go.uber.org/zap"
)
...
...
@@ -493,6 +495,8 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl
wait
WaitFn
stacktrace
types
.
Stacktrace
runner
,
invoker
*
sysTypes
.
User
)
err
:=
func
()
(
err
error
)
{
...
...
@@ -590,11 +594,16 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl
ssp
.
ResourceType
=
""
}
// Finally, assign input values
ssp
.
Input
=
scope
.
Merge
(
p
.
Input
)
if
invokerId
:=
intAuth
.
GetIdentityFromContext
(
ctx
)
.
Identity
();
invokerId
>
0
{
if
invoker
,
err
=
DefaultUser
.
FindByAny
(
ctx
,
invokerId
);
err
!=
nil
{
return
}
runner
=
invoker
}
if
wf
.
RunAs
>
0
{
if
run
As
,
err
=
DefaultUser
.
FindByAny
(
ctx
,
wf
.
RunAs
);
err
!=
nil
{
if
run
ner
,
err
=
DefaultUser
.
FindByAny
(
ctx
,
wf
.
RunAs
);
err
!=
nil
{
return
}
}
...
...
@@ -604,6 +613,14 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl
runAs
=
intAuth
.
GetIdentityFromContext
(
ctx
)
}
// @todo find a better way to typify expression values
// so that we do not have to import automation types from the system component
_
=
scope
.
AssignFieldValue
(
"invoker"
,
expr
.
Must
(
sysAutoTypes
.
NewUser
(
invoker
)))
_
=
scope
.
AssignFieldValue
(
"runner"
,
expr
.
Must
(
sysAutoTypes
.
NewUser
(
runner
)))
// Finally, assign input values
ssp
.
Input
=
scope
.
Merge
(
p
.
Input
)
wait
,
err
=
svc
.
session
.
Start
(
g
,
runAs
,
ssp
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
tests/workflows/invoker_and_runner_in_scope_test.go
0 → 100644
View file @
80e7356f
package
workflows
import
(
"context"
"testing"
"github.com/cortezaproject/corteza-server/automation/types"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/rbac"
sysTypes
"github.com/cortezaproject/corteza-server/system/types"
"github.com/stretchr/testify/require"
)
func
Test_invoker_and_runner_in_scope
(
t
*
testing
.
T
)
{
var
(
ctx
=
superUser
(
context
.
Background
())
req
=
require
.
New
(
t
)
)
req
.
NoError
(
defStore
.
TruncateUsers
(
ctx
))
req
.
NoError
(
defStore
.
TruncateRoles
(
ctx
))
req
.
NoError
(
defStore
.
TruncateRoleMembers
(
ctx
))
req
.
NoError
(
defStore
.
TruncateRbacRules
(
ctx
))
loadNewScenario
(
ctx
,
t
)
// user that the workflow is configured to use for run-as
wfRunner
,
err
:=
defStore
.
LookupUserByHandle
(
ctx
,
"wf-runner"
)
req
.
NoError
(
err
)
// user invoking the workflow
wfInvoker
,
err
:=
defStore
.
LookupUserByHandle
(
ctx
,
"wf-invoker"
)
req
.
NoError
(
err
)
// invokers group with permissions to execute workflow
wfInvokers
,
err
:=
defStore
.
LookupRoleByHandle
(
ctx
,
"wf-invokers"
)
req
.
NoError
(
err
)
err
=
defStore
.
CreateRoleMember
(
ctx
,
&
sysTypes
.
RoleMember
{
UserID
:
wfInvoker
.
ID
,
RoleID
:
wfInvokers
.
ID
})
req
.
NoError
(
err
)
wfInvoker
.
SetRoles
([]
uint64
{
wfInvokers
.
ID
})
ctx
=
auth
.
SetIdentityToContext
(
ctx
,
wfInvoker
)
rbac
.
Global
()
.
Reload
(
ctx
)
t
.
Run
(
"invoker set in scope"
,
func
(
t
*
testing
.
T
)
{
var
(
req
=
require
.
New
(
t
)
aux
=
struct
{
Invoker
*
sysTypes
.
User
Runner
*
sysTypes
.
User
}{}
)
vars
,
_
:=
mustExecWorkflow
(
ctx
,
t
,
"invoker"
,
types
.
WorkflowExecParams
{})
req
.
NoError
(
vars
.
Decode
(
&
aux
))
// Expecting both, invoker & runner to be same as invoker
req
.
NotNil
(
aux
.
Runner
)
req
.
NotNil
(
aux
.
Invoker
)
req
.
Equal
(
aux
.
Runner
.
Handle
,
wfInvoker
.
Handle
)
req
.
Equal
(
aux
.
Invoker
.
Handle
,
wfInvoker
.
Handle
)
})
t
.
Run
(
"runner set in scope"
,
func
(
t
*
testing
.
T
)
{
var
(
req
=
require
.
New
(
t
)
aux
=
struct
{
Invoker
*
sysTypes
.
User
Runner
*
sysTypes
.
User
}{}
)
vars
,
_
:=
mustExecWorkflow
(
ctx
,
t
,
"runner"
,
types
.
WorkflowExecParams
{})
req
.
NoError
(
vars
.
Decode
(
&
aux
))
// Expecting runner and invoker to be different.
req
.
NotNil
(
aux
.
Runner
)
req
.
NotNil
(
aux
.
Invoker
)
req
.
Equal
(
aux
.
Runner
.
Handle
,
wfRunner
.
Handle
)
req
.
Equal
(
aux
.
Invoker
.
Handle
,
wfInvoker
.
Handle
)
})
}
This diff is collapsed.
Click to expand it.
tests/workflows/main_test.go
View file @
80e7356f
...
...
@@ -66,6 +66,13 @@ func loadScenario(ctx context.Context, t *testing.T) {
loadScenarioWithName
(
ctx
,
t
,
"S"
+
t
.
Name
()[
4
:
])
}
// 1st step in migration to workflow testdata w/o number prefix
//
// When all old scenarios are renamed, replace it with loadScenario.
func
loadNewScenario
(
ctx
context
.
Context
,
t
*
testing
.
T
)
{
loadScenarioWithName
(
ctx
,
t
,
t
.
Name
()[
5
:
])
}
func
loadScenarioWithName
(
ctx
context
.
Context
,
t
*
testing
.
T
,
scenario
string
)
{
var
(
err
error
...
...
@@ -130,7 +137,11 @@ func mustExecWorkflow(ctx context.Context, t *testing.T, name string, p autTypes
}
}
t
.
Fatalf
(
"could not exec %q: %v"
,
name
,
errors
.
Unwrap
(
err
))
if
unw
:=
errors
.
Unwrap
(
err
);
unw
!=
nil
{
err
=
unw
}
t
.
Fatalf
(
"could not exec %q: %v"
,
name
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
tests/workflows/testdata/invoker_and_runner_in_scope/users.yaml
0 → 100644
View file @
80e7356f
users
:
wf-runner
:
workflow-runner@cortezaproject.org
wf-invoker
:
workflow-invoker@cortezaproject.org
roles
:
wf-invokers
:
members
:
-
wf-invoker
This diff is collapsed.
Click to expand it.
tests/workflows/testdata/invoker_and_runner_in_scope/workflow.yaml
0 → 100644
View file @
80e7356f
workflows
:
invoker
:
enabled
:
true
trace
:
true
triggers
:
-
enabled
:
true
stepID
:
1
steps
:
-
stepID
:
1
kind
:
termination
paths
:
[]
allow
:
wf-invokers
:
-
execute
runner
:
enabled
:
true
trace
:
true
runAs
:
wf-runner
triggers
:
-
enabled
:
true
stepID
:
1
steps
:
-
stepID
:
1
kind
:
termination
paths
:
[]
allow
:
wf-invokers
:
-
execute
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment