Skip to content

Commit

Permalink
feat(deps): add ada - whatwg-compliant and fast url parser (#13120)
Browse files Browse the repository at this point in the history
Adds libada and lua-resty-ada as a dependency.

This is needed for:
#12758

But it may be great for many other uses too.

The `lua-resty-ada` LuaJIT FFI bindings can be found here:
https://github.com/bungle/lua-resty-ada

Signed-off-by: Aapo Talvensaari <[email protected]>
  • Loading branch information
bungle committed Sep 17, 2024
1 parent 37ea820 commit f652b9e
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ OPENSSL=3.2.1
OPENSSL_SHA256=83c7329fe52c850677d75e5d0b0ca245309b97e8ecbcfdc1dfdc4ab9fac35b39
PCRE=10.44
PCRE_SHA256=86b9cb0aa3bcb7994faa88018292bc704cdbb708e785f7c74352ff6ea7d3175b
ADA=2.9.2
ADA_SHA256=b2cce630590b490d79ea4f4460ba77efd5fb29c5a87a4e8cb7ebc4859bc4b564
LIBEXPAT=2.6.2
LIBEXPAT_SHA256=d4cf38d26e21a56654ffe4acd9cd5481164619626802328506a2869afab29ab3

Expand Down Expand Up @@ -53,7 +55,7 @@ OPENSSL_FIPS_PROVIDER=3.0.9
OPENSSL_FIPS_PROVIDER_SHA256=eb1ab04781474360f77c318ab89d8c5a03abc38e63d65a603cabbf1b00a1dc90


KONGROCKS=v1.2.67
KONGROCKS=v1.2.69


# EE Debugging tools
Expand Down
5 changes: 3 additions & 2 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clib_deps = [
"@openssl",
"@libexpat",
"@snappy",
"@ada",
# EE only
"@jq",
"@libxml2",
Expand All @@ -25,8 +26,8 @@ clib_deps = [
kong_install(
name = "install-%s" % get_workspace_name(k),
src = k,
prefix = "kong/lib" if k in ("@passwdqc", "@snappy") else "kong",
strip_path = "snappy" if k == "@snappy" else "",
prefix = "kong/lib" if k in ("@passwdqc", "@snappy", "@ada") else "kong",
strip_path = "snappy" if k == "@snappy" else "ada" if k == "@ada" else "",
)
for k in clib_deps
]
Expand Down
18 changes: 18 additions & 0 deletions build/openresty/ada/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cc_library(
name = "ada-lib",
srcs = ["ada.cpp"],
hdrs = [
"ada.h",
"ada_c.h",
],
copts = [
"-std=c++17",
],
linkstatic = True,
)

cc_shared_library(
name = "ada",
visibility = ["//visibility:public"],
deps = [":ada-lib"],
)
19 changes: 19 additions & 0 deletions build/openresty/ada/ada_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""A module defining the third party dependency Ada"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@kong_bindings//:variables.bzl", "KONG_VAR")

def ada_repositories():
"""Defines the ada repository"""

version = KONG_VAR["ADA"]

maybe(
http_archive,
name = "ada",
sha256 = KONG_VAR["ADA_SHA256"],
url = "https://github.com/ada-url/ada/releases/download/v" + version + "/singleheader.zip",
type = "zip",
build_file = "//build/openresty/ada:BUILD.bazel",
)
2 changes: 2 additions & 0 deletions build/openresty/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ load("//build/openresty/msgpack_c:msgpack_c_repositories.bzl", "msgpack_c_reposi
load("//build/openresty/wasmx:wasmx_repositories.bzl", "wasmx_repositories")
load("//build/openresty/brotli:brotli_repositories.bzl", "brotli_repositories")
load("//build/openresty/snappy:snappy_repositories.bzl", "snappy_repositories")
load("//build/openresty/ada:ada_repositories.bzl", "ada_repositories")

# This is a dummy file to export the module's repository.
_NGINX_MODULE_DUMMY_FILE = """
Expand Down Expand Up @@ -41,6 +42,7 @@ def openresty_repositories():
wasmx_repositories()
brotli_repositories()
snappy_repositories()
ada_repositories()

openresty_version = KONG_VAR["OPENRESTY"]

Expand Down
4 changes: 4 additions & 0 deletions changelog/unreleased/kong/feat-add-ada.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
**Core**: Added Ada dependency - WHATWG-compliant and fast URL parser.
type: feature
scope: Core
1 change: 1 addition & 0 deletions kong-3.9.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies = {
"lua-resty-ljsonschema == 1.1.6-2",
"lua-resty-jq == 0.1.0",
"lua-resty-snappy == 1.0-1",
"lua-resty-ada == 1.1.0",
}
build = {
type = "builtin",
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/debian-11-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/debian-12-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el8-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el9-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/el9-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
- libc.so.6
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libm.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
- libc.so.6
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libm.so.6
- libgcc_s.so.1
- libc.so.6

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libstdc++.so.6
Expand Down
7 changes: 7 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
- Path : /usr/local/kong/lib/engines-3/padlock.so
Runpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libada.so
Needed :
- libstdc++.so.6
- libgcc_s.so.1
- libc.so.6
- ld-linux-aarch64.so.1

- Path : /usr/local/kong/lib/libcrypto.so.3
Needed :
- libc.so.6
Expand Down
4 changes: 4 additions & 0 deletions scripts/explain_manifest/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def common_suites(expect, libxcrypt_no_obsolete_api: bool = False, skip_libsimdj
.version_requirement.key("libssl.so.3").less_than("OPENSSL_3.3.0") \
.version_requirement.key("libcrypto.so.3").less_than("OPENSSL_3.3.0") \

ADA_VERSION = read_requirements()["ADA"]
expect("**/*.so", "ada version is less than %s" % ADA_VERSION) \
.version_requirement.key("libada.so").is_not().greater_than("ADA_%s" % ADA_VERSION) \

# wasm filters
for f in wasm_filters:
expect("/usr/local/kong/wasm/%s" % f, "wasm filter %s is installed under kong/wasm" % f).exists()
Expand Down
40 changes: 40 additions & 0 deletions spec/01-unit/31-ada-url_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- This software is copyright Kong Inc. and its licensors.
-- Use of the software is subject to the agreement between your organization
-- and Kong Inc. If there is no such agreement, use is governed by and
-- subject to the terms of the Kong Master Software License Agreement found
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]


local ada = require("resty.ada")


local assert = assert
local describe = describe
local it = it


local equal = assert.equal
local is_nil = assert.is_nil
local is_table = assert.is_table


local function is_err(msg, ok, err)
is_nil(ok)
equal(msg, err)
return ok, err
end


describe("Ada", function()
describe("URL", function()
describe(".parse", function()
it("rejects invalid url", function()
is_err("invalid url", ada.parse("<invalid>"))
end)
it("accepts valid url", function()
is_table(ada.parse("http://www.google.com/"))
end)
end)
end)
end)

0 comments on commit f652b9e

Please sign in to comment.