/usr/share/perl5/Prophet/ForeignReplica.pm is in libprophet-perl 0.750-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | package Prophet::ForeignReplica;
use Any::Moose;
use Params::Validate qw(:all);
extends 'Prophet::Replica';
=head1 NAME
Prophet::ForeignReplica
=head1 DESCRIPTION
This abstract baseclass implements the helpers you need to be able to
easily sync a prophet replica with a "second class citizen" replica
which can't exactly reconstruct changesets, doesn't use uuids to track
records and so on.
=head1 METHODS
=cut
sub fetch_local_metadata {
my $self = shift;
my $key = shift;
return $self->app_handle->handle->fetch_local_metadata(
$self->uuid . "-".$key );
}
sub store_local_metadata {
my $self = shift;
my $key = shift;
my $value = shift;
return $self->app_handle->handle->store_local_metadata(
$self->uuid."-".$key => $value);
}
sub conflicts_from_changeset { return; }
sub can_write_changesets {1}
sub record_resolutions {
die "Resolution handling is not for foreign replicas";
}
sub import_resolutions_from_remote_source {
warn 'resdb not implemented yet';
return;
}
=head2 record_changes L<Prophet::ChangeSet>
Integrate all changes in this changeset.
=cut
sub record_changes {
my $self = shift;
my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );
$self->integrate_changes($changeset);
}
# XXX TODO = or do these ~always stay stubbed?
sub begin_edit { }
sub commit_edit { }
# foreign replicas never have a db uuid
sub db_uuid { return undef }
sub uuid_for_url {
my ( $self, $url ) = @_;
return $self->uuid_generator->create_string_from_url( $url );
}
=head2 prompt_for_login
Interactively prompt the user for a username and an authentication secret
(usually a password).
Named parameters:
uri
username
password
username_prompt
secret_prompt
To use the default prompts, which ask for a username and password, pass in
C<uri> and (optionally) C<username>. Either prompt will be skipped if
a value is passed in to begin, making this suitable for use in a login
loop that prompts for values and then tests that they work for authentication,
looping around if they don't.
You can also override the default prompts by passing in subroutines for
C<username_prompt> and/or C<secret_prompt>. These subroutines return strings
to be printed and are called like this:
username_prompt( uri )
secret_prompt( uri, username )
Where C<uri> and C<username> are the args that are passed in under those
names (if any). You don't need to use them; use a closure if you want
something else.
=cut
sub prompt_for_login {
my $self = shift;
my %args = (
uri => undef,
username => undef,
password => undef,
secret_prompt => sub {
my ($uri, $username) = @_;
return "Password for $username: @ $uri: ";
},
username_prompt => sub {
my ($uri) = shift;
return "Username for ${uri}: ";
},
@_,
);
# check if username and password are in config
my $replica_username_key = 'replica.' . $self->scheme
.":" . $self->{url} . '.username';
my $replica_token_key = 'replica.' . $self->scheme . ":"
. $self->{url} . '.secret_token';
if ( !$args{username} ) {
my $check_username
= $self->app_handle->config->get( key => $replica_username_key );
$args{username} = $check_username if $check_username;
}
my $was_in_pager = Prophet::CLI->in_pager();
Prophet::CLI->end_pager();
# XXX belongs to some CLI callback
use Term::ReadKey;
local $| = 1;
unless ($args{username}) {
print $args{username_prompt}($args{uri});
ReadMode 1;
chomp( $args{username} = ReadLine 0 );
}
if ( my $check_password
= $self->app_handle->config->get( key => $replica_token_key ) )
{
$args{password} = $check_password;
}
elsif ( !defined($args{password}) ) {
print $args{secret_prompt}( $args{uri}, $args{username} );
ReadMode 2;
chomp( $args{password} = ReadLine 0 );
ReadMode 1;
print "\n";
}
Prophet::CLI->start_pager() if ($was_in_pager);
return ( $args{username}, $args{password} );
}
sub log {
my $self = shift;
my ($msg) = validate_pos(@_, 1);
Carp::confess unless ($self->app_handle);
$self->app_handle->log($self->url.": " .$msg);
}
no Any::Moose;
__PACKAGE__->meta->make_immutable;
1;
|