Skip to content

Commit

Permalink
create shared get task name func
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Jun 7, 2024
1 parent 3fe8dc3 commit 815129e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_validator"
"github.com/kurtosis-tech/stacktrace"
"github.com/xtgo/uuid"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
"strings"
Expand Down Expand Up @@ -168,16 +167,11 @@ type RunPythonCapabilities struct {
}

func (builtin *RunPythonCapabilities) Interpret(locatorOfModuleInWhichThisBuiltinIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
if arguments.IsSet(TaskNameArgName) {
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", TaskNameArgName)
}
builtin.name = taskName.GoString()
} else {
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())
taskName, err := getTaskNameFromArgs(arguments)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to get task name from args.")
}
builtin.name = taskName

pythonScript, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, RunArgName)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ type RunShCapabilities struct {
}

func (builtin *RunShCapabilities) Interpret(locatorOfModuleInWhichThisBuiltinIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
taskName, err := getTaskNameFromArgs(arguments)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to get task name from args.")
}
builtin.name = taskName

if arguments.IsSet(TaskNameArgName) {
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_registry_spec"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/nix_build_spec"
"github.com/xtgo/uuid"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -313,3 +314,16 @@ func extractEnvVarsIfDefined(arguments *builtin_argument.ArgumentValuesSet) (*ma
}
return &envVars, nil
}

func getTaskNameFromArgs(arguments *builtin_argument.ArgumentValuesSet) (string, error) {
if arguments.IsSet(TaskNameArgName) {
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
return "", startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", TaskNameArgName)
}
return taskName.GoString(), nil
} else {
randomUuid := uuid.NewRandom()
return fmt.Sprintf("task-%v", randomUuid.String()), nil
}
}

0 comments on commit 815129e

Please sign in to comment.