From 084ec28adef9f16a0f38f0457662e9695dfcff8a Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 17 Mar 2025 16:32:11 -0600 Subject: feat: use csv files to simulate database tables --- README.md | 26 +++++++++++++++++++++++++- bin/api | 2 +- bin/idp | 10 +++------- db/groups.csv | 9 +++++++++ db/organizations.csv | 3 +++ db/projects.csv | 9 +++++++++ db/users.csv | 2 ++ 7 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 db/groups.csv create mode 100644 db/organizations.csv create mode 100644 db/projects.csv create mode 100644 db/users.csv diff --git a/README.md b/README.md index e29e796d..cf7af05c 100644 --- a/README.md +++ b/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. diff --git a/bin/api b/bin/api index 868d5754..e63c7138 100755 --- a/bin/api +++ b/bin/api @@ -49,7 +49,7 @@ class Entity end def [](attribute) - @attributes.fetch(attribute) + @attributes.fetch(attribute.to_sym) end def to_h diff --git a/bin/idp b/bin/idp index 81e5ffe0..8d13411b 100755 --- a/bin/idp +++ b/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 diff --git a/db/groups.csv b/db/groups.csv new file mode 100644 index 00000000..1ff280b6 --- /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 00000000..67584777 --- /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 00000000..d824f59b --- /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 00000000..a0194d71 --- /dev/null +++ b/db/users.csv @@ -0,0 +1,2 @@ +"id","username","email","password_digest" +1,"root","root@example.org","$2a$12$pFh1DgN0JcvRAeHeTCGfiuDtuaFaV0vG7He0B6YVpkKWsBy2ZmZtO" -- cgit v1.2.3