Skip to content

Commit

Permalink
Remove organization concept
Browse files Browse the repository at this point in the history
This is some groundwork to eventually use the landscape YAML file as
data source.

Related to #471

Signed-off-by: Sergio Castaño Arteaga <[email protected]>
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
Co-authored-by: Sergio Castaño Arteaga <[email protected]>
Co-authored-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
tegioz and cynthia-sg committed Aug 30, 2022
1 parent 04071b0 commit 92bf9e1
Show file tree
Hide file tree
Showing 40 changed files with 336 additions and 686 deletions.
19 changes: 6 additions & 13 deletions .gitpod/sample_data.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
insert into organization (organization_id, name, home_url, logo_url, foundation)
values ('00000001-0000-0000-0000-000000000000', 'artifact-hub', 'https://artifacthub.io/', 'https://raw.githubusercontent.com/cncf/artwork/master/projects/artifacthub/icon/color/artifacthub-icon-color.svg', 'cncf');
insert into organization (organization_id, name, home_url, logo_url, foundation)
values ('00000002-0000-0000-0000-000000000000', 'containerd', 'https://containerd.io', 'https://raw.githubusercontent.com/cncf/artwork/master/projects/containerd/icon/color/containerd-icon-color.svg', 'cncf');
insert into organization (organization_id, name, home_url, logo_url, foundation)
values ('00000003-0000-0000-0000-000000000000', 'core-dns', 'https://coredns.io', 'https://raw.githubusercontent.com/cncf/artwork/master/projects/coredns/icon/color/coredns-icon-color.svg', 'cncf');

insert into project (project_id, name, display_name, description, category, devstats_url, maturity, organization_id)
values ('00000000-0001-0000-0000-000000000000', 'artifact-hub', 'Artifact Hub', 'Artifact Hub is a web-based application that enables finding, installing, and publishing packages and configurations for CNCF projects.', 'app definition', 'https://artifacthub.devstats.cncf.io/', 'sandbox', '00000001-0000-0000-0000-000000000000');
insert into project (project_id, name, description, category, devstats_url, maturity, organization_id)
values ('00000000-0002-0000-0000-000000000000', 'containerd', 'An industry-standard container runtime with an emphasis on simplicity, robustness and portability.', 'runtime', 'https://containerd.devstats.cncf.io', 'graduated', '00000002-0000-0000-0000-000000000000');
insert into project (project_id, name, display_name, category, description, devstats_url, maturity, organization_id)
values ('00000000-0003-0000-0000-000000000000', 'core-dns', 'CoreDNS', 'CoreDNS is a DNS server. It is written in Go. It can be used in a multitude of environments because of its flexibility.', 'orchestration', 'https://coredns.devstats.cncf.io', 'graduated', '00000003-0000-0000-0000-000000000000');
insert into project (project_id, name, display_name, description, category, devstats_url, maturity, foundation_id)
values ('00000000-0001-0000-0000-000000000000', 'artifact-hub', 'Artifact Hub', 'Artifact Hub is a web-based application that enables finding, installing, and publishing packages and configurations for CNCF projects.', 'app definition', 'https://artifacthub.devstats.cncf.io/', 'sandbox', 'cncf');
insert into project (project_id, name, description, category, devstats_url, maturity, foundation_id)
values ('00000000-0002-0000-0000-000000000000', 'containerd', 'An industry-standard container runtime with an emphasis on simplicity, robustness and portability.', 'runtime', 'https://containerd.devstats.cncf.io', 'graduated', 'cncf');
insert into project (project_id, name, display_name, category, description, devstats_url, maturity, foundation_id)
values ('00000000-0003-0000-0000-000000000000', 'core-dns', 'CoreDNS', 'CoreDNS is a DNS server. It is written in Go. It can be used in a multitude of environments because of its flexibility.', 'orchestration', 'https://coredns.devstats.cncf.io', 'graduated', 'cncf');

