Artifactory-Client

 view release on metacpan or  search on metacpan

lib/Artifactory/Client.pm  view on Meta::CPAN


=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', ... )

Push Docker tag to Bintray.  Calculation can be synchronous (the default) or asynchronous.  You will need to enter your
Bintray credentials, for more details, please refer to Entering your Bintray credentials.

=cut

sub push_docker_tag_to_bintray {
    my ( $self, %args ) = @_;

    my $url = $self->_api_url() . '/bintray/docker/push/' . $self->repository();
    return $self->post(
        $url,
        "Content-Type" => 'application/json',
        Content        => $self->_json->encode( \%args )
    );
}

=head2 distribute_artifact( publish => 'true', async => 'false' )

Deploys artifacts from Artifactory to Bintray, and creates an entry in the corresponding Artifactory distribution
repository specified

=cut

sub distribute_artifact {
    my ( $self, %args ) = @_;

    my $url = $self->_api_url() . '/distribute';
    return $self->post(
        $url,
        "Content-Type" => 'application/json',
        Content        => $self->_json->encode( \%args )
    );
}

=head2 file_compliance_info( $path )

Retrieves file compliance info of a given path.

=cut

sub file_compliance_info {
    my ( $self, $path ) = @_;

lib/Artifactory/Client.pm  view on Meta::CPAN

Deletes an Artifactory permission target

=cut

sub delete_permission_target {
    my ( $self, $name ) = @_;
    return $self->_handle_security( $name, 'delete', 'permissions' );
}

=head2 effective_item_permissions( $path )

Returns a list of effective permissions for the specified item (file or folder)

=cut

sub effective_item_permissions {
    my ( $self, $arg ) = @_;

    my $path = $self->_merge_repo_and_path($arg);
    my $url  = $self->_api_url() . "/storage/$path?permissions";
    return $self->get($url);
}

=head2 security_configuration

Retrieve the security configuration (security.xml)

=cut

sub security_configuration {
    my ( $self, $path ) = @_;

    my $url = $self->_api_url() . "/system/security";
    return $self->get($url);
}

=head2 activate_master_key_encryption

Creates a new master key and activates master key encryption

=cut

sub activate_master_key_encryption {
    my $self = shift;
    my $url  = $self->_api_url() . "/system/encrypt";
    return $self->post($url);
}

=head2 deactivate_master_key_encryption

Removes the current master key and deactivates master key encryption

=cut

sub deactivate_master_key_encryption {
    my $self = shift;
    my $url  = $self->_api_url() . "/system/decrypt";
    return $self->post($url);
}

=head2 set_gpg_public_key( key => $string )

Sets the public key that Artifactory provides to Debian clients to verify packages

=cut

sub set_gpg_public_key {
    my ( $self, %args ) = @_;
    my $key = $args{key};
    return $self->_handle_gpg_key( 'public', 'put', content => $key );
}

=head2 get_gpg_public_key

Gets the public key that Artifactory provides to Debian clients to verify packages

=cut

sub get_gpg_public_key {
    my $self = shift;
    return $self->_handle_gpg_key( 'public', 'get' );
}

=head2 set_gpg_private_key( key => $string )

Sets the private key that Artifactory will use to sign Debian packages

=cut

sub set_gpg_private_key {
    my ( $self, %args ) = @_;
    my $key = $args{key};
    return $self->_handle_gpg_key( 'private', 'put', content => $key );
}

=head2 set_gpg_pass_phrase( $passphrase )

Sets the pass phrase required signing Debian packages using the private key

=cut

sub set_gpg_pass_phrase {
    my ( $self, $pass ) = @_;
    return $self->_handle_gpg_key( 'passphrase', 'put', 'X-GPG-PASSPHRASE' => $pass );
}

=head2 create_token( username => 'johnq', scope => 'member-of-groups:readers' )

Creates an access token

=cut

sub create_token {
    my ( $self, %data ) = @_;
    my $url = $self->_api_url() . "/security/token";
    return $self->post( $url, content => \%data );
}

=head2 refresh_token( grant_type => 'refresh_token', refresh_token => 'fgsg53t3g' )

Refresh an access token to extend its validity. If only the access token and the refresh token are provided (and no
other parameters), this pair is used for authentication. If username or any other parameter is provided, then the
request must be authenticated by a token that grants admin permissions.

=cut

sub refresh_token {
    my ( $self, %data ) = @_;
    return $self->create_token(%data);
}

=head2 revoke_token( token => 'fgsg53t3g' )

Revoke an access token

=cut

sub revoke_token {
    my ( $self, %data ) = @_;
    my $url = $self->_api_url() . "/security/token/revoke";
    return $self->post( $url, content => \%data );
}

=head2 get_service_id

Provides the service ID of an Artifactory instance or cluster

=cut

sub get_service_id {
    my $self = shift;
    my $url  = $self->_api_url() . "/system/service_id";
    return $self->get($url);
}

=head2 get_certificates

Returns a list of installed SSL certificates.

=cut

sub get_certificates {
    my $self = shift;
    my $url  = $self->_api_url() . "/system/security/certificates";

lib/Artifactory/Client.pm  view on Meta::CPAN

    return $self->$method($url);
}

sub _handle_repositories {
    my ( $self, $repo, $payload, $method, %args ) = @_;

    $repo =~ s{^\/}{}xi;
    $repo =~ s{\/$}{}xi;

    my $url =
      (%args)
      ? $self->_api_url() . "/repositories/$repo?"
      : $self->_api_url() . "/repositories/$repo";
    $url .= $self->_stringify_hash( '&', %args ) if (%args);

    if ($payload) {
        return $self->$method(
            $url,
            'Content-Type' => 'application/json',
            content        => $self->_json->encode($payload)
        );
    }
    return $self->$method($url);
}

sub _handle_system {
    my ( $self, $arg ) = @_;

    my $url =
      ($arg)
      ? $self->_api_url() . "/system/$arg"
      : $self->_api_url() . "/system";
    return $self->get($url);
}

sub _handle_plugins {
    my ( $self, $type ) = @_;

    my $url =
      ($type)
      ? $self->_api_url() . "/plugins/$type"
      : $self->_api_url() . "/plugins";
    return $self->get($url);
}

sub _handle_system_settings {
    my ( $self, $action, %args ) = @_;

    my $url = $self->_api_url() . "/$action/system";

    if (%args) {
        return $self->post(
            $url,
            'Content-Type' => 'application/json',
            content        => $self->_json->encode( \%args )
        );
    }
    return $self->get($url);
}

sub _handle_gpg_key {
    my ( $self, $type, $method, %args ) = @_;
    my $url = $self->_api_url() . "/gpg/key/$type";
    return $self->$method( $url, %args );
}

sub _handle_repository_reindex {
    my ( $self, $endpoint, %args ) = @_;
    my $url =
      (%args)
      ? $self->_api_url() . $endpoint . "?"
      : $self->_api_url() . $endpoint;
    $url .= $self->_stringify_hash( '&', %args ) if (%args);
    return $self->post($url);
}

sub _handle_multi_push_replication {
    my ( $self, $payload, $method ) = @_;

    my $url = $self->_api_url() . '/replications/multiple';
    return $self->$method(
        $url,
        "Content-Type" => 'application/json',
        Content        => $self->_json->encode($payload)
    );
}

sub _merge_repo_and_path {
    my ( $self, $_path ) = @_;

    $_path = '' if not defined $_path;
    $_path =~ s{^\/}{}xi;

    return join( '/', grep { $_ } $self->repository(), $_path );
}

sub _gather_delete_builds_params {
    my ( $self, $buildnumbers, $artifacts, $deleteall ) = @_;

    my @params;
    if ( ref($buildnumbers) eq 'ARRAY' ) {
        my $str = "buildNumbers=";
        $str .= join( ",", @{$buildnumbers} );
        push @params, $str;
    }
    push @params, "artifacts=$artifacts" if ( defined $artifacts );
    push @params, "deleteAll=$deleteall" if ( defined $deleteall );
    return @params;
}

sub _handle_api_key {
    my ( $self, $method, %args ) = @_;

    my $url = $self->_api_url() . "/apiKey/auth";
    return $self->$method(
        $url,
        'Content-Type' => 'application/json',
        content        => $self->_json->encode( \%args )
    );
}

sub _handle_revoke_api_key {
    my ( $self, $endpoint ) = @_;



( run in 1.510 second using v1.01-cache-2.11-cpan-e1769b4cff6 )