-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(spyglass/lenses) allow configuration sandbox permissions #296
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,11 @@ const ( | |
var defaultHighlightLineLengthMax = 10000 // Default maximum length of a line worth highlighting | ||
|
||
type config struct { | ||
HighlightRegexes []string `json:"highlight_regexes"` | ||
HideRawLog bool `json:"hide_raw_log,omitempty"` | ||
Highlighter *highlightConfig `json:"highlighter,omitempty"` | ||
HighlightLengthMax *int `json:"highlight_line_length_max,omitempty"` | ||
HighlightRegexes []string `json:"highlight_regexes"` | ||
HideRawLog bool `json:"hide_raw_log,omitempty"` | ||
Highlighter *highlightConfig `json:"highlighter,omitempty"` | ||
HighlightLengthMax *int `json:"highlight_line_length_max,omitempty"` | ||
IframeSandboxPermissions []string `json:"iframe_sandbox_permissions,omitempty"` | ||
} | ||
|
||
type highlightConfig struct { | ||
|
@@ -68,10 +69,11 @@ type highlightConfig struct { | |
} | ||
|
||
type parsedConfig struct { | ||
highlightRegex *regexp.Regexp | ||
showRawLog bool | ||
highlighter *highlightConfig | ||
highlightLengthMax int | ||
highlightRegex *regexp.Regexp | ||
showRawLog bool | ||
highlighter *highlightConfig | ||
highlightLengthMax int | ||
IframeSandboxPermissions string | ||
} | ||
|
||
var _ api.Lens = Lens{} | ||
|
@@ -97,6 +99,17 @@ func (lens Lens) Header(artifacts []api.Artifact, resourceDir string, config jso | |
// It is only used if highlight_regexes is not specified in the lens config. | ||
var defaultErrRE = regexp.MustCompile(`timed out|ERROR:|(FAIL|Failure \[)\b|panic\b|^E\d{4} \d\d:\d\d:\d\d\.\d\d\d]`) | ||
|
||
// defaultSandboxPermissions is the default value for iframe_sandbox_permissions lense config if it is not specified. | ||
var defaultSandboxPermissions = strings.Join( | ||
[]string{ | ||
"allow-scripts", | ||
"allow-top-navigation", | ||
"allow-popups", | ||
"allow-same-origin", | ||
}, | ||
" ", | ||
) | ||
Comment on lines
+103
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is defaultSandboxPermissions for the parsedConfig, tho I personally like to work with arrays instead of strings with Not sure if you prefer this or the Please let me know, I'll update if you want to change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion is to do another PR after this to adjust the defaults to not combine |
||
|
||
func init() { | ||
lenses.RegisterLens(Lens{}) | ||
} | ||
|
@@ -170,8 +183,9 @@ type buildLogsView struct { | |
|
||
func getConfig(rawConfig json.RawMessage) parsedConfig { | ||
conf := parsedConfig{ | ||
highlightRegex: defaultErrRE, | ||
showRawLog: true, | ||
highlightRegex: defaultErrRE, | ||
showRawLog: true, | ||
IframeSandboxPermissions: defaultSandboxPermissions, | ||
} | ||
|
||
// No config at all is fine. | ||
|
@@ -189,6 +203,13 @@ func getConfig(rawConfig json.RawMessage) parsedConfig { | |
conf.highlighter = nil | ||
} | ||
conf.showRawLog = !c.HideRawLog | ||
|
||
if c.IframeSandboxPermissions == nil { | ||
conf.IframeSandboxPermissions = defaultSandboxPermissions | ||
} else { | ||
conf.IframeSandboxPermissions = strings.Join(c.IframeSandboxPermissions, " ") | ||
} | ||
|
||
if len(c.HighlightRegexes) == 0 { | ||
return conf | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this as it looked like a sane idea to do if this is supposed to demostrate a full configuration file example.