Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-MCaw committed Jan 13, 2025
1 parent 6f5a74c commit 6bce076
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/alire/alire-index.adb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ package body Alire.Index is
for Crate of All_Crates.all loop
for Rel of Crate.Releases loop
if Rel.Origin.Kind in Origins.VCS_Kinds then
if not Publish.Is_Trusted (Rel.Origin.URL, False) then
if not Publish.Is_Trusted
(Rel.Origin.URL, For_Community => False)
then
OK := False;
Put_Warning ("Release " & Rel.Milestone.TTY_Image
& " has URL not in known hosts: "
Expand Down
34 changes: 22 additions & 12 deletions src/alire/alire-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,14 @@ package body Alire.Publish is

if Context.Origin.Kind in Origins.VCS_Kinds then

-- Check an VCS origin is from a trusted site, unless we are forcing
-- a local repository.
-- Check a VCS origin is from a trusted site, unless we are forcing
-- a local repository or '--for-private-index' is specified.

if (Force and then
URI.URI_Kind (URL) in URI.Local_URIs)
or else
Is_Trusted (URL, not Context.Options.For_Private_Index)
Is_Trusted
(URL, For_Community => not Context.Options.For_Private_Index)
then
Put_Success ("Origin is hosted on trusted site: "
& URI.Host (URL));
Expand Down Expand Up @@ -1079,9 +1080,9 @@ package body Alire.Publish is
-- Trusted_Sites --
-------------------

function Trusted_Sites (Ignore_Setting : Boolean) return Vector is
function Trusted_Sites (For_Community : Boolean) return Vector is
Space_Separated : constant String :=
(if Ignore_Setting then Community_Trusted_Sites
(if For_Community then Community_Trusted_Sites
else Settings.Builtins.Origins_Git_Trusted_Sites.Get);
Split_Vector : constant Vector := Split (Space_Separated, ' ');
Sites : Vector := Empty_Vector;
Expand All @@ -1094,17 +1095,27 @@ package body Alire.Publish is
return Sites;
end Trusted_Sites;

---------------------------
-- All_Sites_Are_Trusted --
---------------------------

function All_Sites_Are_Trusted (For_Community : Boolean) return Boolean is
Sites : constant Vector := Trusted_Sites (For_Community);
begin
return Sites.Length in 1 and then Sites (1) = "...";
end All_Sites_Are_Trusted;

----------------
-- Is_Trusted --
----------------

function Is_Trusted (URL : Alire.URL; Ignore_Setting : Boolean)
function Is_Trusted (URL : Alire.URL; For_Community : Boolean)
return Boolean
is
Sites : constant Vector := Trusted_Sites (Ignore_Setting);
Sites : constant Vector := Trusted_Sites (For_Community);
begin
return
Sites.Length in 0 -- Empty list means all sites are trusted
All_Sites_Are_Trusted (For_Community)
or else (for some Site of Sites
=> URI.Host (URL) = Site
or else Has_Suffix (URI.Host (URL), "." & Site));
Expand Down Expand Up @@ -1470,11 +1481,10 @@ package body Alire.Publish is
-- Print_Trusted_Sites --
-------------------------

procedure Print_Trusted_Sites (For_Private_Index : Boolean) is
Ignore_Setting : constant Boolean := not For_Private_Index;
Sites : constant Vector := Trusted_Sites (Ignore_Setting);
procedure Print_Trusted_Sites (For_Community : Boolean) is
Sites : constant Vector := Trusted_Sites (For_Community);
begin
if Sites.Length in 0 then
if All_Sites_Are_Trusted (For_Community) then
Trace.Always ("All sites are currently trusted for private indexes.");
else
for Site of Sites loop
Expand Down
12 changes: 6 additions & 6 deletions src/alire/alire-publish.ads
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ package Alire.Publish is
& M.Crate.As_String & "-"
& M.Version.Image);

procedure Print_Trusted_Sites (For_Private_Index : Boolean);
procedure Print_Trusted_Sites (For_Community : Boolean);
-- Print our list of allowed sites to host git releases.
--
-- If For_Private_Index is True, the list is that configured with the
-- 'origins.git.trusted_sites' setting, otherwise it is the hardcoded
-- Community_Trusted_Sites list.
-- If For_Community is True, the list is the hardcoded
-- Community_Trusted_Sites list, otherwise it is that configured with the
-- 'origins.git.trusted_sites' setting.

function Is_Trusted (URL : Alire.URL; Ignore_Setting : Boolean)
function Is_Trusted (URL : Alire.URL; For_Community : Boolean)
return Boolean;
-- According to the 'origins.git.trusted_sites' setting, or the hardcoded
-- Community_Trusted_Sites if Ignore_Setting is True.
-- Community_Trusted_Sites if For_Community is True.

type Data is tagged limited private;

Expand Down
9 changes: 4 additions & 5 deletions src/alire/alire-settings-builtins.ads
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ package Alire.Settings.Builtins is
Global_Only => True,
Help =>
"Space-separated list of trusted sites for Git origins, used by"
& " 'alr index --check' and 'alr publish --for-private-index'. If"
& " empty (e.g. if set to ' '), all origins are trusted. Note that"
& " this does not have any effect when using 'alr publish' for"
& " submissions to the community index (which only permits the"
& " default list).");
& " 'alr index --check' and 'alr publish --for-private-index'. If set to"
& " '...', all origins are trusted. Note that this does not have any"
& " effect when using 'alr publish' for submissions to the community"
& " index (which only permits the default list).");

-- SOLVER

Expand Down
3 changes: 2 additions & 1 deletion src/alr/alr-commands-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ package body Alr.Commands.Publish is
Cmd.Auto_Update_Index;

if Cmd.Print_Trusted then
Alire.Publish.Print_Trusted_Sites (Cmd.For_Private_Index);
Alire.Publish.Print_Trusted_Sites
(For_Community => not Cmd.For_Private_Index);

elsif Cmd.Tar then

Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/index/untrusted-host/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
p.out
)

# Set 'origins.git.trusted_sites' to ' ' and verify that all hosts are now
# Set 'origins.git.trusted_sites' to '...' and verify that all hosts are now
# permitted.
alr_settings_set("origins.git.trusted_sites", " ")
alr_settings_set("origins.git.trusted_sites", "...")
p = run_alr("index", "--check", quiet=False)
assert_eq("Success: No issues found in index contents.\n", p.out)

Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/publish/trusted-sites/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
p = run_alr("publish", "--for-private-index", "--trusted-sites")
assert_eq("some.host\nother.host\nthird.host\n", p.out)

# Set `origins.git.trusted_sites` to an empty list (which trusts all hosts)
alr_settings_set("origins.git.trusted_sites", " ")
# Set `origins.git.trusted_sites` to '...' (which trusts all hosts)
alr_settings_set("origins.git.trusted_sites", "...")

# Verify that the output of `alr publish --trusted-sites` is unchanged
p = run_alr("publish", "--trusted-sites")
Expand Down

0 comments on commit 6bce076

Please sign in to comment.