From 3899ed93cd0817b211580e6daa628e71d2854cac Mon Sep 17 00:00:00 2001 From: Andrew Gardener Date: Thu, 18 Jan 2018 15:20:50 -0800 Subject: [PATCH] Add protocol option for automatic lti updates Used to force internal request_url to use a specific protocol (useful if updating directly to a specific webwork server behind a load balancer, etc) --- lib/WebworkBridge/autoupdate.pl | 16 +++++++++++++--- lib/WebworkBridge/updateclass_lti.pl | 8 +++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/WebworkBridge/autoupdate.pl b/lib/WebworkBridge/autoupdate.pl index 0dfd518c23..7c4537fe8f 100755 --- a/lib/WebworkBridge/autoupdate.pl +++ b/lib/WebworkBridge/autoupdate.pl @@ -9,8 +9,9 @@ =head1 SYNOPSIS autoupdate [options] Options: - -check Only check to see if LTI roster requests are successful. - -grade Try to send grades to the LMS. + -check Only check to see if LTI roster requests are successful. + -grade Try to send grades to the LMS. + -protocol Force using provided protocol when sending request to server =head1 OPTIONS @@ -28,6 +29,11 @@ =head1 OPTIONS Enables additional parameters in the LTI launch request that tells Webwork to try sending grades to the LMS. +=item B<-protocol=s> + +Force using protocol when sending request to server for class membership and grade updates. +Overrides protocol used by server_root_url + =back =cut @@ -53,12 +59,16 @@ BEGIN # if set to true, will try to send grades to the LMS my $grade = ''; +# force request url to use protocol (overrides server_root_url) +my $protocol = ''; + my $man = 0; my $help = 0; GetOptions ( "check" => \$check, "grade" => \$grade, + "protocol=s" => \$protocol, 'help|?' => \$help, man => \$man ); @@ -93,7 +103,7 @@ BEGIN } else { - $cmd = $ENV{WEBWORK_ROOT} . "/lib/WebworkBridge/updateclass_lti.pl '$courseName' '$oauth_consumer_key' '$context_id' $grade"; + $cmd = $ENV{WEBWORK_ROOT} . "/lib/WebworkBridge/updateclass_lti.pl '$courseName' '$oauth_consumer_key' '$context_id' '$grade' '$protocol'"; } my $ret = `$cmd\n`; diff --git a/lib/WebworkBridge/updateclass_lti.pl b/lib/WebworkBridge/updateclass_lti.pl index 4f1fb0c84b..eae5df2201 100755 --- a/lib/WebworkBridge/updateclass_lti.pl +++ b/lib/WebworkBridge/updateclass_lti.pl @@ -30,6 +30,7 @@ BEGIN print "Parameter count incorrect, please enter all parameters:"; print "\updateclass_lti CourseName oauthConsumerKey contextId\n"; print "\nGrades (Optional) - If given, will try to send grades to LMS.\n"; + print "\nProtocol (Optional) - If given, will override request_url's protocol.\n"; print "\ne.g.: updateclass_lti Math100-100 consumerKey 123abc123abc\n"; exit(); } @@ -38,6 +39,7 @@ BEGIN my $oauth_consumer_key = shift; my $context_id = shift; my $grade = shift; +my $protocol = shift; # bring up a course environment my $ce = WeBWorK::CourseEnvironment->new({ @@ -66,7 +68,7 @@ BEGIN my $custom_context_memberships_url = $ltiContext->custom_context_memberships_url; my %gradeParams; -if (defined($grade)) +if (defined($grade) && $grade eq 'true') { $gradeParams{'ext_ims_lis_resultvalue_sourcedids'} = 'decimal'; $gradeParams{'custom_gradesync'} = '1'; @@ -108,6 +110,10 @@ BEGIN my $ua = LWP::UserAgent->new; push @{ $ua->requests_redirectable }, 'POST'; +# force replace request_url protocol for internal request +if ($protocol) { + $request_url =~ s/^\w+:\/\//$protocol:\/\//g; +} my $res = $ua->post($request_url . $courseName . "/", $request->to_hash); if ($res->is_success) {