summaryrefslogtreecommitdiff
path: root/pkg/web
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/web')
-rw-r--r--pkg/web/cookie/new.go36
1 files changed, 15 insertions, 21 deletions
diff --git a/pkg/web/cookie/new.go b/pkg/web/cookie/new.go
index 08b796a..9aed2ab 100644
--- a/pkg/web/cookie/new.go
+++ b/pkg/web/cookie/new.go
@@ -8,40 +8,34 @@ import (
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
-type CookieOption pls.Option[*http.Cookie]
-
-func New(name, value string, options ...CookieOption) *http.Cookie {
- cookie := &http.Cookie{
- Name: name,
- Value: value, // TODO:: digitally sign the value
- Path: "/",
- HttpOnly: true,
- Secure: true,
- SameSite: http.SameSiteStrictMode,
- Domain: env.Fetch("HOST", "localhost"),
- }
-
- for _, option := range options {
- cookie = option(cookie)
- }
-
- return cookie
+func New(name, value string, options ...pls.Option[*http.Cookie]) *http.Cookie {
+ options = append(options, With(func(c *http.Cookie) {
+ c.Name = name
+ c.Value = value // TODO:: digitally sign the value
+ c.Path = "/"
+ c.HttpOnly = true
+ c.Secure = true
+ c.SameSite = http.SameSiteStrictMode
+ c.Domain = env.Fetch("HOST", "localhost")
+ }))
+
+ return pls.New[*http.Cookie](options...)
}
-func With(with func(*http.Cookie)) CookieOption {
+func With(with func(*http.Cookie)) pls.Option[*http.Cookie] {
return func(c *http.Cookie) *http.Cookie {
with(c)
return c
}
}
-func WithSameSite(value http.SameSite) CookieOption {
+func WithSameSite(value http.SameSite) pls.Option[*http.Cookie] {
return With(func(c *http.Cookie) {
c.SameSite = value
})
}
-func WithExpiration(expires time.Time) CookieOption {
+func WithExpiration(expires time.Time) pls.Option[*http.Cookie] {
return With(func(c *http.Cookie) {
c.Expires = expires
c.MaxAge = int(time.Until(expires).Seconds())