Skip to content

Commit

Permalink
fix: remove model for testing against given openfga server
Browse files Browse the repository at this point in the history
  • Loading branch information
le-yams committed May 16, 2024
1 parent 07bf422 commit 3bc8a67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 20 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,32 @@ runs:
with:
repo: openfga/cli
cache: enable
- uses: chrisdickinson/[email protected]
with:
yq-version: v4.25.3
- name: Run OpenFGA CLI
shell: bash
run: |
fga_opts=""
fga_token="${{ inputs.fga_api_token }}"
if [[ -n "${{ inputs.fga_server_url }}" ]]; then
if [[ -z "${{ inputs.fga_server_store_id }}" ]]; then
echo "missing store id for specified OpenFGA server ${{ inputs.fga_server_url }}."
exit 1
fi
fga_opts="--api-url ${{ inputs.fga_server_url }} --store-id ${{ inputs.fga_server_store_id }} ${fga_token:+--api-token ${fga_token}}"
fi
while IFS= read -r -d '' test_file
do
((test_files_count+=1))
echo "Running FGA test file ${test_file}"
fga model test ${fga_opts} --tests "${test_file}"
if [[ -z "${{ inputs.fga_server_url }}" ]]; then
echo "Running FGA test file ${test_file}"
fga model test --tests "${test_file}"
else
echo "Running FGA test file ${test_file} against OpenFGA server ${{ inputs.fga_server_url }}"
fga_token="${{ inputs.fga_api_token }}"
test_file_without_model=mktemp
yq 'del(.model_file, .model)' ${test_file} > ${test_file_without_model}
fga model test \
${fga_server_opts} \
--api-url "${{ inputs.fga_server_url }}" \
--store-id "${{ inputs.fga_server_store_id }}" \
${fga_token:+--api-token ${fga_token}} \
--tests "${test_file_without_model}"
fi
done < <(find ${{ inputs.test_path }} -name "${{ inputs.test_files_pattern }}" -print0)
if [[ ${test_files_count} -eq 0 ]]; then
Expand Down
3 changes: 3 additions & 0 deletions example/model_with_conditions.fga.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: FolderBox with temporal accesses # store name
model_file: ./model_with_conditions.fga

model: |
toto
tuples:
- user: user:bob
relation: viewer
Expand Down

0 comments on commit 3bc8a67

Please sign in to comment.