Skip to content

Instantly share code, notes, and snippets.

@smacfarlane
Created December 9, 2016 16:44
Show Gist options
  • Save smacfarlane/81c240e5e4403159a126416e5eba180a to your computer and use it in GitHub Desktop.
Save smacfarlane/81c240e5e4403159a126416e5eba180a to your computer and use it in GitHub Desktop.
Inspec Custom Matcher
require 'net/http'
require 'fileutils'
class GdalTranslate < Inspec.resource(1)
name 'gdal_translate'
def initialize(remote_file)
uri = URI.parse(remote_file)
@response = Net::HTTP.get(uri)
@filename = File.basename(uri.path)
end
def tiff_to_png
tempdir = Dir.mktmpdir
tempfile = File.join(tempdir, @filename)
File.open(tempfile, "wb") do |file|
file.write(@response)
end
cmd = inspec.command "gdal_translate -of PNG #{tempfile} #{tempfile}.tif"
result = cmd.result
FileUtils.remove_entry_secure(tempdir)
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment