Artifactory-Client

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.4.0   2017/2/8
        Added 5.0.0 calls

1.3.1   2017/1/11
        Added verify_connection call, created .gitignore file to ignore carton files & snapshot

1.3.0   2016/9/28
        Added cpanfile for carton

1.2.0   2016/8/10
        Added repository overrides for the rest of method calls that have repository as part of endpoint

1.1.8   2016/8/9
        Adding repository override via cmdline param for some methods

1.1.7   2016/7/11
        Added distribute_build while deprecating push_build_to_bintray

1.1.6   2016/7/2
        Adding Makefile.PL in MANIFEST

1.1.5   2016/6/28
        Added 4.8 endpoints

1.1.4   2016/5/10
        Added 4.7.5 endpoints

1.1.3   2016/4/26
        Added 4.7.2 endpoints

1.1.2   2016/4/3
        Fixing up dependencies in Makefile.PL

1.1.1   2016/4/2
        Switching back from Module::Build to ExtUtils::MakeMaker as Module::Build has been removed from the core

1.1.0   2016/4/1
        Added API calls up to 4.6.0

README.md  view on Meta::CPAN

    };
    my $file = '/local/file.xml';

    # Name of methods are taken straight from Artifactory REST API documentation.  'Deploy Artifact' would map to
    # deploy_artifact method, like below.  The caller gets HTTP::Response object back.
    my $resp = $client->deploy_artifact( path => $path, properties => $properties, file => $file );

    # Custom requests can also be made via usual get / post / put / delete requests.
    my $resp = $client->get( 'http://artifactory.server.com/path/to/resource' );

    # Repository override for calls that have a repository in the endpoint.  The passed-in repository will not persist.
    my $resp = $client->calculate_yum_repository_metadata( repository => 'different_repo', async => 1 );

# Dev Env Setup / Running Tests

    carton install

    # to run unit tests
    prove -r t

# GENERIC METHODS

README.md  view on Meta::CPAN

## calculate\_conda\_repository\_metadata

Calculates/recalculates the Conda packages and release metadata for this repository.

# SYSTEM & CONFIGURATION

## system\_info

Get general system information

## verify\_connection( endpoint => 'http://server/foobar', username => 'admin', password => 'password' )

Verifies a two-way connection between Artifactory and another product

## system\_health\_ping

Get a simple status response about the state of Artifactory

## general\_configuration

Get the general configuration (artifactory.config.xml)

README.md  view on Meta::CPAN

## export\_system\_settings\_example

Returned default Export Settings JSON

## export\_system( exportPath => '/export/path', includeMetadata => 'true' etc )

Export full system to a server local directory

## ignore\_xray\_alert( $path )

Sets an alert to be ignored until next time the repository hosting the artifact about which the alert was issued, is scanned. Note that this endpoint does not
affect artifacts that are blocked because they have not been scanned at all.

## allow\_download\_of\_blocked\_artifacts( 'true'|'false' )

When a repository is configured to block downloads of artifacts, you may override that configuration (and allow download of blocked artifacts). Note that this
setting cannot override the blocking of unscanned artifacts.

## allow\_download\_when\_xray\_is\_unavailable( 'true'|'false' )

You may configure Artifactory to block downloads of artifacts when the connected Xray instance is unavailable. This endpoint lets you override that
configuration (and allow download of artifacts).

## create\_bundle( %hash of data structure )

Create a new support bundle

## list\_bundles

Lists previously created bundle currently stored in the system

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

    };
    my $file = '/local/file.xml';

    # Name of methods are taken straight from Artifactory REST API documentation.  'Deploy Artifact' would map to
    # deploy_artifact method, like below.  The caller gets HTTP::Response object back.
    my $resp = $client->deploy_artifact( path => $path, properties => $properties, file => $file );

    # Custom requests can also be made via usual get / post / put / delete requests.
    my $resp = $client->get( 'http://artifactory.server.com/path/to/resource' );

    # Repository override for calls that have a repository in the endpoint.  The passed-in repository will not persist.
    my $resp = $client->calculate_yum_repository_metadata( repository => 'different_repo', async => 1 );

=cut

=head1 Dev Env Setup / Running Tests

    carton install

    # to run unit tests
    prove -r t

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


Get general system information

=cut

sub system_info {
    my $self = shift;
    return $self->_handle_system();
}

=head2 verify_connection( endpoint => 'http://server/foobar', username => 'admin', password => 'password' )

Verifies a two-way connection between Artifactory and another product

=cut

sub verify_connection {
    my ( $self, %args ) = @_;
    my $url = $self->_api_url() . "/system/verifyconnection";

    return $self->post(

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


=cut

sub export_system {
    my ( $self, %args ) = @_;
    return $self->_handle_system_settings( 'export', %args );
}

=head2 ignore_xray_alert( $path )

Sets an alert to be ignored until next time the repository hosting the artifact about which the alert was issued, is scanned. Note that this endpoint does not
affect artifacts that are blocked because they have not been scanned at all.

=cut

sub ignore_xray_alert {
    my ( $self, $path ) = @_;
    my $url = $self->_api_url() . "/xray/setAlertIgnored?path=$path";
    return $self->post($url);
}

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

=cut

sub allow_download_of_blocked_artifacts {
    my ( $self, $bool ) = @_;
    my $url = $self->_api_url() . "/xray/allowBlockedArtifactsDownload?allow=$bool";
    return $self->post($url);
}

=head2 allow_download_when_xray_is_unavailable( 'true'|'false' )

You may configure Artifactory to block downloads of artifacts when the connected Xray instance is unavailable. This endpoint lets you override that
configuration (and allow download of artifacts).

=cut

sub allow_download_when_xray_is_unavailable {
    my ( $self, $bool ) = @_;
    my $url = $self->_api_url() . "/xray/allowDownloadWhenUnavailable?allow=$bool";
    return $self->post($url);
}

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

    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,

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


    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 ) = @_;

    my $resp    = $self->get_api_key();
    my $content = $self->_json->decode( $resp->content );
    my %header;
    $header{'X-Api-Key'} = $content->{apiKey};
    my $url = $self->_api_url() . $endpoint;
    return $self->delete( $url, %header );
}

sub _handle_block_system_replication {
    my ( $self, $ep, %args ) = @_;
    my %merged = (
        push => 'true',
        pull => 'true',
        %args    # overriding defaults
    );

t/01_unit.t  view on Meta::CPAN

        );
    };
    my $resp            = $client->system_info();
    my $url_in_response = $resp->request->uri;
    like( $url_in_response, qr|/api/system|, 'requsted URL looks sane' );
};

subtest 'verify_connection', sub {
    my $client = setup();
    my %args   = (
        endpoint => 'http://localhost/foobar',
        username => 'admin',
        password => 'password'
    );
    local *{'LWP::UserAgent::post'} = sub {
        return $mock_responses{http_200};
    };
    my $resp = $client->verify_connection(%args);
    is( $resp->code, 200, 'verify_connection succeeded' );
};



( run in 0.279 second using v1.01-cache-2.11-cpan-b61123c0432 )