MatrixTool/Command/client/login.pm

filter: Statementstmt 52.6% 20 / 38 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 1 totaltotal 53.0% 26 / 49 CC 2 SCAR 8.0
CC
2
Cov
50%
run
6.0
__ANON__
2.0
BEGIN
1.0
CRAP 2.2
« MatrixTool/SubCommands.pm ↑ Summary MatrixTool/Command/client/list_rooms.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk
5  
6 package App::MatrixTool::Command::client::login;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base qw( App::MatrixTool::Command::client );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '0.08';
13  
14 1 ▶use constant DESCRIPTION => "Obtain a client authentication token";
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant ARGUMENTS => ( "user", "password?" );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant OPTIONS => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 matrixtool client login - Obtain a client authentication token
21  
22 =head1 SYNOPSIS
23  
24 $ matrixtool client login @me:example.com
25  
26 =head1 DESCRIPTION
27  
28 This command performs the C</login> steps of the Matrix client API, obtaining
29 an access token for the given user ID. This requires a password - either
30 provided on the commandline as a second argument, or requested interactively
31 on the terminal.
32  
33 Once the access token is obtained it is stored in the token cache, which lives
34 in F<$HOME/.matrix/client-tokens>. This cache will be consulted by other
35 C<matrixtool client> sub-commands to automatically provide the access token if
36 required.
37  
38 Note that the interactive terminal method requires the optional dependency of
39 L<IO::Termios> to be installed, so that local echo can temporarily be disabled
40 while the user types in the password.
41  
42 =cut
43  
44 sub run
45 0 ▶{
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my $self = shift;
47 0 my ( $opts, $user, $password ) = @_;
48  
49 0 $self->{user_id} = $user;
50  
51 0 ▶ if( !defined $password ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $password) 0 0 0
52 0 require IO::Termios;
53 0 my $stdin = IO::Termios->new( \*STDIN );
54  
55 0 STDOUT->autoflush(1);
56 0 print "Password: ";
57  
58 0 $stdin->setflag_echo( 0 );
59 0 $password = <$stdin>; chomp $password; print "\n";
60 0 $stdin->setflag_echo( 1 );
61 }
62  
63 $self->do_json( POST => "/_matrix/client/r0/login",
64 content => {
65 type => "m.login.password",
66 user => $user,
67 password => $password,
68 }
69 0 ▶ )->then( sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 my ( $body ) = @_;
71  
72 $self->client_token_store->put(
73 server => $self->{server},
74 id => $user,
75 data => $body->{access_token},
76 0 );
77  
78 0 $self->output_ok( "Obtained access token" );
79  
80 0 Future->done();
81 0 });
82 }
83  
84 =head1 AUTHOR
85  
86 Paul Evans <leonerd@leonerd.org.uk>
87  
88 =cut
89  
90 1 0x55AA;
« MatrixTool/SubCommands.pm ↑ Summary MatrixTool/Command/client/list_rooms.pm »