diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-17 16:32:11 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-17 16:32:11 -0600 |
| commit | 084ec28adef9f16a0f38f0457662e9695dfcff8a (patch) | |
| tree | b2f4abd372d26d13331a9c9ee69d75249bcc50a3 | |
| parent | 94d084a51172b7e3851779e9e052435084d4abfe (diff) | |
feat: use csv files to simulate database tables
| -rw-r--r-- | README.md | 26 | ||||
| -rwxr-xr-x | bin/api | 2 | ||||
| -rwxr-xr-x | bin/idp | 10 | ||||
| -rw-r--r-- | db/groups.csv | 9 | ||||
| -rw-r--r-- | db/organizations.csv | 3 | ||||
| -rw-r--r-- | db/projects.csv | 9 | ||||
| -rw-r--r-- | db/users.csv | 2 |
7 files changed, 52 insertions, 9 deletions
@@ -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. @@ -49,7 +49,7 @@ class Entity end def [](attribute) - @attributes.fetch(attribute) + @attributes.fetch(attribute.to_sym) end def to_h @@ -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 diff --git a/db/groups.csv b/db/groups.csv new file mode 100644 index 0000000..1ff280b --- /dev/null +++ b/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" diff --git a/db/organizations.csv b/db/organizations.csv new file mode 100644 index 0000000..6758477 --- /dev/null +++ b/db/organizations.csv @@ -0,0 +1,3 @@ +id, name +1, default +2, gitlab diff --git a/db/projects.csv b/db/projects.csv new file mode 100644 index 0000000..d824f59 --- /dev/null +++ b/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" diff --git a/db/users.csv b/db/users.csv new file mode 100644 index 0000000..a0194d7 --- /dev/null +++ b/db/users.csv @@ -0,0 +1,2 @@ +"id","username","email","password_digest" +1,"root","root@example.org","$2a$12$pFh1DgN0JcvRAeHeTCGfiuDtuaFaV0vG7He0B6YVpkKWsBy2ZmZtO" |
