AWS-CLI-Config

 view release on metacpan or  search on metacpan

lib/AWS/CLI/Config.pm  view on Meta::CPAN

        my $credentials = credentials($profile);
        if ($credentials && $credentials->$profile_key) {
            return $credentials->$profile_key;
        }

        my $config = config($profile);
        if ($config && $config->$profile_key) {
            return $config->$profile_key;
        }

        return undef;
    };
}

sub credentials {
    my $profile = shift || _default_profile();

    $CREDENTIALS ||= _parse(
        (exists $ENV{AWS_CONFIG_FILE} and $ENV{AWS_CONFIG_FILE})
            ? $ENV{AWS_CONFIG_FILE}
            : File::Spec->catfile(_default_dir(), 'credentials')

lib/AWS/CLI/Config.pm  view on Meta::CPAN

    my $file = shift;
    my $profile = shift || _default_profile();

    my $hash = {};
    my $nested = {};

    return +{} unless -r $file;

    my $contents;
    {
        local $/  = undef;
        open my $fh, '<', $file;
        $contents = <$fh>;
        close( $fh );
    }

    foreach my $line (split /\n/, $contents) {
        chomp $line;

        $profile = $1 if $line =~ /^\[(?:profile )?([\w]+)\]/;
        my ($indent, $key, $value) = $line =~ /^(\s*)([\w]+)\s*=\s*(.*)/;

t/02_access_key_id.t  view on Meta::CPAN


use AWS::CLI::Config;

subtest 'Environment Variable' => sub {
    local $ENV{AWS_ACCESS_KEY_ID} = '__dummy__';
    is(AWS::CLI::Config::access_key_id, $ENV{AWS_ACCESS_KEY_ID}, 'set by env');
};

subtest 'From credentials file' => sub {
    my $access_key_id = q[It's me.];
    undef local $ENV{AWS_ACCESS_KEY_ID};
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return AWS::CLI::Config::Profile->new({
                aws_access_key_id => $access_key_id,
            });
    };
    is(AWS::CLI::Config::access_key_id, $access_key_id, 'set by credentials');
};

subtest 'From config file' => sub {
    my $access_key_id = q[It's me.];
    undef local $ENV{AWS_ACCESS_KEY_ID};
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return undef;
    };
    *AWS::CLI::Config::config = sub {
        return AWS::CLI::Config::Profile->new({
                aws_access_key_id => $access_key_id,
            });
    };
    is(AWS::CLI::Config::access_key_id, $access_key_id, 'set by config');
};

done_testing;

t/03_output.t  view on Meta::CPAN

            });
    };
    is(AWS::CLI::Config::output, $output, 'set by credentials');
};

subtest 'From config file' => sub {
    my $output = '__format__';
    no strict 'refs';
    no warnings 'redefine';
    *AWS::CLI::Config::credentials = sub {
        return undef;
    };
    *AWS::CLI::Config::config = sub {
        return AWS::CLI::Config::Profile->new({
                output => $output,
            });
    };
    is(AWS::CLI::Config::output, $output, 'set by config');
};

done_testing;

t/04_config.t  view on Meta::CPAN

subtest 'Specific profile' => sub {
    my $config = AWS::CLI::Config::config('tester');

    is($config->aws_access_key_id, $tester_access_key_id, 'access_key_id');
    is($config->aws_secret_access_key, $tester_secret_access_key, 'secret_access_key');
    is($config->s3->{addressing_style}, 'path', 'nested value');
};

subtest 'Undefined profile' => sub {
    my $config = AWS::CLI::Config::config('no-such-profile');
    ok(!$config, 'undefined');
};

done_testing;

__END__
# vi: set ts=4 sw=4 sts=0 et ft=perl fenc=utf-8 ff=unix :



( run in 3.597 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )