Implement support for username and password

This commit is contained in:
Daniel Berteaud 2019-03-25 23:02:47 +01:00
parent a8ed673353
commit 6eb3385295
1 changed files with 8 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use Encode qw(encode);
use Compress::Zlib;
use Getopt::Long;
use YAML::Tiny;
use MIME::Base64;
my $conf = {};
my $cmd = {
@ -72,6 +73,13 @@ if ( $conf->{compress} ){
$ua->default_header( 'Content-Encoding' => 'gzip' );
}
# Add basic auth header if set in the config
# Note that we do not check the realm, nor we check for a 401 response, we consider
# admins will be careful enough not to set wrong server in the conf
if ( $conf->{username} and $conf->{password} ) {
$ua->default_header( 'Authorization' => 'Basic ' . encode_base64($conf->{username} . ':' . $conf->{password}) );
}
# Check if the state file exists and contains a valid cursor
my $cursor_arg = '';
open CURSOR, "+<", $conf->{state};