Skip to content

Commit

Permalink
Amend the OMC role to handle the new omc/data repository checkout
Browse files Browse the repository at this point in the history
We also allow callers to refer to this option as 'data', but also
retain 'omc' and 'bureau' for backward compatibility.

The OMC role itself should also be renamed to DATA for consistency,
but that not strictly necessary to do now.

Fixes #2
  • Loading branch information
levitte committed Feb 25, 2022
1 parent d3da462 commit 816ef27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
22 changes: 11 additions & 11 deletions QueryApp/bin/query.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use OpenSSL::Query::DB;
use URI::Encode qw(uri_decode);

set serializer => 'JSON';
set omc => '/var/cache/openssl/checkouts/omc';
set data => '/var/cache/openssl/checkouts/data';

# Version 0 API.
# Feel free to add new routes, but never to change them or remove them,
Expand All @@ -73,15 +73,15 @@ sub name_decode {
}

get '/People' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc});
my $query = OpenSSL::Query->new(data => config->{data});
my @response = $query->list_people();

return [ @response ] if @response;
send_error('Not found', HTTP_NO_CONTENT);
};

get '/Person/:name' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc});
my $query = OpenSSL::Query->new(data => config->{data});
my $name = name_decode(uri_decode(param('name')));
my %response = $query->find_person($name);

Expand All @@ -90,7 +90,7 @@ get '/Person/:name' => sub {
};

get '/Person/:name/Membership' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $name = name_decode(uri_decode(param('name')));
my %response = $query->find_person($name);

Expand All @@ -99,7 +99,7 @@ get '/Person/:name/Membership' => sub {
};

get '/Person/:name/IsMemberOf/:group' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $name = name_decode(uri_decode(param('name')));
my $group = uri_decode(param('group'));
my $response = $query->is_member_of($name, $group);
Expand All @@ -109,7 +109,7 @@ get '/Person/:name/IsMemberOf/:group' => sub {
};

get '/Person/:name/ValueOfTag/:tag' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $name = name_decode(uri_decode(param('name')));
my $tag = uri_decode(param('tag'));
my $response = $query->find_person_tag($name, $tag);
Expand All @@ -119,7 +119,7 @@ get '/Person/:name/ValueOfTag/:tag' => sub {
};

get '/Person/:name/HasCLA' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $name = name_decode(uri_decode(param('name')));
my %person = $query->find_person($name);
my @response = ();
Expand All @@ -134,7 +134,7 @@ get '/Person/:name/HasCLA' => sub {
};

get '/Group/:group/Members' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $group = uri_decode(param('group'));
my @response = $query->members_of($group);

Expand All @@ -143,7 +143,7 @@ get '/Group/:group/Members' => sub {
};

get '/Group/:group/CLAs' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $group = uri_decode(param('group'));
my @response = ();

Expand All @@ -160,7 +160,7 @@ get '/Group/:group/CLAs' => sub {
};

get '/HasCLA/:id' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc}, REST => 0);
my $query = OpenSSL::Query->new(data => config->{data}, REST => 0);
my $id = uri_decode(param('id'));
if ($id =~ m|^\S+\@\S+$|) {
my $response = $query->has_cla($id);
Expand All @@ -173,7 +173,7 @@ get '/HasCLA/:id' => sub {
};

get '/CLAs' => sub {
my $query = OpenSSL::Query->new(omc => config->{omc});
my $query = OpenSSL::Query->new(data => config->{data});
my @response = $query->list_clas();

return [ @response ] if @response;
Expand Down
12 changes: 8 additions & 4 deletions QueryApp/lib/OpenSSL/Query/Role/OMC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ use Carp;
use File::Spec::Functions;
use Moo::Role;

has omc => ( is => 'ro' );
has bureau => ( is => 'ro' ); # Backward compat, omc takes precedense
has data => ( is => 'ro' );
has omc => ( is => 'ro' ); # Backward compat, data takes precedense
has bureau => ( is => 'ro' ); # Backward compat, data or omc take precedense

sub _find_file {
my $self = shift;
my $filename = shift;
my $envvar = shift;

my $omc = $ENV{OMC} // $self->omc // $ENV{BUREAU} // $self->bureau;
my $data =
$ENV{DATA} // $self->data
// $ENV{OMC} // $self->omc
// $ENV{BUREAU} // $self->bureau;
my @paths = ( $ENV{$envvar} // (),
$omc ? catfile($omc, $filename) : (),
$data ? catfile($data, $filename) : (),
catfile('.', $filename) );
foreach (@paths) {
return $_ if -r $_;
Expand Down

0 comments on commit 816ef27

Please sign in to comment.