-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API endpoint for Helm exporter tool (#1544)
Related to: sstarcher/helm-exporter#66 Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com> Signed-off-by: Cintia Sanchez Garcia <cynthiasg@icloud.com> Co-authored-by: Sergio Castaño Arteaga <tegioz@icloud.com> Co-authored-by: Cintia Sanchez Garcia <cynthiasg@icloud.com>
- Loading branch information
1 parent
3f1c1f6
commit 64c123a
Showing
12 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
database/migrations/functions/packages/get_helm_exporter_dump.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- get_helm_exporter_dump returns a json list with the latest version of all | ||
-- packages of kind Helm available so that they can be used by Helm exporter. | ||
create or replace function get_helm_exporter_dump() | ||
returns setof json as $$ | ||
select coalesce(json_agg(json_build_object( | ||
'name', p.name, | ||
'version', p.latest_version, | ||
'repository', json_build_object( | ||
'name', r.name, | ||
'url', r.url | ||
) | ||
)), '[]') | ||
from package p | ||
join repository r using (repository_id) | ||
where r.repository_kind_id = 0; | ||
$$ language sql; |
111 changes: 111 additions & 0 deletions
111
database/tests/functions/packages/get_helm_exporter_dump.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
-- Start transaction and plan tests | ||
begin; | ||
select plan(2); | ||
|
||
-- Declare some variables | ||
\set org1ID '00000000-0000-0000-0000-000000000001' | ||
\set repo1ID '00000000-0000-0000-0000-000000000001' | ||
\set repo2ID '00000000-0000-0000-0000-000000000002' | ||
\set repo3ID '00000000-0000-0000-0000-000000000003' | ||
\set package1ID '00000000-0000-0000-0000-000000000001' | ||
\set package2ID '00000000-0000-0000-0000-000000000002' | ||
\set package3ID '00000000-0000-0000-0000-000000000003' | ||
|
||
-- No packages at this point | ||
select is( | ||
get_helm_exporter_dump()::jsonb, | ||
'[]'::jsonb, | ||
'No packages in db yet, empty dump expected' | ||
); | ||
|
||
-- Seed some data | ||
insert into organization (organization_id, name, display_name, description, home_url) | ||
values (:'org1ID', 'org1', 'Organization 1', 'Description 1', 'https://org1.com'); | ||
insert into repository (repository_id, name, display_name, url, repository_kind_id, organization_id) | ||
values (:'repo1ID', 'repo1', 'Repo 1', 'https://repo1.com', 0, :'org1ID'); | ||
insert into repository (repository_id, name, display_name, url, repository_kind_id, organization_id) | ||
values (:'repo2ID', 'repo2', 'Repo 2', 'https://repo2.com', 0, :'org1ID'); | ||
insert into repository (repository_id, name, display_name, url, repository_kind_id, organization_id) | ||
values (:'repo3ID', 'repo3', 'Repo 3', 'https://repo3.com', 1, :'org1ID'); | ||
insert into package ( | ||
package_id, | ||
name, | ||
latest_version, | ||
repository_id | ||
) values ( | ||
:'package1ID', | ||
'package1', | ||
'1.0.0', | ||
:'repo1ID' | ||
); | ||
insert into snapshot ( | ||
package_id, | ||
version | ||
) values ( | ||
:'package1ID', | ||
'1.0.0' | ||
); | ||
insert into package ( | ||
package_id, | ||
name, | ||
latest_version, | ||
repository_id | ||
) values ( | ||
:'package2ID', | ||
'package2', | ||
'1.0.0', | ||
:'repo2ID' | ||
); | ||
insert into snapshot ( | ||
package_id, | ||
version | ||
) values ( | ||
:'package2ID', | ||
'1.0.0' | ||
); | ||
insert into package ( | ||
package_id, | ||
name, | ||
latest_version, | ||
repository_id | ||
) values ( | ||
:'package3ID', | ||
'package3', | ||
'1.0.0', | ||
:'repo3ID' | ||
); | ||
insert into snapshot ( | ||
package_id, | ||
version | ||
) values ( | ||
:'package3ID', | ||
'1.0.0' | ||
); | ||
|
||
-- Run some tests | ||
select is( | ||
get_helm_exporter_dump()::jsonb, | ||
'[ | ||
{ | ||
"name": "package1", | ||
"version": "1.0.0", | ||
"repository": { | ||
"name": "repo1", | ||
"url": "https://repo1.com" | ||
} | ||
}, | ||
{ | ||
"name": "package2", | ||
"version": "1.0.0", | ||
"repository": { | ||
"name": "repo2", | ||
"url": "https://repo2.com" | ||
} | ||
} | ||
]'::jsonb, | ||
'Two packages expected in dump' | ||
); | ||
|
||
-- Finish tests and rollback transaction | ||
select * from finish(); | ||
rollback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters