Module: OCI::Core::Util

Defined in:
lib/oci/core/util.rb

Overview

This module contains utility methods for dealing with Core Services (Compute, Block Volume and Networking)

Class Method Summary collapse

Class Method Details

.file_content_as_launch_instance_user_data(file_path) ⇒ String

Takes a file path and returns a Base64-encoded string which can be provided as the value of the user_data key in the metadata dictionary when launching an instance. See Models::LaunchInstanceDetails for more information.

Parameters:

  • file_path (String)

    The path to the file to use for user_data

Returns:

  • (String)

    A Base64-encoded string which can be used as the value of the user_data key in the metadata dictionary when launching an instance



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/oci/core/util.rb', line 18

def self.file_content_as_launch_instance_user_data(file_path)
  expanded_path = File.expand_path(file_path)
  raise 'The specified file does not exist' unless File.exist?(file_path)

  file_content = nil
  File.open(expanded_path, 'rb') do |file|
    file_content = file.read
  end

  Base64.strict_encode64(file_content)
end