API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/API/Plugins.pm view on Meta::CPAN
my $remote = $opts{remote} // $name;
my $privileges = $self->_privileges_body('upgrade', $remote, %opts);
return $self->client->post("/plugins/$name/upgrade", $privileges,
params => { remote => $remote },
$self->_auth_headers(\%opts),
%{ $self->_request_options },
exists $opts{on_event} ? ( on_event => $opts{on_event} ) : ( ndjson => 1 ),
);
}
sub push {
my ($self, $name, %opts) = @_;
croak __PACKAGE__ . '->push plugin name required' unless $name;
return $self->client->post("/plugins/$name/push", undef,
$self->_auth_headers(\%opts),
%{ $self->_request_options },
exists $opts{on_event} ? ( on_event => $opts{on_event} ) : ( ndjson => 1 ),
);
}
sub configure {
my ($self, $name, @settings) = @_;
croak __PACKAGE__ . '->configure plugin name required' unless $name;
# One ArrayRef or a plain list, and nothing after either: this method reads
# no options at all. The ArrayRef form used to be where the transport bounds
# went, because a trailing `read_timeout => 2` in the plain list would be two
# more settings as far as this method can tell -- they now go on the resource
# class instead (karr k74), and what is left is a form, not a split.
if (ref $settings[0] eq 'ARRAY') {
my $list = shift @settings;
croak __PACKAGE__ . '->configure takes nothing after the ArrayRef of '
. 'settings; a transport bound goes on the resource class, as '
. '$docker->plugins->using(read_timeout => 5)->configure(...)'
if @settings;
@settings = @$list;
}
croak __PACKAGE__ . '->configure requires at least one setting, as an '
. 'ArrayRef or a list of "KEY=value" strings' unless @settings;
croak __PACKAGE__ . '->configure settings must be plain strings'
if grep { ref $_ } @settings;
return $self->client->post("/plugins/$name/set", \@settings,
%{ $self->_request_options },
);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
API::Docker::API::Plugins - Docker Engine Plugins API
=head1 VERSION
version 0.004
=head1 SYNOPSIS
my $docker = API::Docker->new;
# List installed plugins
my $plugins = $docker->plugins->list;
# Install: look at what the plugin demands, then grant exactly that
my $privileges = $docker->plugins->privileges('vieux/sshfs:latest');
$docker->plugins->install('vieux/sshfs:latest',
privileges => $privileges,
);
$docker->plugins->enable('vieux/sshfs:latest');
# Inspect
my $plugin = $docker->plugins->inspect('vieux/sshfs:latest');
say $plugin->name, $plugin->enabled ? ' (enabled)' : ' (disabled)';
# Configure, upgrade, disable, remove
$docker->plugins->configure('vieux/sshfs:latest', ['DEBUG=1']);
$docker->plugins->upgrade('vieux/sshfs:latest', privileges => $privileges);
$docker->plugins->disable('vieux/sshfs:latest');
$docker->plugins->remove('vieux/sshfs:latest');
=head1 DESCRIPTION
This module provides access to the Docker managed-plugin endpoints
(C</plugins>).
Accessed via C<< $docker->plugins >>, or through
L<API::Docker::Role::Using/using> for a run of calls that needs its own
transport bound: C<< $docker->plugins->using(read_timeout => 5) >>.
=head2 Installing is two calls, and the engine enforces it
C<< POST /plugins/pull >> takes the list of privileges the plugin demands
B<in its request body>, and the daemon compares that list against the one it
computes from the plugin's own config. They must match exactly -- same
length, same names, same values -- or the install fails with
C<incorrect privileges>. A plugin runs with the host access it asked for, so
the round trip exists to make somebody look at that access before granting
it.
L</privileges> is the first call, L</install> the second:
my $privileges = $docker->plugins->privileges('vieux/sshfs:latest');
# inspect $privileges here -- it is an ArrayRef of
# { Name => 'network', Description => '...', Value => ['host'] }
$docker->plugins->install('vieux/sshfs:latest', privileges => $privileges);
C<install> B<requires> C<privileges> and croaks without it, which is stricter
( run in 0.506 second using v1.01-cache-2.11-cpan-02e1dfdd527 )