Puppet Function: url_parse

Defined in:
lib/puppet/parser/functions/url_parse.rb
Function type:
Ruby 3.x API

Overview

url_parse()Any

Returns:

  • (Any)


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
# File 'lib/puppet/parser/functions/url_parse.rb', line 4

newfunction(:url_parse, :type => :rvalue) do |args|
  @doc = "Returns information about an url
    
  This function expects two arguments, an URL and the part of the url you want to retrieve. 

  Example:
  $source_filename = url_parse($source_url,path)

  Given an url like: https://my_user:my_pass@www.example.com:8080/path/to/file.php?id=1&ret=0
  You obtain the following results according to the second argument:
  scheme   : https
  userinfo : my_user:my_pass
  user     : my_user
  password : my_pass
  host     : www.example.com
  port     : 8080
  path     : /path/to/file.php
  query    : id=1&ret=0
  filename : file.php
  filetype : php
  filedir  : file"

  raise ArgumentError, ("url_parse(): wrong number of arguments (#{args.length}; must be 2)") if args.length != 2
  url=URI.parse args[0]
  case args[1]
    when 'scheme'   then url.scheme
    when 'userinfo' then url.userinfo
    when 'user'     then url.user
    when 'password' then url.password
    when 'host'     then url.host
    when 'port'     then url.port
    when 'path'     then url.path
    when 'query'    then url.query
    when 'filename' then File.basename url.path
    when 'filetype' then File.extname url.path
    when 'filedir'  then (File.basename url.path).chomp(File.extname(url.path))
    else url
  end
end