Config-Identity

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Config-Identity

0.0019    2016-11-19 22:55:59-05:00 America/New_York
    - DAGOLDEN joined as maintainer
    - Attemped test bug fix for rt.cpan.org#112569 (fails with newer gpg)
    - SYNOPSIS fixed
    - Added a generic "load_check" method to Config::Identity for simple
      use cases that don't really need subclassing
    - Replaces a die() call with croak() for consistency

0.0018 Saturday March 01 13:40:31 PST 2014:
    - Be more sane with how we interact with gpg
 
0.0017 Saturday March 01 11:12:09 PST 2014:
    - Use IPC::Run instead of IPC::Open3

0.0016 Wednesday June 16 23:26:25 PDT 2010:
    - Added CI_PAUSE_STUB/CI_GITHUB_STUB override

0.0015 Tuesday June 08 15:57:29 PDT 2010:
    - Added username/user aliasing to the PAUSE format (and loader)

0.0014 Wednesday June 02 20:23:51 PDT 2010:
    - Changed load_best to try_best and added a stricter load_best

0.0013 2010-06-12:
    - Surpress secmem warning during testing
    - Added documentation about CI_{GPG/CI_GPG_ARGUMENTS}
    - Put in information about using gpg-agent
    
0.0012 Tuesday May 11 23:59:01 PDT 2010:
    - Updated documentation

0.0010 Tuesday May 11 18:32:09 PDT 2010:
    - Initial release

MANIFEST  view on Meta::CPAN

cpanfile
dist.ini
lib/Config/Identity.pm
lib/Config/Identity/GitHub.pm
lib/Config/Identity/PAUSE.pm
perlcritic.rc
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/01-basic.t
t/assets/github/.github
t/assets/gpg/pubring.gpg
t/assets/gpg/secring.gpg
t/assets/gpg/trustdb.gpg
t/assets/h0/.test
t/assets/h0/.test-identity
t/assets/h1/.test
t/assets/pause-username/.pause-identity
t/assets/pause/.pause-alternate
t/assets/pause/.pause-identity
t/assets/test.asc
t/assets/test.gpg
xt/author/00-compile.t
xt/author/critic.t
xt/author/pod-spell.t
xt/author/pod-syntax.t
xt/author/test-version.t
xt/release/distmeta.t
xt/release/minimum-version.t

README  view on Meta::CPAN


  %identity = Config::Identity->load_check( <stub>, <checker> )
    Works like "load_best" but also checks for required keys. The "checker"
    argument must be an array reference of required keys or a code reference
    that takes a hashref of key/value pairs from the identity file and
    returns a list of missing keys. For convenience, the hashref will also
    be placed in $_.

    If any keys are found missing, the method croaks.

Using a custom "gpg" or passing custom arguments
    You can specify a custom "gpg" executable by setting the CI_GPG
    environment variable

        export CI_GPG="$HOME/bin/gpg"

    You can pass custom arguments by setting the CI_GPG_ARGUMENTS
    environment variable

        export CI_GPG_ARGUMENTS="--no-secmem-warning"

Encrypting your identity information with GnuPG
    If you've never used GnuPG before, first initialize it:

        # Follow the prompts to create a new key for yourself
        gpg --gen-key

    To encrypt your GitHub identity with GnuPG using the above key:

        # Follow the prompts, using the above key as the "recipient"
        # Use ^D once you've finished typing out your authentication information
        gpg -ea > $HOME/.github

Caching your GnuPG secret key via gpg-agent
    Put the following in your .*rc

        if which gpg-agent 1>/dev/null
        then
            if test -f $HOME/.gpg-agent-info && \
                kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null
            then
                . "${HOME}/.gpg-agent-info"
                export GPG_AGENT_INFO
            else
                eval `gpg-agent --daemon --write-env-file "${HOME}/.gpg-agent-info"`
            fi
        else
        fi

PAUSE identity format
        user <user>
        password <password>

    "username" can also be used as alias for "user"

dist.ini  view on Meta::CPAN

match     = ^t/assets/

[@DAGOLDEN]
:version = 0.072
github_issues = 0
no_coverage = 1
-remove = Test::Portability
Git::GatherDir.exclude_match = ^t/assets
stopwords = GnuPG
stopwords = decrypt
stopwords = gpg

; Assets must be gathered with dotfiles
[Git::GatherDir / GatherAssets]
root = t/assets
prefix = t/assets
include_dotfiles = 1

lib/Config/Identity.pm  view on Meta::CPAN


our $VERSION = '0.0019';

use Carp;
use IPC::Run qw/ start finish /;
use File::HomeDir();
use File::Spec;

