Skip to content

Commit

Permalink
allow filesystem source (#7)
Browse files Browse the repository at this point in the history
* allow filesystem source

chooses a source based on the identifier: if it starts with "Masters/", then use the FilesystemSource. Otherwise, use HttpSource as before to retreive from fedora.

(the slash must be url-escaped as %2F in the request, but it is already unescaped by the time the delegate script is invoked)

Also adds the method `authorize`, which replaces `authorized?` and `redirect` in Cantaloupe 4.1 (https://cantaloupe-project.github.io/manual/4.1/delegate-script.html#MigratingFrom4To41)

* get the right version of bundler in travis
  • Loading branch information
sourcefilter authored Jul 16, 2019
1 parent 6565699 commit 105e799
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ dist: trusty
language: ruby
cache: bundler
sudo: false
script:
install:
- jruby -S gem install bundler -v 2.0.1
- jruby -S bundle install
script:
- jruby -S bundle exec rake
jdk:
- oraclejdk8
Expand Down
39 changes: 38 additions & 1 deletion lib/delegates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ class CustomDelegate
#
attr_accessor :context

##
# Returns authorization status for the current request. Will be called upon
# all requests to all public endpoints.
#
# Implementations should assume that the underlying resource is available,
# and not try to check for it.
#
# Possible return values:
#
# 1. Boolean true/false, indicating whether the request is fully authorized
# or not. If false, the client will receive a 403 Forbidden response.
# 2. Hash with a `status_code` key.
# a. If it corresponds to an integer from 200-299, the request is
# authorized.
# b. If it corresponds to an integer from 300-399:
# i. If the hash also contains a `location` key corresponding to a
# URI string, the request will be redirected to that URI using
# that code.
# ii. If the hash also contains `scale_numerator` and
# `scale_denominator` keys, the request will be
# redirected using that code to a virtual reduced-scale version of
# the source image.
# c. If it corresponds to 401, the hash must include a `challenge` key
# corresponding to a WWW-Authenticate header value.
#
# @param options [Hash] Empty hash.
# @return [Boolean,Hash<String,Object>] See above.
#
def authorize(options = {})
authorized?(options)
end

##
# Tells the server whether to redirect in response to the request. Will be
# called upon all image requests.
Expand Down Expand Up @@ -103,7 +135,12 @@ def extra_iiif2_information_response_keys(_options = {})
# @return [String] Source name.
#
def source(_options = {})
'HttpSource'
identifier = context['identifier']
if identifier.start_with?('Masters/')
'FilesystemSource'
else
'HttpSource'
end
end

##
Expand Down

0 comments on commit 105e799

Please sign in to comment.