class Aspera::Node

Provides additional functions using node API.

Constants

ACCESS_LEVELS

permissions

MATCH_EXEC_PREFIX

Public Class Methods

decode_bearer_token(token) click to toggle source

for information only

# File lib/aspera/node.rb, line 14
def self.decode_bearer_token(token)
  return JSON.parse(Zlib::Inflate.inflate(Base64.decode64(token)).partition('==SIGNATURE==').first)
end
file_matcher(match_expression) click to toggle source

for access keys: provide expression to match entry in folder if no prefix: regex if prefix: ruby code if filder is nil, then always match

# File lib/aspera/node.rb, line 22
def self.file_matcher(match_expression)
  match_expression||="#{MATCH_EXEC_PREFIX}true"
  if match_expression.start_with?(MATCH_EXEC_PREFIX)
    return eval "lambda{|f|#{match_expression[MATCH_EXEC_PREFIX.length..-1]}}"
  end
  return lambda{|f|f['name'].match(/#{match_expression}/)}
end
new(rest_params) click to toggle source
Calls superclass method
# File lib/aspera/node.rb, line 30
def initialize(rest_params)
  super(rest_params)
end

Public Instance Methods

crawl(processor,opt={}) click to toggle source

recursively crawl in a folder. subfolders a processed if the processing method returns true @param processor must provide a method to process each entry @param opt options

  • top_file_id file id to start at (default = access key root file id)

  • top_file_path path of top folder (default = /)

  • method processing method (default= process_entry)

# File lib/aspera/node.rb, line 41
def crawl(processor,opt={})
  Log.log.debug("crawl1 #{opt}")
  # not possible with bearer token
  opt[:top_file_id] ||= read('access_keys/self')[:data]['root_file_id']
  opt[:top_file_path] ||= '/'
  opt[:method] ||= :process_entry
  raise "processor must have #{opt[:method]}" unless processor.respond_to?(opt[:method])
  Log.log.debug("crawl #{opt}")
  #top_info=read("files/#{opt[:top_file_id]}")[:data]
  folders_to_explore=[{id: opt[:top_file_id], relpath: opt[:top_file_path]}]
  Log.dump(:folders_to_explore,folders_to_explore)
  while !folders_to_explore.empty? do
    current_item = folders_to_explore.shift
    Log.log.debug("searching #{current_item[:relpath]}".bg_green)
    # get folder content
    folder_contents = begin
      read("files/#{current_item[:id]}/files")[:data]
    rescue => e
      Log.log.warn("#{current_item[:relpath]}: #{e.class} #{e.message}")
      []
    end
    Log.dump(:folder_contents,folder_contents)
    folder_contents.each do |entry|
      relative_path=File.join(current_item[:relpath],entry['name'])
      Log.log.debug("looking #{relative_path}".bg_green)
      # entry type is file, folder or link
      if processor.send(opt[:method],entry,relative_path) and entry['type'].eql?('folder')
        folders_to_explore.push({:id=>entry['id'],:relpath=>relative_path})
      end
    end
  end
end