our $home = File::HomeDir->home;
{
    my $gpg;
    sub GPG() { $ENV{CI_GPG} || ( $gpg ||= do {
        require File::Which;
        $gpg = File::Which::which( $_ ) and last for qw/ gpg gpg2 /;
        $gpg;
    } ) }
}
sub GPG_ARGUMENTS() { $ENV{CI_GPG_ARGUMENTS} || '' }

# TODO Do not even need to do this, since the file is on disk already...
sub decrypt {
    my $self = shift;
    my $file = shift;

    my $gpg = GPG or croak "Missing gpg";
    my $gpg_arguments = GPG_ARGUMENTS;
    my $run;
    # Old versions, please ignore
    #$run = "$gpg $gpg_arguments -qd --no-tty --command-fd 0 --status-fd 1";
    #$run = "$gpg $gpg_arguments -qd --no-tty --command-fd 0";
    $run = "$gpg $gpg_arguments -qd --no-tty";
    my @run = split m/\s+/, $run;
    push @run, $file;
    my $process = start( \@run, '>pipe', \*OUT, '2>pipe', \*ERR );
    my $output = join '', <OUT>;
    my $_error = join '', <ERR>;
    finish $process;
    return ( $output, $_error );
}

sub best {

lib/Config/Identity.pm  view on Meta::CPAN

=head2 %identity = Config::Identity->load_check( <stub>, <checker> )

Works like C<load_best> but also checks for required keys.  The C<checker>
argument must be an array reference of B<required> keys or a code reference
that takes a hashref of key/value pairs from the identity file and returns
a list of B<missing> keys.  For convenience, the hashref will also be
placed in C<$_>.

If any keys are found missing, the method croaks.

=head1 Using a custom C<gpg> or passing custom arguments

You can specify a custom C<gpg> executable by setting the CI_GPG environment variable

    export CI_GPG="$HOME/bin/gpg"

You can pass custom arguments by setting the CI_GPG_ARGUMENTS environment variable

    export CI_GPG_ARGUMENTS="--no-secmem-warning"

=head1 Encrypting your identity information with GnuPG

If you've never used GnuPG before, first initialize it:

    # Follow the prompts to create a new key for yourself
    gpg --gen-key 

To encrypt your GitHub identity with GnuPG using the above key:

    # Follow the prompts, using the above key as the "recipient"
    # Use ^D once you've finished typing out your authentication information
    gpg -ea > $HOME/.github

=head1 Caching your GnuPG secret key via gpg-agent

Put the following in your .*rc

    if which gpg-agent 1>/dev/null
    then
        if test -f $HOME/.gpg-agent-info && \
            kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null
        then
            . "${HOME}/.gpg-agent-info"
            export GPG_AGENT_INFO
        else
            eval `gpg-agent --daemon --write-env-file "${HOME}/.gpg-agent-info"`
        fi
    else
    fi

=head1 PAUSE identity format

    user <user>
    password <password>

C<username> can also be used as alias for C<user>

t/01-basic.t  view on Meta::CPAN

        cmp_deeply( $_, $expected, "checker sub has expected fields in \$_" );
        return "notfound1"; # fake error
    };

    eval { Config::Identity->load_check('pause-alternate', $checker) };
    like( $@, qr/^Missing required field: notfound1/, "load_check detected missing field (from checker sub)" );

}

SKIP: {
    skip 'GnuPG not available' unless my $gpg = Config::Identity->GPG;

    my $homedir = File::Spec->catfile(qw/ t assets gpg /);

    # Per https://rt.cpan.org/Public/Bug/Display.html?id=112569 gpg 2.1.x
    # needs a key format migration run on test data before tests
    {
        my $gpg_v = qx/$gpg --version/;
        my ($first,$second) = $gpg_v =~ /^gpg \s+ \([^)]+\) \s+ (\d+) \. (\d+)/mx;
        if ( $first && $second && ($first > 2 || ($first == 2 && $second > 0))) {
            qx/$gpg --homedir $homedir --list-secret-keys/;
        }
    }

    $ENV{CI_GPG_ARGUMENTS} =
        '--no-secmem-warning ' .
        '--no-permission-warning ' .
        '--homedir ' . $homedir
    ;

    is( Config::Identity->read( File::Spec->catfile(qw/ t assets test.asc /) ), <<_END_ );
1234567890xyzzy

# 123
_END_

    if ($ENV{RELEASE_TESTING}) {
        is( Config::Identity->read( File::Spec->catfile(qw/ t assets test.gpg /) ), <<_END_ );
ABCDEFGHIJKLMNOPQRSTUVWXYZ

1 2 3 4 5 6 7 8 9 0

.
_END_
    }

    use Config::Identity::GitHub;
    {

xt/author/pod-spell.t  view on Meta::CPAN

David
GitHub
GnuPG
Golden
Identity
Krimen
PAUSE
Robert
dagolden
decrypt
gpg
lib
robertkrimen



( run in 0.704 second using v1.01-cache-2.11-cpan-e1769b4cff6 )