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   405674 use strict;
  12         28  
  12         331  
4 12     12   61 use warnings;
  12         25  
  12         388  
5 12     12   9106 use Eixo::Base::Clase qw(Eixo::Rest::Api);
  12         167025  
  12         59  
6              
7 12     12   2178076 use Eixo::Docker::EventRegister;
  12         32  
  12         5697  
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){
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              
29             }
30            
31             # rest of initialization has to be manual
32 0           my %args = @args;
33            
34 0           while(my ($key, $val) = each(%args)){
35 0           $self->$key($val);
36             }
37              
38 0           my ($proto, $host) = split ('://', $self->host);
39            
40              
41 0 0 0       ($host = $proto and $proto = undef) unless($host);
42            
43 0 0 0       if(!$proto || $proto eq 'tcp'){
44              
45 0 0         $proto = ($self->tls_verify)? 'https' : 'http';
46            
47             }
48              
49              
50             $self->SUPER::initialize(
51            
52 0 0         "$proto://$host",
53              
54             ssl_opts => {
55             ($proto eq 'https')?
56             (
57             SSL_use_cert => 1,
58             verify_hostname => 1,
59             SSL_ca_file => $self->ca_file,
60             SSL_cert_file => $self->cert_file,
61             SSL_key_file => $self->key_file
62              
63             ):()
64             }
65             )
66              
67             }
68              
69             sub containers {
70 0 0   0 0   $_[0]->produce(
71              
72             ($_[0]->__legacy)?
73             'Eixo::Docker::ContainerLegacy':
74             'Eixo::Docker::Container'
75              
76             );
77             }
78              
79             sub images {
80 0     0 0   $_[0]->produce('Eixo::Docker::Image');
81             }
82              
83             sub version{
84 0     0 0   $_[0]->produce('Eixo::Docker::Version');
85             }
86              
87             sub events{
88 0     0 0   $_[0]->produce('Eixo::Docker::Events');
89             }
90              
91             sub eventPool{
92 0     0 0   my ($self) = @_;
93            
94 0 0         return $self->{ev} if($self->{ev});
95              
96 0           $self->{ev} = Eixo::Docker::EventRegister->new(
97              
98             $self,
99              
100            
101             );
102             }
103              
104             sub __legacy {
105 0     0     $_[0]->version->get->ApiVersion <= 1.19
106             }
107              
108             1;