Skip to content

Commit

Permalink
did some clenaup
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Oct 9, 2023
1 parent 354adf0 commit 078d650
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewImportModule(
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[starlark.String],
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
return builtin_argument.RelativeOrRemoteAbsoluteLocator(value, packageId, ModuleFileArgName)
return builtin_argument.LocatorValidator(value, packageId, ModuleFileArgName)
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewReadFileHelper(
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[starlark.String],
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
return builtin_argument.RelativeOrRemoteAbsoluteLocator(value, packageId, SrcArgName)
return builtin_argument.LocatorValidator(value, packageId, SrcArgName)
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewUploadFiles(
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[starlark.String],
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
return builtin_argument.RelativeOrRemoteAbsoluteLocator(value, packageId, SrcArgName)
return builtin_argument.LocatorValidator(value, packageId, SrcArgName)
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package builtin_argument

import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
"github.com/sirupsen/logrus"
"go.starlark.net/starlark"
"reflect"
"regexp"
Expand Down Expand Up @@ -112,28 +111,15 @@ func DurationOrNone(value starlark.Value, attributeName string) *startosis_error
return nil
}

func RelativeOrRemoteAbsoluteLocator(locatorStarlarkValue starlark.Value, packageId string, argNameForLogging string) *startosis_errors.InterpretationError {
func LocatorValidator(locatorStarlarkValue starlark.Value, packageId string, argNameForLogging string) *startosis_errors.InterpretationError {

if err := NonEmptyString(locatorStarlarkValue, argNameForLogging); err != nil {
return err
}

locatorStarlarkStr, ok := locatorStarlarkValue.(starlark.String)
_, ok := locatorStarlarkValue.(starlark.String)
if !ok {
return startosis_errors.NewInterpretationError("Value for '%s' was expected to be a starlark.String but was '%s'", argNameForLogging, reflect.TypeOf(locatorStarlarkValue))
}
locatorStr := locatorStarlarkStr.GoString()

logrus.Infof("MONDAY this is the information i have %v %v %v", locatorStarlarkValue, packageId, argNameForLogging)

// if absolute and local return error
if isLocalAbsoluteLocator(locatorStr, packageId) {
return startosis_errors.NewInterpretationError("The locator '%s' set in attribute '%v' is not a 'local relative locator'. Local absolute locators are not allowed you should modified it to be a valid 'local relative locator'", locatorStarlarkStr, argNameForLogging)
}
return nil
}

func isLocalAbsoluteLocator(locatorStr string, packageId string) bool {
logrus.Debug(packageId, locatorStr)
return strings.HasPrefix(locatorStr, packageId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (provider *GitPackageContentProvider) GetAbsoluteLocatorForRelativeLocator(
) (string, *startosis_errors.InterpretationError) {
var absoluteLocator string

if isLocalAbsoluteLocator(maybeRelativeLocator, parentModuleId) {
return "", startosis_errors.NewInterpretationError("The locator '%s' set in attribute is not a 'local relative locator'. Local absolute locators are not allowed you should modified it to be a valid 'local relative locator'", maybeRelativeLocator)
}

// maybe it's not a relative url in which case we return the url
_, errorParsingUrl := parseGitURL(maybeRelativeLocator)
if errorParsingUrl == nil {
Expand Down Expand Up @@ -491,3 +495,7 @@ func getKurtosisYamlPathForFileUrlInternal(absPathToFile string, packagesDir str
}
return filePathToKurtosisYamlNotFound, nil
}

func isLocalAbsoluteLocator(locator string, parentPackageId string) bool {
return strings.HasPrefix(locator, parentPackageId)
}

0 comments on commit 078d650

Please sign in to comment.