Artifactory-Client
view release on metacpan or search on metacpan
lib/Artifactory/Client.pm view on Meta::CPAN
is => 'ro',
isa => 'Str',
init_arg => undef,
writer => '_set_art_url',
);
sub BUILD {
my ($self) = @_;
# Save URIs
my $uri = URI->new( $self->artifactory() );
$uri->port( $self->port );
my $context_root = $self->context_root();
$context_root = '' if ( $context_root eq '/' );
$uri->path_segments( $context_root, );
my $_art_url = $uri->canonical()->as_string();
$_art_url =~ s{\/$}{}xi;
$self->_set_art_url($_art_url);
$uri->path_segments( $context_root, 'api' );
$self->_set_api_url( $uri->canonical()->as_string() );
# Save Repository
my $repo = $self->repository;
$repo =~ s{^\/}{}xi;
$repo =~ s{\/$}{}xi;
$self->_set_repository($repo);
return 1;
}
=head1 GENERIC METHODS
=cut
=head2 get( @args )
Invokes GET request on LWP::UserAgent-like object; params are passed through.
=cut
sub get {
my ( $self, @args ) = @_;
return $self->_request( 'get', @args );
}
=head2 post( @args )
nvokes POST request on LWP::UserAgent-like object; params are passed through.
=cut
sub post {
my ( $self, @args ) = @_;
return $self->_request( 'post', @args );
}
=head2 put( @args )
Invokes PUT request on LWP::UserAgent-like object; params are passed through.
=cut
sub put {
my ( $self, @args ) = @_;
return $self->_request( 'put', @args );
}
=head2 delete( @args )
Invokes DELETE request on LWP::UserAgent-like object; params are passed
through.
=cut
sub delete {
my ( $self, @args ) = @_;
return $self->_request( 'delete', @args );
}
=head2 request( @args )
Invokes request() on LWP::UserAgent-like object; params are passed through.
=cut
sub request {
my ( $self, @args ) = @_;
return $self->_request( 'request', @args );
}
=head1 BUILDS
=cut
=head2 all_builds
Retrieves information on all builds from artifactory.
=cut
sub all_builds {
my $self = shift;
return $self->_get_build('');
}
=head2 build_runs( $build_name )
Retrieves information of a particular build from artifactory.
=cut
sub build_runs {
my ( $self, $build ) = @_;
return $self->_get_build($build);
}
=head2 build_upload( $path_to_json )
Upload Build
lib/Artifactory/Client.pm view on Meta::CPAN
Takes path and traces artifact retrieval
=cut
sub trace_artifact_retrieval {
my ( $self, $path ) = @_;
$path = $self->_merge_repo_and_path($path);
my $url = $self->_art_url() . "/$path?trace";
return $self->get($url);
}
=head2 archive_entry_download( $path, $archive_path )
Takes path and archive_path, retrieves an archived resource from the specified archive destination.
=cut
sub archive_entry_download {
my ( $self, $path, $archive_path ) = @_;
$path = $self->_merge_repo_and_path($path);
my $url = $self->_art_url() . "/$path!$archive_path";
return $self->get($url);
}
=head2 create_directory( path => $path, properties => { key => [ values ] } )
Takes path, properties then create a directory. Directory needs to end with a /, such as "/some_dir/".
=cut
sub create_directory {
my ( $self, %args ) = @_;
return $self->deploy_artifact(%args);
}
=head2 deploy_artifact( path => $path, properties => { key => [ values ] }, file => $file )
Takes path on Artifactory, properties and filename then deploys the file. Note that properties are a hashref with
key-arrayref pairs, such as:
$prop = { key1 => ['a'], key2 => ['a', 'b'] }
=cut
sub deploy_artifact {
my ( $self, %args ) = @_;
my $path = $args{path};
my $properties = $args{properties};
my $file = $args{file};
my $header = $args{header};
$path = $self->_merge_repo_and_path($path);
my @joiners = ( $self->_art_url() . "/$path" );
my $props = $self->_attach_properties( properties => $properties, matrix => 1 );
push @joiners, $props if ($props); # if properties aren't passed in, the function returns empty string
my $url = join( ";", @joiners );
my $req = HTTP::Request::StreamingUpload->new(
PUT => $url,
headers => HTTP::Headers->new( %{$header} ),
( $file ? ( fh => Path::Tiny::path($file)->openr_raw() ) : () ),
);
return $self->request($req);
}
=head2 deploy_artifact_by_checksum( path => $path, properties => { key => [ values ] }, file => $file, sha1 => $sha1 )
Takes path, properties, filename and sha1 then deploys the file. Note that properties are a hashref with key-arrayref
pairs, such as:
$prop = { key1 => ['a'], key2 => ['a', 'b'] }
=cut
sub deploy_artifact_by_checksum {
my ( $self, %args ) = @_;
my $sha1 = $args{sha1};
my $header = {
'X-Checksum-Deploy' => 'true',
'X-Checksum-Sha1' => $sha1,
};
$args{header} = $header;
return $self->deploy_artifact(%args);
}
=head2 deploy_artifacts_from_archive( path => $path, file => $file )
Path is the path on Artifactory, file is path to local archive. Will deploy $file to $path.
=cut
sub deploy_artifacts_from_archive {
my ( $self, %args ) = @_;
my $header = { 'X-Explode-Archive' => 'true', };
$args{header} = $header;
return $self->deploy_artifact(%args);
}
=head2 push_a_set_of_artifacts_to_bintray( descriptor => 'foo', gpgPassphrase => 'top_secret', gpgSign => 'true' )
Push a set of artifacts to Bintray as a version. Uses a descriptor file (that must have 'bintray-info' in it's filename
and a .json extension) that was deployed to artifactory, the call accepts the full path to the descriptor as a
parameter.
=cut
sub push_a_set_of_artifacts_to_bintray {
my ( $self, %args ) = @_;
my $url = $self->_api_url() . "/bintray/push";
my $params = $self->_stringify_hash( '&', %args );
$url .= "?" . $params if ($params);
return $self->post($url);
}
=head2 push_docker_tag_to_bintray( dockerImage => 'jfrog/ubuntu:latest', async => 'true', ... )
( run in 0.574 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )