Skip to content
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

chore: bump dependencies #4017

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/cve-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.grype-scan.outputs.sarif }}
- name: Kubescape scanner
uses: kubescape/github-action@main
id: kubescape
with:
image: oryd/kratos:${{ env.SHA_SHORT }}
verbose: true
format: pretty-printer
# can't whitelist CVE yet: https://github.com/kubescape/kubescape/pull/1568
severityThreshold: critical
# - name: Kubescape scanner
# uses: kubescape/github-action@main
# id: kubescape
# with:
# verbose: true
# format: pretty-printer
# # can't whitelist CVE yet: https://github.com/kubescape/kubescape/pull/1568
# image: oryd/kratos:${{ env.SHA_SHORT }}
# severityThreshold: critical
- name: Trivy Scanner
uses: aquasecurity/trivy-action@master
if: ${{ always() }}
Expand Down Expand Up @@ -89,5 +89,5 @@ jobs:
shell: bash
run: |
echo "::group::Hadolint Scan Details"
echo "${HADOLINT_RESULTS}" | jq '.'
echo "${HADOLINT_RESULTS}" | jq '.'
echo "::endgroup::"
27 changes: 13 additions & 14 deletions courier/template/load_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"github.com/ory/x/fetcher"

"github.com/Masterminds/sprig/v3"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/pkg/errors"
)

//go:embed courier/builtin/templates/*
var templates embed.FS

var Cache, _ = lru.New(16)
var Cache, _ = lru.New[string, Template](16)

type Template interface {
Execute(wr io.Writer, data interface{}) error
Expand All @@ -36,7 +36,7 @@

func loadBuiltInTemplate(filesystem fs.FS, name string, html bool) (Template, error) {
if t, found := Cache.Get(name); found {
return t.(Template), nil
return t, nil

Check warning on line 39 in courier/template/load_template.go

View check run for this annotation

Codecov / codecov/patch

courier/template/load_template.go#L39

Added line #L39 was not covered by tests
}

file, err := filesystem.Open(name)
Expand Down Expand Up @@ -77,18 +77,16 @@
}

func loadRemoteTemplate(ctx context.Context, d templateDependencies, url string, html bool) (t Template, err error) {
var b []byte
if t, found := Cache.Get(url); found {
b = t.([]byte)
} else {
f := fetcher.NewFetcher(fetcher.WithClient(d.HTTPClient(ctx)))
bb, err := f.FetchContext(ctx, url)
if err != nil {
return nil, errors.WithStack(err)
}
b = bb.Bytes()
_ = Cache.Add(url, b)
return t, nil
}

f := fetcher.NewFetcher(fetcher.WithClient(d.HTTPClient(ctx)))
bb, err := f.FetchContext(ctx, url)
if err != nil {
return nil, errors.WithStack(err)
}
b := bb.Bytes()

if html {
t, err = htemplate.New(url).Funcs(sprig.HermeticHtmlFuncMap()).Parse(string(b))
Expand All @@ -101,13 +99,14 @@
return nil, errors.WithStack(err)
}
}
Cache.Add(url, t)

return t, nil
}

func loadTemplate(filesystem fs.FS, name, pattern string, html bool) (Template, error) {
if t, found := Cache.Get(name); found {
return t.(Template), nil
return t, nil
}

matches, _ := fs.Glob(filesystem, name)
Expand Down
14 changes: 7 additions & 7 deletions courier/template/load_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ory/kratos/internal"
"github.com/ory/x/fetcher"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -51,20 +51,20 @@ func TestLoadTextTemplate(t *testing.T) {
})

t.Run("method=fallback to bundled", func(t *testing.T) {
template.Cache, _ = lru.New(16) // prevent Cache hit
template.Cache, _ = lru.New[string, template.Template](16) // prevent Cache hit
actual := executeTextTemplate(t, "some/inexistent/dir", "test_stub/email.body.gotmpl", "", nil)
assert.Contains(t, actual, "stub email")
})

t.Run("method=with Sprig functions", func(t *testing.T) {
template.Cache, _ = lru.New(16) // prevent Cache hit
m := map[string]interface{}{"input": "hello world"} // create a simple model
template.Cache, _ = lru.New[string, template.Template](16) // prevent Cache hit
m := map[string]interface{}{"input": "hello world"} // create a simple model
actual := executeTextTemplate(t, "courier/builtin/templates/test_stub", "email.body.sprig.gotmpl", "", m)
assert.Contains(t, actual, "HelloWorld,HELLOWORLD")
})

t.Run("method=sprig should not support non-hermetic", func(t *testing.T) {
template.Cache, _ = lru.New(16)
template.Cache, _ = lru.New[string, template.Template](16)
ctx := context.Background()
_, reg := internal.NewFastRegistryWithMocks(t)

Expand All @@ -80,8 +80,8 @@ func TestLoadTextTemplate(t *testing.T) {
})

t.Run("method=html with nested templates", func(t *testing.T) {
template.Cache, _ = lru.New(16) // prevent Cache hit
m := map[string]interface{}{"lang": "en_US"} // create a simple model
template.Cache, _ = lru.New[string, template.Template](16) // prevent Cache hit
m := map[string]interface{}{"lang": "en_US"} // create a simple model
actual := executeHTMLTemplate(t, "courier/builtin/templates/test_stub", "email.body.html.gotmpl", "email.body.html*", m)
assert.Contains(t, actual, "lang=en_US")
})
Expand Down
Loading
Loading