1 # Define: archive::artifactory
2 # ============================
4 # archive wrapper for downloading files from artifactory
9 # * path: fully qualified filepath for the download the file or use archive_path and only supply filename. (namevar).
10 # * ensure: ensure the file is present/absent.
11 # * url: artifactory download url filepath. NOTE: replaces server, port, url_path parameters.
12 # * server: artifactory server name (deprecated).
13 # * port: artifactory server port (deprecated).
14 # * url_path: artifactory file path http://{server}:{port}/artifactory/{url_path} (deprecated).
15 # * owner: file owner (see archive params for defaults).
16 # * group: file group (see archive params for defaults).
17 # * mode: file mode (see archive params for defaults).
18 # * archive_path: the parent directory of local filepath.
19 # * extract: whether to extract the files (true/false).
20 # * creates: the file created when the archive is extracted (true/false).
21 # * cleanup: remove archive file after file extraction (true/false).
26 # archive::artifactory { '/tmp/logo.png':
27 # url => 'https://repo.jfrog.org/artifactory/distributions/images/Artifactory_120x75.png',
33 # $dirname = 'gradle-1.0-milestone-4-20110723151213+0300'
34 # $filename = "${dirname}-bin.zip"
36 # archive::artifactory { $filename:
37 # archive_path => '/tmp',
38 # url => "http://repo.jfrog.org/artifactory/distributions/org/gradle/${filename}",
40 # extract_path => '/opt',
41 # creates => "/opt/${dirname}",
45 define archive::artifactory (
47 Enum['present', 'absent'] $ensure = present,
48 Optional[Pattern[/^https?:\/\//]] $url = undef,
49 Optional[String] $server = undef,
50 Optional[Integer] $port = undef,
51 Optional[String] $url_path = undef,
52 Optional[String] $owner = undef,
53 Optional[String] $group = undef,
54 Optional[String] $mode = undef,
55 Optional[Boolean] $extract = undef,
56 Optional[String] $extract_path = undef,
57 Optional[String] $creates = undef,
58 Optional[Boolean] $cleanup = undef,
59 Optional[Stdlib::Compat::Absolute_path] $archive_path = undef,
62 include ::archive::params
65 $file_path = "${archive_path}/${name}"
70 if $file_path !~ Stdlib::Compat::Absolute_path {
71 fail("archive::artifactory[${name}]: \$name or \$archive_path must be an absolute path!") # lint:ignore:trailing_comma
75 $maven2_data = archive::parse_artifactory_url($url)
76 if $maven2_data and $maven2_data['folder_iteg_rev'] == 'SNAPSHOT'{
77 # URL represents a SNAPSHOT version. eg 'http://artifactory.example.com/artifactory/repo/com/example/artifact/0.0.1-SNAPSHOT/artifact-0.0.1-SNAPSHOT.zip'
78 # Only Artifactory Pro lets you download this directly but the corresponding fileinfo endpoint (where the sha1 checksum is published) doesn't exist.
79 # This means we can't use the artifactory_sha1 function
81 $latest_url_data = archive::artifactory_latest_url($url, $maven2_data)
83 $file_url = $latest_url_data['url']
84 $sha1 = $latest_url_data['sha1']
87 $sha1_url = regsubst($url, '/artifactory/', '/artifactory/api/storage/')
90 } elsif $server and $port and $url_path {
91 warning('archive::artifactory attribute: server, port, url_path are deprecated')
92 $art_url = "http://${server}:${port}/artifactory"
93 $file_url = "${art_url}/${url_path}"
94 $sha1_url = "${art_url}/api/storage/${url_path}"
97 fail('Please provide fully qualified url path for artifactory file.')
103 $_sha1 = artifactory_sha1($sha1_url)
105 archive { $file_path:
109 extract_path => $extract_path,
112 checksum_type => 'sha1',
117 $file_owner = pick($owner, $archive::params::owner)
118 $file_group = pick($group, $archive::params::group)
119 $file_mode = pick($mode, $archive::params::mode)
122 owner => $file_owner,
123 group => $file_group,
125 require => Archive[$file_path],