File: JIRACLI.pm

package info (click to toggle)
libjira-rest-perl 0.024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 588; makefile: 8
file content (89 lines) | stat: -rw-r--r-- 1,793 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl

package JIRACLI;

use 5.016;
use utf8;
use warnings;
use JIRA::REST;
use IO::Interactive qw(is_interactive);
use IO::Prompter;
use Carp;

use parent qw(Exporter);
our @EXPORT_OK = qw(get_credentials);
our $VERSION = '0.02';

sub get_credentials {
    my ($user, $pass) = @ENV{qw/jirauser jirapass/};

    return ($user, $pass) if defined $user && defined $pass;

    unless (is_interactive()) {
        # We cannot prompt the user if we're not talking to a
        # terminal.
        croak "Cannot prompt user for credentials because STDIN isn't a terminal.\n";
    }

    if (!defined $user) {
        $user = prompt(
            -prompt  => "Username:",
            -in      => \*STDIN,
            -out     => \*STDERR,
            -verbatim,
        );
    }

    if (! defined $pass) {
        $pass = prompt(
            -prompt  => "Password:",
            -in      => \*STDIN,
            -out     => \*STDERR,
            -echo    => '*',
            -verbatim,
        );
    }

    return ($user, $pass);
}

1;
__END__
=encoding utf8

=head1 NAME

JIRACLI - Common utilities for all JIRA CLI examples

=head1 SYNOPSIS

  use lib $FindBin::Bin;
  use JIRACLI;

=head1 DESCRIPTION

This module contains a few functions used by most of the JIRA CLI examples

=head1 FUNCTIONS

=head2 get_credentials

   my ($user, $pass) = get_credentials();

This function will first check for user and password specified in the
environment variables jirauser and jirpass.

If no environment variables set will prompt interactively for entry of user and password

=over

=head1 COPYRIGHT

Copyright 2016-2021 CPQD.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Gustavo Chaves <gustavo@cpqd.com.br>