File: parse_artifactory_url.rb

package info (click to toggle)
puppet-module-voxpupuli-archive 7.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: ruby: 2,483; sh: 10; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 1,009 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
# frozen_string_literal: true

# A function to parse an Artifactory maven 2 repository URL
Puppet::Functions.create_function(:'archive::parse_artifactory_url') do
  dispatch :parse_artifactory_url do
    param 'Variant[Stdlib::HTTPUrl, Stdlib::HTTPSUrl]', :url
  end

  def parse_artifactory_url(url)
    # Regex is for the 'maven-2-default Repository Layout'
    matchdata = url.match(%r{
             (?<base_url>.*/artifactory)
             /
             (?<repository>[^/]+)
             /
             (?<org_path>.+?)
             /
             (?<module>[^/]+)
             /
             (?<base_rev>[^/]+?)
             (?:-(?<folder_iteg_rev>SNAPSHOT))?
             /
             \k<module>-\k<base_rev>
             (?:-(?<file_iteg_rev>SNAPSHOT|(?:(?:[0-9]{8}.[0-9]{6})-(?:[0-9]+))))?
             (?:-(?<classifier>[^/]+?))?
             \.
             (?<ext>(?:(?!\d))[^\-/]+|7z)
             }x)
    return nil unless matchdata

    matchdata.names.zip(matchdata.captures).to_h
  end
end