Sha256: 16b74a0cb4f5c93c8f0e2c04d99d751d5c1891ad5e30420de9d1b728c388cac8

Contents?: true

Size: 967 Bytes

Versions: 3

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
require 'osso'

namespace :osso do
  desc 'Bootstrap Osso data for a deployment'
  task :bootstrap do
    %w[Production Staging Development].each do |environment|
      next if Osso::Models::OauthClient.find_by_name(environment)

      Osso::Models::OauthClient.create!(
        name: environment,
      )
    end

    Osso::Models::AppConfig.create

    admin_email = ENV['ADMIN_EMAIL']

    if admin_email
      Osso::Models::Account.create(
        email: admin_email,
        status_id: 1,
        role: 'admin',
      )

      base_uri = URI.parse(ENV['BASE_URL'])

      rodauth = Osso::Admin.rodauth.new(Osso::Admin.new({
        'HTTP_HOST' => base_uri.host,
        'SERVER_NAME' => base_uri.to_s,
        'rack.url_scheme' => base_uri.scheme,
      }))

      rodauth.account_from_login(admin_email)
      rodauth.setup_account_verification
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
osso-0.1.2 lib/tasks/bootstrap.rake
osso-0.1.1 lib/tasks/bootstrap.rake
osso-0.1.0 lib/tasks/bootstrap.rake