Class: Terraform::Binary::Executable
- Inherits:
-
Object
- Object
- Terraform::Binary::Executable
- Includes:
- Helpers
- Defined in:
- lib/terraform/binary/executable.rb
Overview
This class handles downloading, extracting, and saving the associated binary file
Defined Under Namespace
Classes: PlatformUnsupported
Constant Summary collapse
- TERRAFORM_DOWNLOAD_URI =
The download URI for the binary package
'releases.hashicorp.com'.freeze
Instance Method Summary collapse
-
#binary ⇒ String
Returns the path to the binary if it exists.
-
#download ⇒ Object
Downloads the zipfile from the origin.
-
#extract ⇒ Object
Extracts the binary from the zipfile and makes it executable.
-
#initialize ⇒ Executable
constructor
Loads global config values and creates the download directory if the current platform is supported.
Methods included from Helpers
debug, err, msg, stderr, stdout, system_command
Constructor Details
#initialize ⇒ Executable
Loads global config values and creates the download directory if the current platform is supported
16 17 18 19 20 21 22 23 24 |
# File 'lib/terraform/binary/executable.rb', line 16 def initialize @terraform_version = Terraform::Binary.config.version @download_path = "#{Terraform::Binary.config.download_path.chomp('/')}/terraform-binary/#{@terraform_version}/bin" @download_filename = "#{@terraform_version}-terraform.zip" FileUtils.mkdir_p @download_path raise PlatformUnsupported unless supported? end |
Instance Method Details
#binary ⇒ String
Returns the path to the binary if it exists
28 29 30 |
# File 'lib/terraform/binary/executable.rb', line 28 def binary Dir["#{@download_path}/terraform*"][0] end |
#download ⇒ Object
Downloads the zipfile from the origin
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/terraform/binary/executable.rb', line 33 def download return if binary_exist? msg("Downloading https://#{download_domain}/#{download_uri}") require 'open-uri' File.open("#{@download_path}/#{@download_filename}", 'wb') do |saved_file| URI.open("https://#{download_domain}/#{download_uri}", 'rb') do |read_file| saved_file.write(read_file.read) end end end |
#extract ⇒ Object
Extracts the binary from the zipfile and makes it executable
48 49 50 51 52 53 |
# File 'lib/terraform/binary/executable.rb', line 48 def extract return if binary_exist? Compressor.extract("#{@download_path}/#{@download_filename}", @download_path) make_exe end |