Skip to content

Commit e49fd2d

Browse files
committed
chore: move scripts from rbac to main scripts directory
1 parent 0a2f3e0 commit e49fd2d

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

coderd/rbac/scripts/benchmark_authz.sh renamed to scripts/rbac-authz/benchmark_authz.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# Benchmark results are saved with filenames based on the branch name.
1111
#
1212
# Usage:
13-
# benchmark_authz.sh --single # Run benchmarks on current branch
14-
# benchmark_authz.sh --compare <branchA> <branchB> # Compare benchmarks between two branches
13+
# benchmark_authz.sh --single # Run benchmarks on current branch
14+
# benchmark_authz.sh --compare <branchA> <branchB> # Compare benchmarks between two branches
1515

1616
set -euo pipefail
1717

@@ -22,7 +22,8 @@ BENCHTIME=5s
2222
COUNT=5
2323

2424
# Script configuration
25-
OUTPUT_DIR="benchmark_outputs"
25+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26+
OUTPUT_DIR="${SCRIPT_DIR}/benchmark_outputs"
2627

2728
# List of benchmark tests
2829
BENCHMARKS=(
@@ -43,14 +44,20 @@ function run_benchmarks() {
4344
echo "Checking out $branch..."
4445
git checkout "$branch"
4546

47+
# Move into the rbac directory to run the benchmark tests
48+
pushd ../../coderd/rbac/ >/dev/null
49+
4650
for bench in "${BENCHMARKS[@]}"; do
4751
local output_file="${output_file_prefix}_${bench}.txt"
4852
echo "Running benchmark $bench on $branch..."
4953
GOMAXPROCS=$GOMAXPROCS go test -timeout $TIMEOUT -bench="^${bench}$" -run=^$ -benchtime=$BENCHTIME -count=$COUNT | tee "$output_file"
5054
done
55+
56+
# Return to original directory
57+
popd >/dev/null
5158
}
5259

53-
if [[ "${1:-}" == "--single" ]]; then
60+
if [[ $# -eq 0 || "${1:-}" == "--single" ]]; then
5461
current_branch=$(git rev-parse --abbrev-ref HEAD)
5562
run_benchmarks "$current_branch"
5663
elif [[ "${1:-}" == "--compare" ]]; then
@@ -72,7 +79,7 @@ elif [[ "${1:-}" == "--compare" ]]; then
7279
done
7380
else
7481
echo "Usage:"
75-
echo " $0 --single # run benchmarks on current branch"
76-
echo " $0 --compare branchA branchB # compare benchmarks between two branches"
82+
echo " $0 --single # run benchmarks on current branch"
83+
echo " $0 --compare branchA branchB # compare benchmarks between two branches"
7784
exit 1
7885
fi

coderd/rbac/scripts/gen_input.go renamed to scripts/rbac-authz/gen_input.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This program generates an input.json file containing action, object, and subject fields
2+
// to be used as input for `opa eval`, e.g.:
3+
// > opa eval --format=pretty "data.authz.allow" -d policy.rego -i input.json
4+
// This helps verify that the policy returns the expected authorization decision.
15
package main
26

37
import (
@@ -41,7 +45,10 @@ func newSubjectJSON(s rbac.Subject) (*SubjectJSON, error) {
4145
}, nil
4246
}
4347

44-
// TODO: support arguments for subject, action and object
48+
// TODO: Support optional CLI flags to customize the input:
49+
// --action=[one of the supported actions]
50+
// --subject=[one of the built-in roles]
51+
// --object=[one of the supported resources]
4552
func main() {
4653
// Template Admin user
4754
subject := rbac.Subject{

0 commit comments

Comments
 (0)