@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/launchrctl/launchr/internal/launchr"
1212 "github.com/launchrctl/launchr/pkg/driver"
13- "github.com/launchrctl/launchr/pkg/jsonschema"
1413)
1514
1615// Action is an action definition with a contextual id (name), working directory path
@@ -29,9 +28,8 @@ type Action struct {
2928 def * Definition // def is an action definition. Loaded by [Loader], may be nil when not initialized.
3029 defRaw * Definition // defRaw is a raw action definition. Loaded by [Loader], may be nil when not initialized.
3130
32- runtime Runtime // runtime is the [Runtime] to execute the action.
33- input * Input // input is a storage for arguments and options used in runtime.
34- processors map [string ]ValueProcessor // processors are [ValueProcessor] for manipulating input.
31+ runtime Runtime // runtime is the [Runtime] to execute the action.
32+ input * Input // input is a storage for arguments and options used in runtime.
3533}
3634
3735// New creates a new action.
@@ -110,11 +108,6 @@ func (a *Action) SetProcessors(list map[string]ValueProcessor) error {
110108 return nil
111109}
112110
113- // GetProcessors returns processors map.
114- func (a * Action ) GetProcessors () map [string ]ValueProcessor {
115- return a .processors
116- }
117-
118111// Reset unsets loaded action to force reload.
119112func (a * Action ) Reset () { a .def = nil }
120113
@@ -256,23 +249,8 @@ func (a *Action) ImageBuildInfo(image string) *driver.BuildDefinition {
256249
257250// SetInput saves arguments and options for later processing in run, templates, etc.
258251func (a * Action ) SetInput (input * Input ) (err error ) {
259- def := a .ActionDef ()
260-
261- // Process arguments.
262- err = a .processInputParams (def .Arguments , input .Args (), input .ArgsChanged (), input )
263- if err != nil {
264- return err
265- }
266-
267- // Process options.
268- err = a .processInputParams (def .Options , input .Opts (), input .OptsChanged (), input )
269- if err != nil {
270- return err
271- }
272-
273- // Validate the new input.
274- if err = a .ValidateInput (input ); err != nil {
275- return err
252+ if ! input .IsValidated () {
253+ return fmt .Errorf ("input is not validated" )
276254 }
277255
278256 a .input = input
@@ -281,60 +259,6 @@ func (a *Action) SetInput(input *Input) (err error) {
281259 return a .EnsureLoaded ()
282260}
283261
284- func (a * Action ) processInputParams (def ParametersList , inp InputParams , changed InputParams , input * Input ) error {
285- var err error
286- for _ , p := range def {
287- _ , isChanged := changed [p .Name ]
288- res := inp [p .Name ]
289- for i , procDef := range p .Process {
290- handler := p .processors [i ]
291- res , err = handler (res , ValueProcessorContext {
292- ValOrig : inp [p .Name ],
293- IsChanged : isChanged ,
294- Input : input ,
295- DefParam : p ,
296- Action : a ,
297- })
298- if err != nil {
299- return ErrValueProcessorHandler {
300- Processor : procDef .ID ,
301- Param : p .Name ,
302- Err : err ,
303- }
304- }
305- }
306- // Cast to []any slice because jsonschema validator supports only this type.
307- if p .Type == jsonschema .Array {
308- res = CastSliceTypedToAny (res )
309- }
310- // If the value was changed, we can safely override the value.
311- // If the value was not changed and processed is nil, do not add it.
312- if isChanged || res != nil {
313- inp [p .Name ] = res
314- }
315- }
316-
317- return nil
318- }
319-
320- // ValidateInput validates action input.
321- func (a * Action ) ValidateInput (input * Input ) error {
322- if input .IsValidated () {
323- return nil
324- }
325- argsDefLen := len (a .ActionDef ().Arguments )
326- argsPosLen := len (input .ArgsPositional ())
327- if argsPosLen > argsDefLen {
328- return fmt .Errorf ("accepts %d arg(s), received %d" , argsDefLen , argsPosLen )
329- }
330- err := validateJSONSchema (a , input )
331- if err != nil {
332- return err
333- }
334- input .SetValidated (true )
335- return nil
336- }
337-
338262// Execute runs action in the specified environment.
339263func (a * Action ) Execute (ctx context.Context ) error {
340264 // @todo maybe it shouldn't be here.
0 commit comments