Class: Jekyll::Commands::GenerateKeys
- Inherits:
-
Jekyll::Command
- Object
- Jekyll::Command
- Jekyll::Commands::GenerateKeys
- Defined in:
- lib/jekyll/commands/generate_keys.rb
Overview
Send Activity Pub notifications
Class Method Summary collapse
Class Method Details
.init_with_program(prog) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jekyll/commands/generate_keys.rb', line 11 def init_with_program(prog) prog.command(:generate_keys) do |c| c.syntax 'generate_keys --key-size 2048 --key path/to/privkey.pem' c.description 'Generate an RSA keypair for ActivityPub' activity_pub_private_key c c.option 'activity_pub_key_size', '--key-size 2048', Integer, 'RSA key size (2048 by default)' c.action do |_, | process_with_graceful_fail(c, , self) end end end |
.process(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll/commands/generate_keys.rb', line 26 def process() # Adjust verbosity quickly Jekyll.logger.adjust_verbosity() private_key_path = ['activity_pub_private_key'] || 'privkey.pem' key_size = ['activity_pub_key_size'] || 2048 if File.exist? private_key_path raise Jekyll::Errors::FatalException, "Private key already exists: #{private_key_path}" end client = DistributedPress::V1::Social::Client.new(public_key_url: nil, key_size: key_size) File.open(private_key_path, 'w') do |f| f.write client.private_key.export rescue StandardError FileUtils.rm_f(private_key_path) raise end Jekyll.logger.info 'ActivityPub:', "Private key written to #{private_key_path}" end |