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

$LOAD_PATH.push File.expand_path('../../lib', __FILE__)

require 'cyclid/hmac'
require 'net/http'
require 'uri'
require 'securerandom'

username = 'test'
secret = 'aasecret55'
uri = URI('http://localhost:9292/organizations')

nonce = SecureRandom.hex()

signer = Cyclid::HMAC::Signer.new
headers = signer.sign_request(uri.path, secret, {auth_header_format: '%{auth_scheme} %{username}:%{signature}', username: username, nonce: nonce})
puts headers.inspect

req = Net::HTTP::Get.new(uri)
headers[0].each do |k, v|
  puts "#{k}=#{v}"
  req[k] = v
end

res = Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end

puts res.body
<commit_msg>Convert hmac-test into something more useful<commit_after>#!/usr/bin/env ruby

$LOAD_PATH.push File.expand_path('../../lib', __FILE__)

require 'cyclid/hmac'
require 'net/http'
require 'uri'
require 'securerandom'
require 'optparse'
require 'logger'

options = {}
options[:scheme] = 'http'
options[:host] = 'localhost'
options[:port] = 9292
options[:log_level] = Logger::INFO

OptionParser.new do |opts|
  opts.on('-u', '--user USERNAME', 'Cyclid username') do |u|
    options[:username] = u
  end

  opts.on('-s', '--secret SECRET', 'HMAC signing secret') do |s|
    options[:secret] = s
  end

  opts.on('-H', '--host URL', "Hostname (Default: #{options[:host]}") do |h|
    options[:host] = h
  end

  opts.on('-P', '--port PORT', "Port number (Default: #{options[:port]}") do |p|
    options[:port] = p.to_i
  end

  opts.on('-d', '--debug', 'Enable verbose debug output') do |d|
    options[:log_level] = Logger::DEBUG
  end
end.parse!

raise OptionParser::MissingArgument if options[:username].nil?
raise OptionParser::MissingArgument if options[:secret].nil?

path = ARGV[0]

# Create a logger
logger = Logger.new(STDERR)
logger.level = options[:log_level]

# Build the request & sign it
uri = URI::HTTP.build(host: options[:host],
                      port: options[:port],
                      path: path)

signer = Cyclid::HMAC::Signer.new

nonce = SecureRandom.hex()
headers = signer.sign_request(uri.path,
                              options[:secret],
                                {auth_header_format: '%{auth_scheme} %{username}:%{signature}',
                                 username: options[:username],
                                 nonce: nonce})
logger.debug headers.inspect

req = Net::HTTP::Get.new(uri)
headers[0].each do |k, v|
  logger.debug "#{k}=#{v}"
  req[k] = v
end

http = Net::HTTP.new(uri.hostname, uri.port)
http.set_debug_output(logger)
res = http.request(req)

puts res.body

{'fraction_non_alphanumeric': 0.17068503635667814, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 3.5381944444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6566860', 'n_tokens_mistral': 918, 'n_tokens_neox': 897, 'n_words': 209}