Mercurial > repos > other > Puppet
comparison modules/archive/manifests/artifactory.pp @ 386:3fce34f642f1
Add a PHP module to handle platform differences
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 03 Jan 2022 17:09:39 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
385:d9009f54eb23 | 386:3fce34f642f1 |
---|---|
1 # Define: archive::artifactory | |
2 # ============================ | |
3 # | |
4 # archive wrapper for downloading files from artifactory | |
5 # | |
6 # Parameters | |
7 # ---------- | |
8 # | |
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. | |
12 # * owner: file owner (see archive params for defaults). | |
13 # * group: file group (see archive params for defaults). | |
14 # * mode: file mode (see archive params for defaults). | |
15 # * archive_path: the parent directory of local filepath. | |
16 # * extract: whether to extract the files (true/false). | |
17 # * creates: the file created when the archive is extracted (true/false). | |
18 # * cleanup: remove archive file after file extraction (true/false). | |
19 # | |
20 # Examples | |
21 # -------- | |
22 # | |
23 # archive::artifactory { '/tmp/logo.png': | |
24 # url => 'https://repo.jfrog.org/artifactory/distributions/images/Artifactory_120x75.png', | |
25 # owner => 'root', | |
26 # group => 'root', | |
27 # mode => '0644', | |
28 # } | |
29 # | |
30 # $dirname = 'gradle-1.0-milestone-4-20110723151213+0300' | |
31 # $filename = "${dirname}-bin.zip" | |
32 # | |
33 # archive::artifactory { $filename: | |
34 # archive_path => '/tmp', | |
35 # url => "http://repo.jfrog.org/artifactory/distributions/org/gradle/${filename}", | |
36 # extract => true, | |
37 # extract_path => '/opt', | |
38 # creates => "/opt/${dirname}", | |
39 # cleanup => true, | |
40 # } | |
41 # | |
42 define archive::artifactory ( | |
43 Stdlib::HTTPUrl $url, | |
44 String $path = $name, | |
45 Enum['present', 'absent'] $ensure = present, | |
46 Optional[String] $owner = undef, | |
47 Optional[String] $group = undef, | |
48 Optional[String] $mode = undef, | |
49 Optional[Boolean] $extract = undef, | |
50 Optional[String] $extract_path = undef, | |
51 Optional[String] $creates = undef, | |
52 Optional[Boolean] $cleanup = undef, | |
53 Optional[String] $username = undef, | |
54 Optional[String] $password = undef, | |
55 Optional[Stdlib::Absolutepath] $archive_path = undef, | |
56 ) { | |
57 include archive::params | |
58 | |
59 if $archive_path { | |
60 $file_path = "${archive_path}/${name}" | |
61 } else { | |
62 $file_path = $path | |
63 } | |
64 | |
65 assert_type(Stdlib::Absolutepath, $file_path) |$expected, $actual| { | |
66 fail("archive::artifactory[${name}]: \$name or \$archive_path must be '${expected}', not '${actual}'") | |
67 } | |
68 | |
69 $maven2_data = archive::parse_artifactory_url($url) | |
70 if $maven2_data and $maven2_data['folder_iteg_rev'] == 'SNAPSHOT' { | |
71 # 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' | |
72 # Only Artifactory Pro lets you download this directly but the corresponding fileinfo endpoint (where the sha1 checksum is published) doesn't exist. | |
73 # This means we can't use the artifactory_sha1 function | |
74 | |
75 $latest_url_data = archive::artifactory_latest_url($url, $maven2_data) | |
76 | |
77 $file_url = $latest_url_data['url'] | |
78 $sha1 = $latest_url_data['sha1'] | |
79 } else { | |
80 $file_url = $url | |
81 $sha1 = archive::artifactory_checksum($url,'sha1') | |
82 } | |
83 | |
84 archive { $file_path: | |
85 ensure => $ensure, | |
86 path => $file_path, | |
87 extract => $extract, | |
88 extract_path => $extract_path, | |
89 username => $username, | |
90 password => $password, | |
91 source => $file_url, | |
92 checksum => $sha1, | |
93 checksum_type => 'sha1', | |
94 creates => $creates, | |
95 cleanup => $cleanup, | |
96 } | |
97 | |
98 $file_owner = pick($owner, $archive::params::owner) | |
99 $file_group = pick($group, $archive::params::group) | |
100 $file_mode = pick($mode, $archive::params::mode) | |
101 | |
102 file { $file_path: | |
103 owner => $file_owner, | |
104 group => $file_group, | |
105 mode => $file_mode, | |
106 require => Archive[$file_path], | |
107 } | |
108 } |