Sha256: 2c7463ec975b015cb8aa41b409cf25b027c260e6de3eacd298d6b2753ddb390c

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'rake'
require 'optparse'
require 'securerandom'

namespace :harmony do
  desc 'Generate a key'
  task :generate_key do
    puts SecureRandom.hex
  end

  desc 'Generate keys and create encrypted sekret files'
  task :write_secrets do |_t, _args|
    abort "ENV['QUEUE_NAME'] must be set." unless ENV['QUEUE_NAME']
    abort "ENV['STAGING_AMPQ_URL'] must be set." unless ENV['STAGING_AMPQ_URL']
    abort "ENV['PRODUCTION_AMPQ_URL'] must be set." unless ENV['PRODUCTION_AMPQ_URL']

    secrets = {
      development: { harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['STAGING_AMPQ_URL'], ampq_vhost: 'harmony-staging-queue' },
      staging: { harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['STAGING_AMPQ_URL'], ampq_vhost: 'harmony-staging-queue' },
      production: { harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['PRODUCTION_AMPQ_URL'], ampq_vhost: 'harmony' }
    }

    secrets.each do |env, data|
      key = SecureRandom.hex
      `ruby -r yaml -e'puts(#{data}.to_yaml)' | sekrets write config/#{env}.yml.enc --key #{key}`
      puts "Created config/#{env}.yml.enc using the key #{key}. Store this key-data association in a secure place."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harmony-service-0.7.1 lib/harmony/service/rake_tasks.rb