<commit_before>#!/usr/bin/env ruby

require 'uri'
require 'securerandom'
require 'logger'
require 'sequel'

uri_string = ARGV[0]
database = ARGV[1]
raise "Usage: #{__FILE__} URI SQLITE_DATABASE_PATH" unless uri_string && database

# Modify this hash with the configuration for your database
DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "sqlite", database: database, :encoding => 'utf8'}

uri = URI(uri_string)
connection = Sequel.connect(DATABASE_CREDENTIALS)

certificate_command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null | openssl x509 -outform PEM"
certificate_content = `#{certificate_command}`

puts "Downloaded certificate from #{uri.host}: #{certificate_content}"

certificate_hash = {
  uuid: SecureRandom.urlsafe_base64,
  description: "Self signed certificate for #{uri.host}",
  content: certificate_content,
  created_at: DateTime.now,
  updated_at: DateTime.now
}

connection[:certificates].insert(certificate_hash)

puts "Done"
<commit_msg>chore: add comment to script for inserting certificate.<commit_after>#!/usr/bin/env ruby

require 'uri'
require 'securerandom'
require 'logger'
require 'sequel'

uri_string = ARGV[0]
database = ARGV[1]
raise "Usage: #{__FILE__} URI SQLITE_DATABASE_PATH" unless uri_string && database

# Modify this hash with the configuration for your database
# For example, a postgres connection would look like:
# DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "postgres", host: "HOST", username: "USERNAME", password: "PASSWORD", :encoding => 'utf8'}
DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "sqlite", database: database, :encoding => 'utf8'}

uri = URI(uri_string)
connection = Sequel.connect(DATABASE_CREDENTIALS)

certificate_command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null | openssl x509 -outform PEM"
certificate_content = `#{certificate_command}`

puts "Downloaded certificate from #{uri.host}: #{certificate_content}"

certificate_hash = {
  uuid: SecureRandom.urlsafe_base64,
  description: "Self signed certificate for #{uri.host}",
  content: certificate_content,
  created_at: DateTime.now,
  updated_at: DateTime.now
}

connection[:certificates].insert(certificate_hash)

puts "Done"

{'fraction_non_alphanumeric': 0.12698412698412698, 'fraction_numerical': 0.008151008151008152, 'mean_word_length': 6.4504792332268375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2006511', 'n_tokens_mistral': 769, 'n_tokens_neox': 752, 'n_words': 196}