File Coverage

blib/lib/Eixo/Docker/Api.pm
Criterion Covered Total %
statement 12 31 38.7
branch 0 14 0.0
condition 0 5 0.0
subroutine 4 11 36.3
pod 0 6 0.0
total 16 67 23.8


line stmt bran cond sub pod time code
1             package Eixo::Docker::Api;
2              
3 12     12   410805 use strict;
  12         28  
  12         332  
4 12     12   92 use warnings;
  12         25  
  12         390  
5 12     12   8989 use Eixo::Base::Clase qw(Eixo::Rest::Api);
  12         179312  
  12         63  
6              
7 12     12   2238753 use Eixo::Docker::EventRegister;
  12         34  
  12         5923  
8              
9             my $CERT_PATH = $ENV{DOCKER_CERT_PATH} || '';
10              
11             has(
12             host => $ENV{DOCKER_HOST},
13             tls_verify => $ENV{DOCKER_TLS_VERIFY},
14             ca_file => $CERT_PATH.'/ca.pem',
15             cert_file => $CERT_PATH.'/cert.pem',
16             key_file => $CERT_PATH.'/key.pem',
17             );
18              
19             sub initialize {
20 0     0 0   my ($self, @args) = @_;
21              
22 0 0         if(@args % 2 == 1){
23              
24             # if pass an odd number of args in new
25             # firt one must be the docker host
26 0           $self->host(shift(@args));
27              
28             # rest of initialization has to be manual
29             #
30 0           my %args = @args;
31              
32 0           while(my ($key, $val) = each(%args)){
33 0           $self->$key($val);
34             }
35             }
36              
37 0           my ($proto,$host) = split '://', $self->host;
38              
39 0 0 0       ($host = $proto and $proto = undef) unless($host);
40            
41 0 0 0       if(!$proto || $proto eq 'tcp'){
42              
43 0 0         $proto = ($self->tls_verify)? 'https' : 'http';
44            
45             }
46              
47              
48             $self->SUPER::initialize(
49            
50 0 0         "$proto://$host",
51              
52             ssl_opts => {
53             ($proto eq 'https')?
54             (
55             SSL_use_cert => 1,
56             verify_hostname => 1,
57             SSL_ca_file => $self->ca_file,
58             SSL_cert_file => $self->cert_file,
59             SSL_key_file => $self->key_file
60              
61             ):()
62             }
63             )
64              
65             }
66              
67             sub containers {
68 0 0   0 0   $_[0]->produce(
69              
70             ($_[0]->__legacy)?
71             'Eixo::Docker::ContainerLegacy':
72             'Eixo::Docker::Container'
73              
74             );
75             }
76              
77             sub images {
78 0     0 0   $_[0]->produce('Eixo::Docker::Image');
79             }
80              
81             sub version{
82 0     0 0   $_[0]->produce('Eixo::Docker::Version');
83             }
84              
85             sub events{
86 0     0 0   $_[0]->produce('Eixo::Docker::Events');
87             }
88              
89             sub eventPool{
90 0     0 0   my ($self) = @_;
91            
92 0 0         return $self->{ev} if($self->{ev});
93              
94 0           $self->{ev} = Eixo::Docker::EventRegister->new(
95              
96             $self,
97              
98            
99             );
100             }
101              
102             sub __legacy {
103 0     0     $_[0]->version->get->ApiVersion <= 1.19
104             }
105              
106             1;