Commit 084ec28

mo khan <mo@mokhan.ca>
2025-03-17 22:32:11
feat: use csv files to simulate database tables
1 parent 94d084a
bin/api
@@ -49,7 +49,7 @@ class Entity
   end
 
   def [](attribute)
-    @attributes.fetch(attribute)
+    @attributes.fetch(attribute.to_sym)
   end
 
   def to_h
bin/idp
@@ -6,6 +6,7 @@ gemfile do
   source "https://rubygems.org"
 
   gem "bcrypt", "~> 3.1"
+  gem "csv", "~> 3.1"
   gem "declarative_policy", "~> 1.0"
   gem "erb", "~> 4.0"
   gem "globalid", "~> 1.0"
@@ -61,13 +62,8 @@ module Authn
 
     class << self
       def all
-        @all ||= 10.times.map do |n|
-          new(
-            id: SecureRandom.uuid,
-            username: "username#{n}",
-            email: "username#{n}@example.org",
-            password_digest: password_digest = ::BCrypt::Password.create("password#{n}")
-          )
+        @all ||= ::CSV.read(File.join(__dir__, "../db/users.csv"), headers: true).map do |row|
+          new(row.to_h.transform_keys(&:to_sym))
         end
       end
 
db/groups.csv
@@ -0,0 +1,9 @@
+id, organization_id, parent_id, name
+1, 1, -1, "A"
+2, 1, -1, "B"
+3, 2, -1, "gitlab-org"
+4, 2, -1, "gitlab-com"
+5, 2, 4, "gl-security"
+6, 2, 5, "test-projects"
+7, 2, 4, "support"
+8, 2, 7, "toolbox"
db/organizations.csv
@@ -0,0 +1,3 @@
+id, name
+1, default
+2, gitlab
db/projects.csv
@@ -0,0 +1,9 @@
+id, group_id, name
+1, 1, "A1"
+2, 2, "B1"
+3, 3, "gitlab"
+4, 6, "eicar-test-project"
+5, 5, "disclosures"
+6, 8, "changelog-parser"
+7, 4, "handbook"
+8, 4, "www-gitlab-com"
db/users.csv
@@ -0,0 +1,2 @@
+"id","username","email","password_digest"
+1,"root","root@example.org","$2a$12$pFh1DgN0JcvRAeHeTCGfiuDtuaFaV0vG7He0B6YVpkKWsBy2ZmZtO"
README.md
@@ -46,6 +46,30 @@ I have ommitted TLS, RS256 from the prototype to offload the decision of key
 management and rotation. See [smallstep](https://smallstep.com/docs/step-cli/)
 for PKI management.
 
+CSV files are used instead of a database to simulate different types of
+scenarios. The following organizational hierarchy is demonstrated here:
+
+```
+Organization(name: "default")
+  * Group(name: "A")
+    * Project(name: "A1"
+  * Group(name: "B")
+    * Project(name: "B1"
+Organization(name: "gitlab")
+  * Group(name: "gitlab-org")
+    * Project(name: "gitlab")
+  * Group(name: "gitlab-com")
+    * Group(name: "gl-security")
+      * Group(name: "test-projects")
+        * Project(name: "eicar-test-project")
+      * Project(name: "disclosures")
+    * Group(name: "support")
+      * Group(name: "toolbox")
+        * Project(name: "changelog-parser")
+    * Project(name: "handbook")
+    * Project(name: "www-gitlab-com")
+```
+
 ## Getting Started
 
 1. Install tools:
@@ -69,7 +93,7 @@ for PKI management.
     $ mage
     ```
 
-1. Open browser to `http://ui.example.com:8080/saml/new` to start a new SAML
+1. Open a browser to `http://ui.example.com:8080/saml/new` to start a new SAML
    session. Or open `http://ui.example.com:8080/oidc/new` to start a new OIDC
    session.