-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BANES][Open311] Create a multi with a Passthrough #399
Open
MorayMySoc
wants to merge
5
commits into
master
Choose a base branch
from
BNS172-4830-create-multi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
13eafe9
[Open311] Remove trailing whitespace
MorayMySoc 90955cb
[Open311][BANES] Makes Banes a multi and adds Passthrough
MorayMySoc cecad47
fixup! [Open311][BANES] Makes Banes a multi and adds Passthrough
MorayMySoc 470949b
fixup! [Open311][BANES] Makes Banes a multi and adds Passthrough
MorayMySoc bd7c537
fixup! [Open311][BANES] Makes Banes a multi and adds Passthrough
MorayMySoc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
endpoint: https://localhost:4000/ | ||
api_key: 123 | ||
bearer_details: | ||
username: FMS | ||
password: FMSPassword | ||
url: url/address |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,64 @@ | ||
=head1 NAME | ||
|
||
Open311::Endpoint::Integration::UK::BANES - Bath and North East Somerset integration set-up | ||
|
||
=head1 SYNOPSIS | ||
|
||
BANES manage their own Open311 server to receive all reports made on FMS, whether in | ||
email categories or in those created by their Confirm integration. The Confirm | ||
integration only receives the reports in categories in its services. | ||
|
||
=cut | ||
|
||
package Open311::Endpoint::Integration::UK::BANES; | ||
|
||
use Moo; | ||
extends 'Open311::Endpoint::Integration::Confirm'; | ||
extends 'Open311::Endpoint::Integration::Multi'; | ||
|
||
use Module::Pluggable | ||
search_path => ['Open311::Endpoint::Integration::UK::BANES'], | ||
instantiate => 'new'; | ||
|
||
has jurisdiction_id => ( | ||
is => 'ro', | ||
default => 'banes', | ||
); | ||
|
||
=head2 _map_with_new_id & _map_from_new_id | ||
|
||
BANES's two endpoints do not overlap in service_codes as the Passthrough | ||
accepts all reports with email addresses and the others are Confirm. | ||
This code overrides the default Multi code to not change anything, | ||
and cope accordingly. | ||
|
||
=cut | ||
|
||
sub _map_with_new_id { | ||
my ($self, $attributes, @results) = @_; | ||
|
||
@results = map { | ||
my ($name, $result) = @$_; | ||
$result; | ||
} @results; | ||
|
||
return @results; | ||
} | ||
|
||
my $email_regex = qr/\@.*?\./; | ||
|
||
sub _map_from_new_id { | ||
my ($self, $code, $type) = @_; | ||
|
||
my $integration; | ||
if ($type eq 'service' || $type eq 'request') { | ||
if ($code =~ /$email_regex/) { | ||
$integration = 'Passthrough'; | ||
} else { | ||
$integration = 'Confirm'; | ||
} | ||
} | ||
|
||
around BUILDARGS => sub { | ||
my ($orig, $class, %args) = @_; | ||
$args{jurisdiction_id} = 'banes_confirm'; | ||
return $class->$orig(%args); | ||
}; | ||
return ($integration, $code); | ||
} | ||
|
||
1; | ||
__PACKAGE__->run_if_script; |
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,12 @@ | ||
package Open311::Endpoint::Integration::UK::BANES::Confirm; | ||
|
||
use Moo; | ||
extends 'Open311::Endpoint::Integration::Confirm'; | ||
|
||
around BUILDARGS => sub { | ||
my ($orig, $class, %args) = @_; | ||
$args{jurisdiction_id} = 'banes_confirm'; | ||
return $class->$orig(%args); | ||
}; | ||
|
||
1; |
109 changes: 109 additions & 0 deletions
109
perllib/Open311/Endpoint/Integration/UK/BANES/Passthrough.pm
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,109 @@ | ||
=head1 NAME | ||
|
||
Open311::Endpoint::Integration::UK::BANES::Passthrough - Bath and North East Somerset Passthrough backend | ||
|
||
=head1 SUMMARY | ||
|
||
This is the BANES-specific Passthrough integration. It follows Open311 | ||
standards except requires a bearer token to be passed rather than an | ||
api token | ||
|
||
=cut | ||
|
||
package Open311::Endpoint::Integration::UK::BANES::Passthrough; | ||
|
||
use Moo; | ||
extends 'Open311::Endpoint::Integration::Passthrough'; | ||
|
||
use Types::Standard ':all'; | ||
|
||
around BUILDARGS => sub { | ||
my ($orig, $class, %args) = @_; | ||
$args{jurisdiction_id} = 'www.banes.gov.uk'; | ||
return $class->$orig(%args); | ||
}; | ||
|
||
has bearer_details => (is => 'ro'); | ||
|
||
=head2 identifier_types | ||
|
||
Add an identifier_types attribute to duplicate the UK.pm service_code validation | ||
so the mocking in the test can remain shallow | ||
|
||
=cut | ||
|
||
has '+identifier_types' => ( | ||
is => 'lazy', | ||
isa => HashRef[Any], | ||
default => sub { | ||
return { | ||
service_code => { type => '/open311/regex', pattern => qr/^ [&,\.\w_\- \@\/\(\)]+ $/ax }, | ||
}; | ||
} | ||
); | ||
|
||
=head2 service | ||
|
||
BANES are not providing services or service calls for their own open311 backend. | ||
All service requests should be sent, so we generate an artificial service | ||
that permits the service request to be sent, but maintains the open311 flow. | ||
|
||
=cut | ||
|
||
sub service { | ||
my ($self, $service_id, $args) = @_; | ||
|
||
my $service = Open311::Endpoint::Service->new(service_code => $service_id); | ||
|
||
my $attribute = Open311::Endpoint::Service::Attribute->new( | ||
code => $service_id, | ||
datatype => 'string', | ||
); | ||
push @{ $service->attributes }, $attribute; | ||
|
||
return $service; | ||
}; | ||
|
||
=head2 _request | ||
|
||
Rather than using an api key, we need to get a bearer token for authorisation | ||
and set the Bearer header. | ||
|
||
Also munge params - jurisdiction_id is not expected and we want to make | ||
the service code the same as the Confirm code now it's been established | ||
it's being sent to the Passthrough | ||
|
||
=cut | ||
|
||
around _request => sub { | ||
my ($orig, $self, $method, $url, $params) = @_; | ||
|
||
delete $params->{jurisdiction_id}; | ||
|
||
if ($params->{service_code} =~ /passthrough-.*?@/) { | ||
($params->{service_code}) = $params->{service_code} =~ /passthrough-(.*?)@/; | ||
} | ||
|
||
if ($method eq 'POST' && $url !~ /api\/token/ ) { | ||
$params = { 'Content' => $params, 'Authorization' => 'Bearer ' . $self->_get_bearer_token()->content }; | ||
}; | ||
|
||
return $self->$orig($method, $url, $params); | ||
}; | ||
|
||
sub _get_bearer_token { | ||
my $self = shift; | ||
|
||
my $bearer_details = $self->bearer_details; | ||
|
||
my $params = { | ||
username => $bearer_details->{username}, | ||
password => $bearer_details->{password}, | ||
}; | ||
|
||
my $url = $bearer_details->{url}; | ||
|
||
return $self->ua->post($url, $params); | ||
}; | ||
|
||
1; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will work, as the code will be a number when type is request for either Passthrough or Confirm