Skip to content

Commit

Permalink
Merge branch 'master' into 6573-table-extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Isan-Rivkin committed Sep 13, 2023
2 parents 9892648 + cb5b558 commit ac5978f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions docs/howto/hooks/lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 37 additions & 0 deletions pkg/actions/lua/net/url/url.go
Original file line number Diff line number Diff line change
@@ -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,
})
}
2 changes: 2 additions & 0 deletions pkg/actions/lua/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit ac5978f

Please sign in to comment.