65e22e562312e39ee066c8f80d90e38d58056959
[mirror/dsa-puppet.git] / 3rdparty / modules / archive / manifests / nexus.pp
1 # define: archive::nexus
2 # ======================
3 #
4 # archive wrapper for downloading files from Nexus using REST API. Nexus API:
5 # https://repository.sonatype.org/nexus-restlet1x-plugin/default/docs/path__artifact_maven_content.html
6 #
7 # Parameters
8 # ----------
9 #
10 # Examples
11 # --------
12 #
13 # archive::nexus { '/tmp/jtstand-ui-0.98.jar':
14 #   url        => 'https://oss.sonatype.org',
15 #   gav        => 'org.codehaus.jtstand:jtstand-ui:0.98',
16 #   repository => 'codehaus-releases',
17 #   packaging  => 'jar',
18 #   extract    => false,
19 # }
20 #
21 define archive::nexus (
22   String            $url,
23   String            $gav,
24   String            $repository,
25   Enum['present', 'absent'] $ensure  = present,
26   Enum['none', 'md5', 'sha1', 'sha2','sha256', 'sha384', 'sha512'] $checksum_type   = 'md5',
27   Boolean           $checksum_verify = true,
28   String            $packaging       = 'jar',
29   Boolean           $use_nexus3_urls = false,
30   Optional[String]  $classifier      = undef,
31   Optional[String]  $extension       = undef,
32   Optional[String]  $username        = undef,
33   Optional[String]  $password        = undef,
34   Optional[String]  $user            = undef,
35   Optional[String]  $owner           = undef,
36   Optional[String]  $group           = undef,
37   Optional[String]  $mode            = undef,
38   Optional[Boolean] $extract         = undef,
39   Optional[String]  $extract_path    = undef,
40   Optional[String]  $extract_flags   = undef,
41   Optional[String]  $extract_command = undef,
42   Optional[String]  $creates         = undef,
43   Optional[Boolean] $cleanup         = undef,
44   Optional[String]  $proxy_server    = undef,
45   Optional[String]  $proxy_type      = undef,
46   Optional[Boolean] $allow_insecure  = undef,
47 ) {
48
49   include ::archive::params
50
51   $artifact_info = split($gav, ':')
52
53   $group_id = $artifact_info[0]
54   $artifact_id = $artifact_info[1]
55   $version = $artifact_info[2]
56
57   $query_params = {
58
59     'g' => $group_id,
60     'a' => $artifact_id,
61     'v' => $version,
62     'r' => $repository,
63     'p' => $packaging,
64     'c' => $classifier,
65     'e' => $extension,
66
67   }.filter |$keys, $values| { $values != undef }
68
69   if $use_nexus3_urls {
70     if $classifier {
71       $c = "-${classifier}"
72     } else {
73       $c = ''
74     }
75     $artifact_url = sprintf('%s/repository/%s/%s/%s/%s/%s-%s%s.%s', $url,
76                             $repository, regsubst($group_id, '\.', '/', 'G'), $artifact_id,
77                             $version, $artifact_id, $version, $c, $packaging)
78     $checksum_url = sprintf('%s.%s', $artifact_url, $checksum_type)
79   } else {
80     $artifact_url = assemble_nexus_url($url, $query_params)
81     $checksum_url = regsubst($artifact_url, "p=${packaging}", "p=${packaging}.${checksum_type}")
82   }
83   archive { $name:
84     ensure          => $ensure,
85     source          => $artifact_url,
86     username        => $username,
87     password        => $password,
88     checksum_url    => $checksum_url,
89     checksum_type   => $checksum_type,
90     checksum_verify => $checksum_verify,
91     extract         => $extract,
92     extract_path    => $extract_path,
93     extract_flags   => $extract_flags,
94     extract_command => $extract_command,
95     user            => $user,
96     group           => $group,
97     creates         => $creates,
98     cleanup         => $cleanup,
99     proxy_server    => $proxy_server,
100     proxy_type      => $proxy_type,
101     allow_insecure  => $allow_insecure,
102   }
103
104   $file_owner = pick($owner, $archive::params::owner)
105   $file_group = pick($group, $archive::params::group)
106   $file_mode  = pick($mode, $archive::params::mode)
107
108   file { $name:
109     owner   => $file_owner,
110     group   => $file_group,
111     mode    => $file_mode,
112     require => Archive[$name],
113   }
114 }