File: nexus.pp

package info (click to toggle)
puppet-module-puppet-archive 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 688 kB
  • sloc: ruby: 2,152; sh: 30; makefile: 2
file content (114 lines) | stat: -rw-r--r-- 3,664 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# define: archive::nexus
# ======================
#
# archive wrapper for downloading files from Nexus using REST API. Nexus API:
# https://repository.sonatype.org/nexus-restlet1x-plugin/default/docs/path__artifact_maven_content.html
#
# Parameters
# ----------
#
# Examples
# --------
#
# archive::nexus { '/tmp/jtstand-ui-0.98.jar':
#   url        => 'https://oss.sonatype.org',
#   gav        => 'org.codehaus.jtstand:jtstand-ui:0.98',
#   repository => 'codehaus-releases',
#   packaging  => 'jar',
#   extract    => false,
# }
#
define archive::nexus (
  String            $url,
  String            $gav,
  String            $repository,
  Enum['present', 'absent'] $ensure  = present,
  Enum['none', 'md5', 'sha1', 'sha2','sha256', 'sha384', 'sha512'] $checksum_type   = 'md5',
  Boolean           $checksum_verify = true,
  String            $packaging       = 'jar',
  Boolean           $use_nexus3_urls = false,
  Optional[String]  $classifier      = undef,
  Optional[String]  $extension       = undef,
  Optional[String]  $username        = undef,
  Optional[String]  $password        = undef,
  Optional[String]  $user            = undef,
  Optional[String]  $owner           = undef,
  Optional[String]  $group           = undef,
  Optional[String]  $mode            = undef,
  Optional[Boolean] $extract         = undef,
  Optional[String]  $extract_path    = undef,
  Optional[String]  $extract_flags   = undef,
  Optional[String]  $extract_command = undef,
  Optional[String]  $creates         = undef,
  Optional[Boolean] $cleanup         = undef,
  Optional[String]  $proxy_server    = undef,
  Optional[String]  $proxy_type      = undef,
  Optional[Boolean] $allow_insecure  = undef,
) {

  include archive::params

  $artifact_info = split($gav, ':')

  $group_id = $artifact_info[0]
  $artifact_id = $artifact_info[1]
  $version = $artifact_info[2]

  $query_params = {

    'g' => $group_id,
    'a' => $artifact_id,
    'v' => $version,
    'r' => $repository,
    'p' => $packaging,
    'c' => $classifier,
    'e' => $extension,

  }.filter |$keys, $values| { $values != undef }

  if $use_nexus3_urls {
    if $classifier {
      $c = "-${classifier}"
    } else {
      $c = ''
    }
    $artifact_url = sprintf('%s/repository/%s/%s/%s/%s/%s-%s%s.%s', $url,
                            $repository, regsubst($group_id, '\.', '/', 'G'), $artifact_id,
                            $version, $artifact_id, $version, $c, $packaging)
    $checksum_url = sprintf('%s.%s', $artifact_url, $checksum_type)
  } else {
    $artifact_url = assemble_nexus_url($url, $query_params)
    $checksum_url = regsubst($artifact_url, "p=${packaging}", "p=${packaging}.${checksum_type}")
  }
  archive { $name:
    ensure          => $ensure,
    source          => $artifact_url,
    username        => $username,
    password        => $password,
    checksum_url    => $checksum_url,
    checksum_type   => $checksum_type,
    checksum_verify => $checksum_verify,
    extract         => $extract,
    extract_path    => $extract_path,
    extract_flags   => $extract_flags,
    extract_command => $extract_command,
    user            => $user,
    group           => $group,
    creates         => $creates,
    cleanup         => $cleanup,
    proxy_server    => $proxy_server,
    proxy_type      => $proxy_type,
    allow_insecure  => $allow_insecure,
  }

  $file_owner = pick($owner, $archive::params::owner)
  $file_group = pick($group, $archive::params::group)
  $file_mode  = pick($mode, $archive::params::mode)

  file { $name:
    owner   => $file_owner,
    group   => $file_group,
    mode    => $file_mode,
    require => Archive[$name],
  }
}