-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into snyk-fix-5b306eafefb6dbcb81b504c89a0a8d26
- Loading branch information
Showing
17 changed files
with
204 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.