Skip to content

Commit 6e98be9

Browse files
authored
Merge pull request #1 from stackql/feature/new-functions
aws policy equal function
2 parents 703315e + be02a1d commit 6e98be9

File tree

7 files changed

+3856
-3
lines changed

7 files changed

+3856
-3
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
include:
21-
- os: ubuntu-20.04
21+
- os: ubuntu-latest
2222
- os: windows-latest
2323
- os: macos-latest
2424
arch: amd64
@@ -29,7 +29,7 @@ jobs:
2929
- uses: actions/checkout@v4
3030

3131
- name: Install dependencies on Linux
32-
if: matrix.os == 'ubuntu-20.04'
32+
if: matrix.os == 'ubuntu-latest'
3333
run: sudo apt-get install -y sqlite3 gcc unzip
3434

3535
- name: Install dependencies on Windows
@@ -53,7 +53,7 @@ jobs:
5353
make download-sqlite
5454
5555
- name: Compile and test on Linux
56-
if: matrix.os == 'ubuntu-20.04'
56+
if: matrix.os == 'ubuntu-latest'
5757
run: |
5858
make compile-linux
5959
make test-all
@@ -67,10 +67,17 @@ jobs:
6767
Get-Content test/json_equal.sql | sqlite3.exe | Out-File -FilePath test.log
6868
if (Select-String -Path test.log -Pattern '^[0-9_]+.[^1]$') { throw 'Test failed' }
6969
Write-Host "json_equal tests completed successfully."
70+
71+
Write-Host "Running aws_policy_equal tests..."
72+
Get-Content test/aws_policy_equal.sql | sqlite3.exe | Out-File -FilePath test.log
73+
if (Select-String -Path test.log -Pattern '^[0-9_]+.[^1]$') { throw 'Test failed' }
74+
Write-Host "aws_policy_equal tests completed successfully."
75+
7076
Write-Host "Running regexp tests..."
7177
Get-Content test/regexp.sql | sqlite3.exe | Out-File -FilePath test.log
7278
if (Select-String -Path test.log -Pattern '^[0-9_]+.[^1]$') { throw 'Test failed' }
7379
Write-Host "regexp tests completed successfully."
80+
7481
Write-Host "Running split_part tests..."
7582
Get-Content test/split_part.sql | sqlite3.exe | Out-File -FilePath test.log
7683
if (Select-String -Path test.log -Pattern '^[0-9_]+.[^1]$') { throw 'Test failed' }

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,35 @@ compile-linux:
2424
gcc -O2 -fPIC -shared -I$(SRC_DIR) $(SRC_DIR)/json_equal/*.c -o $(DIST_DIR)/json_equal.so -lsqlite3
2525
gcc -O2 -fPIC -shared -I$(SRC_DIR) $(SRC_DIR)/regexp/*.c -o $(DIST_DIR)/regexp.so -lsqlite3
2626
gcc -O2 -fPIC -shared -I$(SRC_DIR) $(SRC_DIR)/split_part/*.c -o $(DIST_DIR)/split_part.so -lsqlite3
27+
gcc -O2 -fPIC -shared -I$(SRC_DIR) $(SRC_DIR)/aws_policy_equal/*.c -o $(DIST_DIR)/aws_policy_equal.so -lsqlite3
2728

2829
compile-windows:
2930
gcc -O2 -shared -Isrc src/json_equal/*.c -o dist/json_equal.dll
3031
gcc -O2 -shared -Isrc src/regexp/*.c -o dist/regexp.dll
3132
gcc -O2 -shared -Isrc src/split_part/*.c -o dist/split_part.dll
33+
gcc -O2 -shared -Isrc src/aws_policy_equal/*.c -o dist/aws_policy_equal.dll
3234

3335
compile-macos-x86:
3436
gcc -O2 -fPIC -dynamiclib -Isrc -target x86_64-apple-macos12 src/json_equal/*.c -o dist/json_equal_x86.dylib
3537
gcc -O2 -fPIC -dynamiclib -Isrc -target x86_64-apple-macos12 src/regexp/*.c -o dist/regexp_x86.dylib
3638
gcc -O2 -fPIC -dynamiclib -Isrc -target x86_64-apple-macos12 src/split_part/*.c -o dist/split_part_x86.dylib
39+
gcc -O2 -fPIC -dynamiclib -Isrc -target x86_64-apple-macos12 src/aws_policy_equal/*.c -o dist/aws_policy_equal_x86.dylib
3740

3841
compile-macos-arm64:
3942
gcc -O2 -fPIC -dynamiclib -Isrc -target arm64-apple-macos12 src/json_equal/*.c -o dist/json_equal_arm64.dylib
4043
gcc -O2 -fPIC -dynamiclib -Isrc -target arm64-apple-macos12 src/regexp/*.c -o dist/regexp_arm64.dylib
4144
gcc -O2 -fPIC -dynamiclib -Isrc -target arm64-apple-macos12 src/split_part/*.c -o dist/split_part_arm64.dylib
45+
gcc -O2 -fPIC -dynamiclib -Isrc -target arm64-apple-macos12 src/aws_policy_equal/*.c -o dist/aws_policy_equal_arm64.dylib
4246

4347
compile-macos-universal: compile-macos-x86 compile-macos-arm64
4448
lipo -create -output dist/json_equal.dylib dist/json_equal_x86.dylib dist/json_equal_arm64.dylib
4549
lipo -create -output dist/regexp.dylib dist/regexp_x86.dylib dist/regexp_arm64.dylib
4650
lipo -create -output dist/split_part.dylib dist/split_part_x86.dylib dist/split_part_arm64.dylib
51+
lipo -create -output dist/aws_policy_equal.dylib dist/aws_policy_equal_x86.dylib dist/aws_policy_equal_arm64.dylib
4752
rm -f dist/json_equal_x86.dylib dist/json_equal_arm64.dylib
4853
rm -f dist/regexp_x86.dylib dist/regexp_arm64.dylib
4954
rm -f dist/split_part_x86.dylib dist/split_part_arm64.dylib
55+
rm -f dist/aws_policy_equal_x86.dylib dist/aws_policy_equal_arm64.dylib
5056

5157
pack-linux:
5258
zip -j dist/stackql-sqlite-ext-functions-linux-amd64.zip dist/*.so
@@ -62,6 +68,7 @@ test-all:
6268
@make test suite=json_equal
6369
@make test suite=regexp
6470
@make test suite=split_part
71+
@make test suite=aws_policy_equal
6572

6673
# fails if grep does find a failed test case
6774
test:

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<a href="https://sqlpkg.org/?q=stackql/split_part">
88
<img src="https://img.shields.io/badge/sqlpkg-stackql/split_part-blue">
99
</a>
10+
<a href="https://sqlpkg.org/?q=stackql/aws_policy_equal">
11+
<img src="https://img.shields.io/badge/sqlpkg-stackql/aws_policy_equal-blue">
12+
</a>
1013
<a href="https://github.com/stackql/sqlite-ext-functions/actions/workflows/build.yml">
1114
<img src="https://github.com/stackql/sqlite-ext-functions/actions/workflows/build.yml/badge.svg" alt="Build Status">
1215
</a>
@@ -34,6 +37,7 @@ This repository contains a set of extended functions for SQLite designed to enha
3437
## Features
3538

3639
- **JSON Functions**: Includes `json_equal` to compare JSON objects and arrays.
40+
- **AWS Policy Functions**: Includes `aws_policy_equal` to compare AWS IAM policies semantically.
3741
- **Regular Expression Functions**: Includes `regexp_like`, `regexp_substr`, and `regexp_replace` for pattern matching and manipulation.
3842
- **String Splitting Function**: Includes `split_part` to split strings based on a separator and retrieve specific parts.
3943

@@ -73,6 +77,7 @@ After compilation, you can load the extensions in your SQLite shell using:
7377
.load '/path/to/dist/json_equal'
7478
.load '/path/to/dist/regexp'
7579
.load '/path/to/dist/split_part'
80+
.load '/path/to/dist/aws_policy_equal'
7681
```
7782

7883
Alternatively, you can download the extensions from [__sqlpkg__](https://sqlpkg.org/?q=stackql%2Fjson_equal).
@@ -85,7 +90,21 @@ Alternatively, you can download the extensions from [__sqlpkg__](https://sqlpkg.
8590
SELECT json_equal('{"key": "value"}', '{"key": "value"}'); -- Returns 1 (true)
8691
SELECT json_equal('[1, 2, 3]', '[3, 2, 1]'); -- Returns 0 (false)
8792
```
93+
### AWS Policy Functions
8894

95+
```sql
96+
-- Compare AWS policies with different element ordering
97+
SELECT aws_policy_equal(
98+
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject","s3:PutObject"],"Resource":"*"}]}',
99+
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:PutObject","s3:GetObject"],"Resource":"*"}]}'
100+
); -- Returns 1 (true)
101+
102+
-- Compare trust policies with different Principal formats
103+
SELECT aws_policy_equal(
104+
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::123456789012:role/role1"},"Action":"sts:AssumeRole"}]}',
105+
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":["arn:aws:iam::123456789012:role/role1"]},"Action":"sts:AssumeRole"}]}'
106+
); -- Returns 1 (true)
107+
```
89108
### Regular Expression Functions
90109

91110
```sql
@@ -119,6 +138,10 @@ Clean the distribution directory and test logs:
119138
make clean
120139
```
121140

141+
### Publishing to `sqlpkg`
142+
143+
To publish new functions to [`sqlpkg`](https://sqlpkg.org/), raise a PR to [nalgeon/sqlpkg](https://github.com/nalgeon/sqlpkg) adding the new function manifest JSON files.
144+
122145
## License
123146

124147
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)