insert into repository (repository_id, name, url, check_sets, project_id)
values ('00000000-0000-0001-0000-000000000000', 'artifact-hub', 'https://github.com/artifacthub/hub', '{community,code}', '00000000-0001-0000-0000-000000000000');
Expand Down
62 changes: 14 additions & 48 deletions clomonitor-apiserver/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,13 @@ type Count = i64;
#[cfg_attr(test, automock)]
pub(crate) trait DB {
/// Get project's details in json format.
async fn project(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<JsonString>>;
async fn project(&self, foundation: &str, project: &str) -> Result<Option<JsonString>>;

/// Get project's rating.
async fn project_rating(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<String>>;
async fn project_rating(&self, foundation: &str, project: &str) -> Result<Option<String>>;

/// Get project's score.
async fn project_score(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<Score>>;
async fn project_score(&self, foundation: &str, project: &str) -> Result<Option<Score>>;

/// Get all repositories including checks details.
async fn repositories_with_checks(&self) -> Result<String>;
Expand All @@ -69,31 +54,21 @@ impl PgDB {

#[async_trait]
impl DB for PgDB {
async fn project(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<JsonString>> {
async fn project(&self, foundation: &str, project: &str) -> Result<Option<JsonString>> {
let row = self
.pool
.get()
.await?
.query_one(
"select get_project($1::text, $2::text, $3::text)::text",
&[&foundation, &org, &project],
"select get_project($1::text, $2::text)::text",
&[&foundation, &project],
)
.await?;
let project: Option<String> = row.get(0);
Ok(project)
}

async fn project_rating(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<String>> {
async fn project_rating(&self, foundation: &str, project: &str) -> Result<Option<String>> {
let rows = self
.pool
.get()
Expand All @@ -102,12 +77,10 @@ impl DB for PgDB {
"
select rating
from project p
join organization o using (organization_id)
where o.foundation::text = $1::text
and o.name = $2::text
and p.name = $3::text
where p.foundation_id = $1::text
and p.name = $2::text
",
&[&foundation, &org, &project],
&[&foundation, &project],
)
.await?;
if rows.len() != 1 {
Expand All @@ -117,12 +90,7 @@ impl DB for PgDB {
Ok(rating)
}

async fn project_score(
&self,
foundation: &str,
org: &str,
project: &str,
) -> Result<Option<Score>> {
async fn project_score(&self, foundation: &str, project: &str) -> Result<Option<Score>> {
let rows = self
.pool
.get()
Expand All @@ -131,12 +99,10 @@ impl DB for PgDB {
"
select score
from project p
join organization o using (organization_id)
where o.foundation::text = $1::text
and o.name = $2::text
and p.name = $3::text
where p.foundation_id = $1::text
and p.name = $2::text
",
&[&foundation, &org, &project],
&[&foundation, &project],
)
.await?;
if rows.len() != 1 {
Expand Down
21 changes: 10 additions & 11 deletions clomonitor-apiserver/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ pub const REPORT_SUMMARY_HEIGHT: u32 = 470;
/// Handler that returns the information needed to render the project's badge.
pub(crate) async fn badge(
Extension(db): Extension<DynDB>,
Path((foundation, org, project)): Path<(String, String, String)>,
Path((foundation, project)): Path<(String, String)>,
) -> impl IntoResponse {
// Get project rating from database
let rating = db
.project_rating(&foundation, &org, &project)
.project_rating(&foundation, &project)
.await
.map_err(internal_error)?;
if rating.is_none() {
Expand Down Expand Up @@ -121,19 +121,18 @@ pub(crate) async fn index(
pub(crate) async fn index_project(
Extension(cfg): Extension<Arc<Config>>,
Extension(tmpl): Extension<Arc<Tera>>,
Path((foundation, org, project)): Path<(String, String, String)>,
Path((foundation, project)): Path<(String, String)>,
) -> impl IntoResponse {
let mut ctx = Context::new();
ctx.insert("title", &project);
ctx.insert("description", INDEX_META_DESCRIPTION_PROJECT);
ctx.insert(
"image",
&format!(
"{}/projects/{}/{}/{}/report-summary.png",
"{}/projects/{}/{}/report-summary.png",
cfg.get_string("apiserver.baseURL")
.expect("base url not found"),
&foundation,
&org,
&project
),
);
Expand All @@ -151,11 +150,11 @@ pub(crate) async fn index_project(
/// Handler that returns some information about the requested project.
pub(crate) async fn project(
Extension(db): Extension<DynDB>,
Path((foundation, org, project)): Path<(String, String, String)>,
Path((foundation, project)): Path<(String, String)>,
) -> impl IntoResponse {
// Get project from database
let project = db
.project(&foundation, &org, &project)
.project(&foundation, &project)
.await
.map_err(internal_error)?;

Expand Down Expand Up @@ -190,11 +189,11 @@ impl ReportSummaryTemplate {
/// Handler that returns a PNG image with the project's report summary.
pub(crate) async fn report_summary_png(
Extension(db): Extension<DynDB>,
Path((foundation, org, project)): Path<(String, String, String)>,
Path((foundation, project)): Path<(String, String)>,
) -> impl IntoResponse {
// Get project score from database
let score = db
.project_score(&foundation, &org, &project)
.project_score(&foundation, &project)
.await
.map_err(internal_error)?;
if score.is_none() {
Expand Down Expand Up @@ -231,12 +230,12 @@ pub(crate) async fn report_summary_png(
/// Handler that returns an SVG image with the project's report summary.
pub(crate) async fn report_summary_svg(
Extension(db): Extension<DynDB>,
Path((foundation, org, project)): Path<(String, String, String)>,
Path((foundation, project)): Path<(String, String)>,
Query(params): Query<HashMap<String, String>>,
) -> impl IntoResponse {
// Get project score from database
let score = db
.project_score(&foundation, &org, &project)
.project_score(&foundation, &project)
.await
.map_err(internal_error)?;

Expand Down
Loading

0 comments on commit 92bf9e1

Please sign in to comment.