diff --git a/CHANGELOG.md b/CHANGELOG.md index 41d89a748cb..fd8a8bf3537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## UNRELEASED +:new: What's new: +- Restrict lakectl local to common prefixes only (#6510) +- Added URL parser to lua runtime (#6597) + # v0.109.0 :new: What's new: diff --git a/docs/howto/hooks/lua.md b/docs/howto/hooks/lua.md index 1f73de8a775..a457f085b62 100644 --- a/docs/howto/hooks/lua.md +++ b/docs/howto/hooks/lua.md @@ -420,6 +420,23 @@ The `value` string should be in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601 Returns a new 128-bit [RFC 4122 UUID](https://www.rfc-editor.org/rfc/rfc4122){: target="_blank" } in string representation. +### `net/url` + +Provides a `parse` function parse a URL string into parts, returns a table with the URL's host, path, scheme, query and fragment. + +```lua +> local url = require("net/url") +> url.parse("https://example.com/path?p1=a#section") +{ + ["host"] = "example.com" + ["path"] = "/path" + ["scheme"] = "https" + ["query"] = "p1=a" + ["fragment"] = "section" +} +``` + + ### `net/http` (optional) Provides a `request` function that performs an HTTP request. diff --git a/pkg/actions/lua/net/url/url.go b/pkg/actions/lua/net/url/url.go new file mode 100644 index 00000000000..ad8c4612fbd --- /dev/null +++ b/pkg/actions/lua/net/url/url.go @@ -0,0 +1,37 @@ +package url + +import ( + neturl "net/url" + + "github.com/Shopify/go-lua" + "github.com/treeverse/lakefs/pkg/actions/lua/util" +) + +func Open(l *lua.State) { + open := func(l *lua.State) int { + lua.NewLibrary(l, library) + return 1 + } + lua.Require(l, "net/url", open, false) + l.Pop(1) +} + +var library = []lua.RegistryFunction{ + {Name: "parse", Function: parse}, +} + +func parse(l *lua.State) int { + rawURL := lua.CheckString(l, 1) + u, err := neturl.Parse(rawURL) + if err != nil { + lua.Errorf(l, err.Error()) + panic("unreachable") + } + return util.DeepPush(l, map[string]string{ + "host": u.Host, + "path": u.Path, + "scheme": u.Scheme, + "query": u.RawQuery, + "fragment": u.Fragment, + }) +} diff --git a/pkg/actions/lua/open.go b/pkg/actions/lua/open.go index 2a40bd4ec1d..a573941209e 100644 --- a/pkg/actions/lua/open.go +++ b/pkg/actions/lua/open.go @@ -13,6 +13,7 @@ import ( "github.com/treeverse/lakefs/pkg/actions/lua/encoding/parquet" "github.com/treeverse/lakefs/pkg/actions/lua/encoding/yaml" "github.com/treeverse/lakefs/pkg/actions/lua/net/http" + "github.com/treeverse/lakefs/pkg/actions/lua/net/url" "github.com/treeverse/lakefs/pkg/actions/lua/path" "github.com/treeverse/lakefs/pkg/actions/lua/regexp" "github.com/treeverse/lakefs/pkg/actions/lua/storage/aws" @@ -41,6 +42,7 @@ func Open(l *lua.State, ctx context.Context, cfg OpenSafeConfig) { path.Open(l) aws.Open(l, ctx) gcloud.Open(l, ctx) + url.Open(l) if cfg.NetHTTPEnabled { http.Open(l) }