@@ -15,24 +15,43 @@ import (
15
15
func Authorize (ctx engine.Context , input string ) (runner.AuthorizerResponse , error ) {
16
16
defer context .GetPauseFuncFromCtx (ctx .Ctx )()()
17
17
18
- if ! ctx . Tool . IsCommand ( ) {
18
+ if IsSafe ( ctx ) {
19
19
return runner.AuthorizerResponse {
20
20
Accept : true ,
21
21
}, nil
22
22
}
23
23
24
+ var result bool
25
+ err := survey .AskOne (& survey.Confirm {
26
+ Help : fmt .Sprintf ("The full source of the tools is as follows:\n \n %s" , ctx .Tool .String ()),
27
+ Default : true ,
28
+ Message : ConfirmMessage (ctx , input ),
29
+ }, & result )
30
+ if err != nil {
31
+ return runner.AuthorizerResponse {}, err
32
+ }
33
+
34
+ return runner.AuthorizerResponse {
35
+ Accept : result ,
36
+ Message : "Request denied, blocking execution." ,
37
+ }, nil
38
+ }
39
+
40
+ func IsSafe (ctx engine.Context ) bool {
41
+ if ! ctx .Tool .IsCommand () {
42
+ return true
43
+ }
44
+
45
+ _ , ok := builtin .SafeTools [strings .Split (ctx .Tool .Instructions , "\n " )[0 ][2 :]]
46
+ return ok
47
+ }
48
+
49
+ func ConfirmMessage (ctx engine.Context , input string ) string {
24
50
var (
25
- result bool
26
51
loc = ctx .Tool .Source .Location
27
52
interpreter = strings .Split (ctx .Tool .Instructions , "\n " )[0 ][2 :]
28
53
)
29
54
30
- if _ , ok := builtin .SafeTools [interpreter ]; ok {
31
- return runner.AuthorizerResponse {
32
- Accept : true ,
33
- }, nil
34
- }
35
-
36
55
if ctx .Tool .Source .Repo != nil {
37
56
loc = ctx .Tool .Source .Repo .Root
38
57
loc = strings .TrimPrefix (loc , "https://" )
@@ -44,21 +63,9 @@ func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, err
44
63
loc = "Builtin"
45
64
}
46
65
47
- err := survey .AskOne (& survey.Confirm {
48
- Help : fmt .Sprintf ("The full source of the tools is as follows:\n \n %s" , ctx .Tool .String ()),
49
- Default : true ,
50
- Message : fmt .Sprintf (`Description: %s
66
+ return fmt .Sprintf (`Description: %s
51
67
Interpreter: %s
52
68
Source: %s
53
69
Input: %s
54
- Allow the above tool to execute?` , ctx .Tool .Description , interpreter , loc , strings .TrimSpace (input )),
55
- }, & result )
56
- if err != nil {
57
- return runner.AuthorizerResponse {}, err
58
- }
59
-
60
- return runner.AuthorizerResponse {
61
- Accept : result ,
62
- Message : "Request denied, blocking execution." ,
63
- }, nil
70
+ Allow the above tool to execute?` , ctx .Tool .Description , interpreter , loc , strings .TrimSpace (input ))
64
71
}
0 commit comments