Module: Makitzo::SSH::Commands::HTTP

Included in:
Makitzo::SSH::Context
Defined in:
lib/makitzo/ssh/commands/http.rb

Instance Method Summary collapse

Instance Method Details

#download(url, path) ⇒ Object

downloads a url -> path, using either curl or wget logs a warning if neither is present TODO: hosts/roles should be able to specify their preferred d/l mechanism



7
8
9
10
11
12
13
14
15
16
# File 'lib/makitzo/ssh/commands/http.rb', line 7

def download(url, path)
  if which?("curl")
    download_with_curl(url, path)
  elsif which?("wget")
    download_with_wget(url, path)
  else
    logger.warn("failed: download #{url} -> #{path} (curl/wget not found)")
    false
  end
end

#download!(url, path) ⇒ Object

downloads url and saves in path, using either curl or wget raises CommandFailed if download fails

Raises:



20
21
22
# File 'lib/makitzo/ssh/commands/http.rb', line 20

def download!(url, path)
  raise CommandFailed unless download(url, path)
end

#download_with_curl(url, path) ⇒ Object

downloads url and saves to path, using curl logs success/failure message



26
27
28
29
30
31
32
33
34
35
# File 'lib/makitzo/ssh/commands/http.rb', line 26

def download_with_curl(url, path)
  result = exec("curl -o #{path} -f #{url}")
  if result.success?
    logger.success("download #{url} -> #{path} (curl)")
    true
  else
    logger.warn("failed: download #{url} -> #{path} (curl)")
    false
  end
end

#download_with_wget(url, path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/makitzo/ssh/commands/http.rb', line 37

def download_with_wget(url, path)
  result = exec("wget -o #{path} -- #{url}")
  if result.success?
    logger.success("download #{url} -> #{path} (wget)")
    true
  else
    logger.warn("failed: download #{url} -> #{path} (wget)")
    false
  end
end