From 338ff46e4ab799a4b159f8c2a79b73751f920727 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 17 Mar 2025 16:48:25 -0600 Subject: feat: fix the csv data and serve it from the REST API --- bin/api | 5 ++++- bin/idp | 4 ++-- db/groups.csv | 18 +++++++++--------- db/organizations.csv | 6 +++--- db/projects.csv | 18 +++++++++--------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/bin/api b/bin/api index e63c713..83c2726 100755 --- a/bin/api +++ b/bin/api @@ -5,6 +5,7 @@ require 'bundler/inline' gemfile do source 'https://rubygems.org' + gem "csv", "~> 3.0" gem "declarative_policy", "~> 1.0" gem "erb", "~> 4.0" gem "globalid", "~> 1.0" @@ -30,7 +31,9 @@ $host = ENV.fetch("HOST", "localhost:#{$port}") class Entity class << self def all - @items ||= [] + @items ||= ::CSV.read(File.join(__dir__, "../db/#{self.name.downcase}s.csv"), headers: true).map do |row| + new(row.to_h.transform_keys(&:to_sym)) + end end def create!(attributes) diff --git a/bin/idp b/bin/idp index 8d13411..622faa1 100755 --- a/bin/idp +++ b/bin/idp @@ -5,8 +5,8 @@ require "bundler/inline" gemfile do source "https://rubygems.org" - gem "bcrypt", "~> 3.1" - gem "csv", "~> 3.1" + gem "bcrypt", "~> 3.0" + gem "csv", "~> 3.0" gem "declarative_policy", "~> 1.0" gem "erb", "~> 4.0" gem "globalid", "~> 1.0" diff --git a/db/groups.csv b/db/groups.csv index 1ff280b..03fcf60 100644 --- a/db/groups.csv +++ b/db/groups.csv @@ -1,9 +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" +"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 index 6758477..840de05 100644 --- a/db/organizations.csv +++ b/db/organizations.csv @@ -1,3 +1,3 @@ -id, name -1, default -2, gitlab +"id","name" +1,"default" +2,"gitlab" diff --git a/db/projects.csv b/db/projects.csv index d824f59..594cc39 100644 --- a/db/projects.csv +++ b/db/projects.csv @@ -1,9 +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" +"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" -- cgit v1.2.3