<commit_before>require 'net/https'
require 'uri'

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [String] authtoken
def https_get(uri_string, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Get.new(uri.path)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  https.request(req)
end

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [Hash] payload HTTP request body
# @params [String|nil] authtoken
#   Authtoken string or `nil`.
#   Can pass `nil` only on authenticating with username and password.
def https_post(uri_string, payload, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Post.new(uri.request_uri)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  req.body = payload.to_json
  https.request(req)
end

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [String] authtoken
def https_delete(uri_string, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Delete.new(uri.request_uri)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  https.request(req)
end

# @params [Array<String>]
#   The return value of `ip_address_of` method. It is either
#
#       ["192.168.127.12", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b"]
#
#   or
#
#       ["fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "192.168.127.12"]
#
# @return [String] IPv4 address (e.g. "192.168.127.12")
def ipv4(ip_address)
  ip_address.select { |e| e =~ /\d+\.\d+\.\d+\.\d+/ }.first
end

# @return [String] Image name tag
# @params [String] os OS name
# @raise [StandardError] When the OS name isn't included in the dictionary.
def image_tag_dictionary(os)
  dictionary = {
    'ubuntu'   => 'vmi-ubuntu-14.04-amd64', # Ubuntu 14.04 amd64
    'debian'   => 'vmi-debian-8-amd64', # Debian 8 amd64
    'fedora23' => 'vmi-fedora-23-amd64', # Fedora 23 amd64
    'centos67' => 'vmi-centos-6.7-amd64', # CentOS 6.7
    'centos72' => 'vmi-centos-7.2-amd64', # CentOS 7.2
    'arch'     => 'vmi-arch-amd64', # Arch
  }

  # 'opensuse' => 'vmi-opensuse-42.1-amd64' # openSUSE
  # 'openbsd'  => 'vmi-openbsd-5.8-amd64', # OpenBSD
  # 'netbsd'   => 'vmi-netbsd-7.0-amd64', # NetBSD
  # 'freebsd'  => 'vmi-freebsd-10.1-x86_64', # FreeBSD

  if dictionary.keys.include? os
    dictionary[os]
  else
    raise StandardError.new <<EOS
"#{os}" doesn't exist.
Select os name from the following list:

#{dictionary.keys.join("\n")}
EOS
  end
end<commit_msg>Add openSUSE, OpenBSD, NetBSD and FreeBSD<commit_after>require 'net/https'
require 'uri'

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [String] authtoken
def https_get(uri_string, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Get.new(uri.path)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  https.request(req)
end

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [Hash] payload HTTP request body
# @params [String|nil] authtoken
#   Authtoken string or `nil`.
#   Can pass `nil` only on authenticating with username and password.
def https_post(uri_string, payload, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Post.new(uri.request_uri)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  req.body = payload.to_json
  https.request(req)
end

# @return [Net::HTTPResponse]
# @params [String] uri_string URI string
# @params [String] authtoken
def https_delete(uri_string, authtoken)
  uri = URI.parse uri_string
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  req = Net::HTTP::Delete.new(uri.request_uri)
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  req['X-Auth-Token'] = authtoken
  https.request(req)
end

# @params [Array<String>]
#   The return value of `ip_address_of` method. It is either
#
#       ["192.168.127.12", "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b"]
#
#   or
#
#       ["fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "192.168.127.12"]
#
# @return [String] IPv4 address (e.g. "192.168.127.12")
def ipv4(ip_address)
  ip_address.select { |e| e =~ /\d+\.\d+\.\d+\.\d+/ }.first
end

# @return [String] Image name tag
# @params [String] os OS name
# @raise [StandardError] When the OS name isn't included in the dictionary.
def image_tag_dictionary(os)
  dictionary = {
    'ubuntu'   => 'vmi-ubuntu-14.04-amd64', # Ubuntu 14.04 amd64
    'debian'   => 'vmi-debian-8-amd64', # Debian 8 amd64
    'fedora23' => 'vmi-fedora-23-amd64', # Fedora 23 amd64
    'centos67' => 'vmi-centos-6.7-amd64', # CentOS 6.7
    'centos72' => 'vmi-centos-7.2-amd64', # CentOS 7.2
    'arch'     => 'vmi-arch-amd64', # Arch
    'opensuse' => 'vmi-opensuse-42.1-amd64', # openSUSE
    'openbsd'  => 'vmi-openbsd-5.8-amd64', # OpenBSD
    'netbsd'   => 'vmi-netbsd-7.0-amd64', # NetBSD
    'freebsd'  => 'vmi-freebsd-10.1-x86_64', # FreeBSD
  }

  if dictionary.keys.include? os
    dictionary[os]
  else
    raise StandardError.new <<EOS
"#{os}" doesn't exist.
Select os name from the following list:

#{dictionary.keys.join("\n")}
EOS
  end
end
{'fraction_non_alphanumeric': 0.1689570119802678, 'fraction_numerical': 0.04897815362931642, 'mean_word_length': 3.958078602620087, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '721852', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2224, 'n_words': 472}