Skip to content

Commit

Permalink
LTI-360: remove db scope from remaining rake tasks (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico authored Apr 25, 2024
1 parent b644dd4 commit ab22c2d
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.build.prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Build and Push pre-release
if: contains(env.DOCKER_BUILD_ENABLED, 'true')
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
tags: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.build.push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

- name: Build and Push branch
if: contains(env.DOCKER_BUILD_ENABLED, 'true')
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
tags: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.build.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Build and Push release
if: contains(env.DOCKER_BUILD_ENABLED, 'true')
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
tags: |
Expand Down
138 changes: 138 additions & 0 deletions lib/tasks/apps.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# frozen_string_literal: true

require 'securerandom'
require 'uri'
require 'bbb_lti_broker/helpers'

namespace :apps do
desc 'Add a new blti app - add[name,hostname,uid,secret]'
task :add, [:name, :hostname, :uid, :secret] => :environment do |_t, args|
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
unless args[:name]
puts('No app name provided')
exit(1)
end
blti_apps = Doorkeeper::Application.where(name: args[:name])
unless blti_apps.empty?
puts("App '#{args[:name]}' already exists, it can not be added")
exit(1)
end
unless args[:hostname]
puts("Parameters hostname is required, app '#{args[:name]}' can not be added")
exit(1)
end
puts("Adding '#{args.to_hash}'")
uid = args.[](:uid) || SecureRandom.hex(32)
secret = args.[](:secret) || SecureRandom.hex(32)

redirect_uri = (args[:hostname]).to_s
app = Doorkeeper::Application.create!(name: args[:name], uid: uid, secret: secret, \
redirect_uri: redirect_uri, scopes: 'api')
app1 = app.attributes.select { |key, _value| %w[name uid secret redirect_uri].include?(key) }
puts("Added '#{app1.to_json}'")
rescue StandardError => e
puts(e.backtrace)
exit(1)
end

desc 'Update an existent blti app if exists - update[name,redirect_uris,uid,secret]. redirect_uris is a list of callback uris separated by "\,"'
task :update, [:name, :redirect_uris, :uid, :secret] => :environment do |_t, args|
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
unless args[:name]
puts('No app name provided')
exit(1)
end
app = Doorkeeper::Application.find_by(name: args[:name])
if app.nil?
puts("App '#{args[:name]}' does not exist, it can not be updated")
exit(1)
end
puts("Updating '#{args.to_hash}'")
app.update!(uid: args[:uid]) if args.[](:uid)
app.update!(secret: args[:secret]) if args.[](:secret)

redirect_uri = (args[:redirect_uris]).gsub(',', "\r\n")
puts("redirect_uri:\n#{redirect_uri}")
app.update!(redirect_uri: redirect_uri) if args.[](:redirect_uris)
app_updated = app.attributes.select { |key, _value| %w[name uid secret redirect_uri].include?(key) }
puts("Updated '#{app_updated.to_json}'")
rescue StandardError => e
puts(e.backtrace)
exit(1)
end

desc 'Delete an existent blti app if exists - delete[name]'
task :delete, [:name] => :environment do |_t, args|
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
unless args[:name]
puts('No app name provided')
exit(1)
end
blti_apps = Doorkeeper::Application.where(name: args[:name])
if blti_apps.empty?
puts("App '#{args[:name]}' does not exist, it can not be deleted")
exit(1)
end
blti_apps.each(&:destroy)
puts("Apps with name '#{args[:name]}' were successfully destroyed")
rescue StandardError => e
puts(e.backtrace)
exit(1)
end

desc 'Show an existent blti app if exists - show[name]'
task :show, [:name] => :environment do |_t, args|
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
unless args[:name]
puts('No app name provided')
exit(1)
end
apps = Doorkeeper::Application.where(name: args[:name])
if apps.empty?
puts("App '#{args[:name]}' does not exist, it can not be shown")
exit(1)
end
apps.each do |app|
app1 = app.attributes.select { |key, _value| %w[name uid secret redirect_uri].include?(key) }
puts(app1.to_json)
end
rescue StandardError => e
puts(e.backtrace)
exit(1)
end

desc 'Delete all existent blti apps'
task :deleteall, [] => :environment do
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
Doorkeeper::Application.delete_all
puts('All the registered apps were deleted')
rescue StandardError => e
puts(e.backtrace)
exit(1)
end

desc 'Show all existent blti apps'
task :showall, [] => :environment do
include BbbLtiBroker::Helpers
Rake::Task['environment'].invoke
ActiveRecord::Base.connection
apps = Doorkeeper::Application.all
apps.each do |app|
app1 = app.attributes.select { |key, _value| %w[name uid secret redirect_uri].include?(key) }
puts(app1.to_json)
end
rescue ApplicationRedisRecord::RecordNotFound
puts(e.backtrace)
exit(1)
end
end
File renamed without changes.
140 changes: 0 additions & 140 deletions lib/tasks/db_apps.rake

This file was deleted.

87 changes: 0 additions & 87 deletions lib/tasks/db_tenant_settings.rake

This file was deleted.

Loading

0 comments on commit ab22c2d

Please sign in to comment.