Beekeeper
view release on metacpan or search on metacpan
examples/dashboard/lib/Beekeeper/Service/Dashboard/Worker.pm view on Meta::CPAN
last unless $users_cfg->{$username}->{'password'};
last unless $users_cfg->{$username}->{'password'} eq $pwd_hash;
# Set authentication data and assign an address to the user
$self->set_authentication_data( $username );
$self->bind_remote_session( address => "frontend.dashboard-$username" );
return 1;
}
Beekeeper::JSONRPC::Error->request_not_authenticated;
}
sub service_stats {
my ($self, $params, $req) = @_;
my $resol = $params->{'resolution'} || '1s';
my $count = $params->{'count'} || 1;
my $class = $params->{'class'};
my $after = $params->{'after'};
lib/Beekeeper/JSONRPC/Error.pm view on Meta::CPAN
}
sub request_timeout {
shift->new(
code => -31600,
message => "Request timeout",
@_
);
}
sub request_not_authenticated {
shift->new(
code => -401,
message => "Not logged in",
data => "Request was not authenticated",
@_
);
}
sub request_not_authorized {
shift->new(
code => -403,
message => "Request not authorized",
data => "Request was not authorized",
@_
);
}
sub method_not_found {
shift->new(
code => -32601,
message => "Method not found",
data => "The method does not exist",
@_
);
}
sub method_not_available {
shift->new(
code => -31601,
message => "Method not available",
data => "The method is not available.",
@_
);
}
sub invalid_params {
shift->new(
lib/Beekeeper/Service/Sinkhole/Worker.pm view on Meta::CPAN
sub reject_request {
my ($self, $params, $req) = @_;
# Just return a JSONRPC error response
if ($req->mqtt_properties->{'auth'}) {
# When client provided some kind of authentication tell him the truth
# about the service being down. Otherwise the one trying to fix the
# issue may be deceived into looking for auth/permissions problems
return Beekeeper::JSONRPC::Error->method_not_available;
}
else {
return Beekeeper::JSONRPC::Error->request_not_authorized;
}
}
1;
__END__
=pod
=encoding utf8
lib/Beekeeper/Worker.pm view on Meta::CPAN
}
$request_id = $request->{id};
my $method = $request->{method};
bless $request, 'Beekeeper::JSONRPC::Request';
$request->{_mqtt_properties} = $mqtt_properties;
unless (defined $method && $method =~ m/^([\.\w-]+)\.([\w-]+)$/) {
log_error "Received request with invalid method '$method'";
die Beekeeper::JSONRPC::Error->method_not_found;
}
my $cb = $worker->{callbacks}->{"req.$1.$2"} ||
$worker->{callbacks}->{"req.$1.*"};
local $client->{caller_id} = $mqtt_properties->{'clid'};
local $client->{caller_addr} = $mqtt_properties->{'addr'};
local $client->{auth_data} = $mqtt_properties->{'auth'};
unless (($self->authorize_request($request) || "") eq BKPR_REQUEST_AUTHORIZED) {
log_error "Request '$method' was not authorized";
die Beekeeper::JSONRPC::Error->request_not_authorized;
}
unless ($cb) {
log_error "No handler found for received request '$method'";
die Beekeeper::JSONRPC::Error->method_not_found;
}
# Execute method handler
$cb->($self, $request->{params}, $request);
};
if ($@) {
# Got an exception while executing method handler
if (blessed($@) && $@->isa('Beekeeper::JSONRPC::Error')) {
# Handled exception
( run in 0.262 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )