diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index 525dbc1f55..cd29c1496e 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -16,9 +16,9 @@ import ( "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/tests" "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer" "github.com/kubeshop/testkube/cmd/testworkflow-init/instructions" - intcommon "github.com/kubeshop/testkube/internal/common" apiclientv1 "github.com/kubeshop/testkube/pkg/api/v1/client" "github.com/kubeshop/testkube/pkg/api/v1/testkube" + tclcmd "github.com/kubeshop/testkube/pkg/tcl/testworkflowstcl/cmd" "github.com/kubeshop/testkube/pkg/telemetry" "github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants" "github.com/kubeshop/testkube/pkg/ui" @@ -76,18 +76,10 @@ func NewRunTestWorkflowCmd() *cobra.Command { Config: config, DisableWebhooks: disableWebhooks, Tags: tags, - RunningContext: &testkube.TestWorkflowRunningContext{ - Interface_: &testkube.TestWorkflowRunningContextInterface{ - Name: runContext, - Type_: intcommon.Ptr(interfaceType), - }, - Actor: &testkube.TestWorkflowRunningContextActor{ - Type_: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActorType), - Username: "", - Email: "", - }, - }, - }) + // Pro edition only (tcl protected code) + RunningContext: tclcmd.GetRunningContext(runContext, "", "", interfaceType), + }, + ) if err != nil { // User friendly Open Source operation error errMessage := err.Error() diff --git a/internal/app/api/v1/testworkflows.go b/internal/app/api/v1/testworkflows.go index 14e86ba741..96475b9bfa 100644 --- a/internal/app/api/v1/testworkflows.go +++ b/internal/app/api/v1/testworkflows.go @@ -16,6 +16,7 @@ import ( "github.com/kubeshop/testkube/pkg/api/v1/testkube" "github.com/kubeshop/testkube/pkg/mapper/testworkflows" "github.com/kubeshop/testkube/pkg/scheduler" + "github.com/kubeshop/testkube/pkg/tcl/testworkflowstcl/api" "github.com/kubeshop/testkube/pkg/testworkflows/testworkflowresolver" "github.com/kubeshop/testkube/pkg/workerpool" ) @@ -374,17 +375,8 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler { request.TestWorkflowExecutionName = strings.Clone(c.Query("testWorkflowExecutionName")) if request.RunningContext == nil { - request.RunningContext = &testkube.TestWorkflowRunningContext{ - Interface_: &testkube.TestWorkflowRunningContextInterface{ - Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType), - }, - Actor: &testkube.TestWorkflowRunningContextActor{ - Name: "", - Username: "", - Email: "", - Type_: common.Ptr(testkube.PROGRAM_TestWorkflowRunningContextActorType), - }, - } + // Pro edition only (tcl protected code) + request.RunningContext = api.GetRunningContext("", "", "") } concurrencyLevel := scheduler.DefaultConcurrencyLevel workerpoolService := workerpool.New[testworkflowsv1.TestWorkflow, testkube.TestWorkflowExecutionRequest, diff --git a/pkg/tcl/testworkflowstcl/api/api.go b/pkg/tcl/testworkflowstcl/api/api.go new file mode 100644 index 0000000000..eb5d1e55c4 --- /dev/null +++ b/pkg/tcl/testworkflowstcl/api/api.go @@ -0,0 +1,27 @@ +// Copyright 2024 Testkube. +// +// Licensed as a Testkube Pro file under the Testkube Community +// License (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt +package api + +import ( + "github.com/kubeshop/testkube/internal/common" + "github.com/kubeshop/testkube/pkg/api/v1/testkube" +) + +func GetRunningContext(name, username, email string) *testkube.TestWorkflowRunningContext { + return &testkube.TestWorkflowRunningContext{ + Interface_: &testkube.TestWorkflowRunningContextInterface{ + Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType), + }, + Actor: &testkube.TestWorkflowRunningContextActor{ + Name: name, + Username: username, + Email: email, + Type_: common.Ptr(testkube.PROGRAM_TestWorkflowRunningContextActorType), + }, + } +} diff --git a/pkg/tcl/testworkflowstcl/cmd/cmd.go b/pkg/tcl/testworkflowstcl/cmd/cmd.go new file mode 100644 index 0000000000..ca610a8b77 --- /dev/null +++ b/pkg/tcl/testworkflowstcl/cmd/cmd.go @@ -0,0 +1,28 @@ +// Copyright 2024 Testkube. +// +// Licensed as a Testkube Pro file under the Testkube Community +// License (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt + +package cmd + +import ( + "github.com/kubeshop/testkube/internal/common" + "github.com/kubeshop/testkube/pkg/api/v1/testkube" +) + +func GetRunningContext(runContext, username, email string, interfaceType testkube.TestWorkflowRunningContextInterfaceType) *testkube.TestWorkflowRunningContext { + return &testkube.TestWorkflowRunningContext{ + Interface_: &testkube.TestWorkflowRunningContextInterface{ + Name: runContext, + Type_: common.Ptr(interfaceType), + }, + Actor: &testkube.TestWorkflowRunningContextActor{ + Type_: common.Ptr(testkube.USER_TestWorkflowRunningContextActorType), + Username: username, + Email: email, + }, + } +} diff --git a/pkg/tcl/testworkflowstcl/mapper/cdevents.go b/pkg/tcl/testworkflowstcl/mapper/cdevents.go index 7376ca3fb7..08746d259f 100644 --- a/pkg/tcl/testworkflowstcl/mapper/cdevents.go +++ b/pkg/tcl/testworkflowstcl/mapper/cdevents.go @@ -1,3 +1,11 @@ +// Copyright 2024 Testkube. +// +// Licensed as a Testkube Pro file under the Testkube Community +// License (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt + package mapper import "github.com/kubeshop/testkube/pkg/api/v1/testkube" diff --git a/pkg/tcl/testworkflowstcl/triggers/executor.go b/pkg/tcl/testworkflowstcl/triggers/executor.go index 6710ea2d95..9664d9671e 100644 --- a/pkg/tcl/testworkflowstcl/triggers/executor.go +++ b/pkg/tcl/testworkflowstcl/triggers/executor.go @@ -1,3 +1,11 @@ +// Copyright 2024 Testkube. +// +// Licensed as a Testkube Pro file under the Testkube Community +// License (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt + package triggers import (