Skip to content

Commit

Permalink
Merge pull request kubernetes#25483 from fejta/cookie
Browse files Browse the repository at this point in the history
Consider cookie-auth links savable.
  • Loading branch information
k8s-ci-robot authored Mar 3, 2022
2 parents 0fe79cf + 3ea4b8d commit a0cbe48
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions prow/spyglass/lenses/buildlog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//prow/config:go_default_library",
"//prow/io:go_default_library",
"//prow/spyglass/api:go_default_library",
"//prow/spyglass/lenses:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
7 changes: 6 additions & 1 deletion prow/spyglass/lenses/buildlog/lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/sirupsen/logrus"

prowconfig "k8s.io/test-infra/prow/config"
pkgio "k8s.io/test-infra/prow/io"
"k8s.io/test-infra/prow/spyglass/api"
"k8s.io/test-infra/prow/spyglass/lenses"
)
Expand Down Expand Up @@ -217,13 +218,17 @@ func (lens Lens) Body(artifacts []api.Artifact, resourceDir string, data string,
}
av.LineGroups = groupLines(&artifact, start, end, highlightLines(lines, 0, &artifact, conf.highlightRegex)...)
av.ViewAll = true
av.CanSave = strings.Contains(a.CanonicalLink(), "storage.googleapis.com/")
av.CanSave = canSave(a.CanonicalLink())
buildLogsView.LogViews = append(buildLogsView.LogViews, av)
}

return executeTemplate(resourceDir, "body", buildLogsView)
}

func canSave(link string) bool {
return strings.Contains(link, pkgio.GSAnonHost) || strings.Contains(link, pkgio.GSCookieHost)
}

const failedUnmarshal = "Failed to unmarshal request"
const missingArtifact = "No artifact named %s"
const focusStart = "focus-start"
Expand Down
64 changes: 64 additions & 0 deletions prow/spyglass/lenses/buildlog/lens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func TestGroupLines(t *testing.T) {
func pstr(s string) *string { return &s }

func TestBody(t *testing.T) {
const (
anonLink = "https://storage.googleapis.com/bucket/object/build-log.txt"
cookieLink = "https://storage.cloud.google.com/bucket/object/build-log.txt"
)
render := func(views ...LogArtifactView) string {
return executeTemplate(".", "body", buildLogsView{LogViews: views})
}
Expand Down Expand Up @@ -316,6 +320,66 @@ func TestBody(t *testing.T) {
},
})),
},
{
name: "cookie savable",
artifact: &fake.Artifact{
Path: "foo",
Content: []byte("hello"),
Link: pstr(cookieLink),
},
want: render(func() LogArtifactView {
lav := view("foo", cookieLink, []LineGroup{
{
Start: 1,
End: 1,
ArtifactName: pstr("foo"),
LogLines: []LogLine{
{
ArtifactName: pstr("foo"),
Number: 1,
SubLines: []SubLine{
{
Text: "hello",
},
},
},
},
},
})
lav.CanSave = true
return lav
}()),
},
{
name: "savable",
artifact: &fake.Artifact{
Path: "foo",
Content: []byte("hello"),
Link: pstr(anonLink),
},
want: render(func() LogArtifactView {
lav := view("foo", anonLink, []LineGroup{
{
Start: 1,
End: 1,
ArtifactName: pstr("foo"),
LogLines: []LogLine{
{
ArtifactName: pstr("foo"),
Number: 1,
SubLines: []SubLine{
{
Text: "hello",
},
},
},
},
},
})
lav.CanSave = true
return lav
}()),
},
{
name: "focus",
artifact: &fake.Artifact{
Expand Down
6 changes: 5 additions & 1 deletion prow/spyglass/lenses/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Artifact struct {
Path string
Content []byte
Meta map[string]string
Link *string
}

func (fa *Artifact) JobPath() string {
Expand All @@ -48,7 +49,10 @@ func (fa *Artifact) UpdateMetadata(now map[string]string) error {
const NotFound = "linknotfound.io/404"

func (fa *Artifact) CanonicalLink() string {
return "linknotfound.io/404"
if fa.Link == nil {
return NotFound
}
return *fa.Link
}

func (fa *Artifact) ReadAt(b []byte, off int64) (int, error) {
Expand Down

0 comments on commit a0cbe48

Please sign in to comment.