(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils)
| 49 | var t = i18n.TPrefix("drive.script.") |
| 50 | |
| 51 | func newScriptDrive(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils) (types.IDrive, error) { |
| 52 | cfg, e := driveUtils.Data.Load("_script") |
| 53 | if e != nil { |
| 54 | return nil, e |
| 55 | } |
| 56 | |
| 57 | if cfg["_script"] == "" { |
| 58 | return nil, err.NewNotAllowedMessageError(i18n.T("drive.not_configured")) |
| 59 | } |
| 60 | |
| 61 | poolConfig, e := parsePoolConfig(config["pool"]) |
| 62 | if e != nil { |
| 63 | return nil, err.NewNotAllowedMessageError(i18n.T("drive.script.invalid_pool_config", e.Error())) |
| 64 | } |
| 65 | |
| 66 | vm, e := createVm(ctx, driveUtils.Config, cfg["_script"]) |
| 67 | if e != nil { |
| 68 | return nil, e |
| 69 | } |
| 70 | |
| 71 | d := &ScriptDrive{ |
| 72 | baseVM: vm, |
| 73 | data: make(map[string]json.RawMessage), |
| 74 | } |
| 75 | |
| 76 | vm.Set("setData", s.WrapVmCall(vm, d.setData)) |
| 77 | vm.Set("getData", s.WrapVmCall(vm, d.getData)) |
| 78 | |
| 79 | _, e = vm.Call(ctx, "__driveCreate", s.NewContext(vm, ctx), config, newScriptDriveUtils(driveUtils)) |
| 80 | |
| 81 | if e != nil { |
| 82 | _ = d.Dispose() |
| 83 | return nil, e |
| 84 | } |
| 85 | vm.Set("selfDrive", s.NewDrive(d)) |
| 86 | d.pool = s.NewVMPool(vm, poolConfig) |
| 87 | |
| 88 | return d, nil |
| 89 | } |
| 90 | |
| 91 | func initConfig(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils) (*drive_util.DriveInitConfig, error) { |
| 92 | selectedScript := config["script"] |
nothing calls this directly
no test coverage detected