class BannerJobsub::Base

Represents the current Banner environment the job is running in. At initilization, configuration values are loaded from three sources (in increasing order of precedence):

Avaliable configuration values are:

Attributes

conn[R]
header[R]
log[R]
name[R]
page_length[R]
params[R]
title[R]

Public Class Methods

new(name:, params:, opts: {}) click to toggle source
# File lib/banner_jobsub.rb, line 28
def initialize(name:, params:, opts: {})
  @name = name
  @config = {
    username: ENV['BANUID'],
    password: ENV['PSWD'],
    instance: ENV['ORACLE_SID'],
    seed_one: nil,
    seed_three: nil,
    page_length: 55,
    footer: '\f',
    header: '',
            banjsproxy: 'disabled'
  }

  configure_from_files
  configure_from_hash(opts)
  @config.each { |k, v| fail "Required configuration parameter \"#{k}\" is null." if v.nil? }

  # If banner jobsub proxy is marked as enabled, shuffle ENV vars to match Ellucian shenanigans
  if @config[:banjsproxy].downcase == 'enabled'
    @config[:password] = ''
    @config[:instance] = ENV['PSWD']
  end         
      
  set_db_connection
  set_role_security

  @title = @conn.select_one('SELECT GJBJOBS_TITLE FROM GJBJOBS WHERE GJBJOBS_NAME = :1', @name)[0]

  get_parameters(params)
  @page_length = @config[:page_length].to_i if @page_length.nil?

  set_header
  set_footer

  # Manage STDOUT/LOG
  @log = $stdout
  $stdout = File.new(ARGV[2], 'w') if ARGV[2]
end

Public Instance Methods

print_control_page(page_number = '') click to toggle source
print_header(page_number = 1) click to toggle source

Private Instance Methods

configure_from_files() click to toggle source
# File lib/banner_jobsub.rb, line 144
        def configure_from_files
  files = ["#{ENV['BANNER_HOME']}/admin/banner_jobsub.yaml", "#{Dir.home}/.banner_jobsub"]
  files.each do |f|
    begin
      config = YAML.load(IO.read(f))
      config.each { |k, v| @config[k.to_sym] = v if @config.keys.include?(k.to_sym) }
    rescue Errno::ENOENT # Ignore missing file exceptions.
    rescue Psych::SyntaxError => e
      raise "Error parsing YAML in #{f}: #{e}"
    end
  end
end
configure_from_hash(opts) click to toggle source
# File lib/banner_jobsub.rb, line 140
        def configure_from_hash(opts)
  opts.each { |k, v| @config[k.to_sym] = v if @config.keys.include?(k.to_sym) }
end
get_institution_name() click to toggle source
# File lib/banner_jobsub.rb, line 196
        def get_institution_name
  @conn.select_one('SELECT GUBINST_NAME FROM GUBINST WHERE GUBINST_KEY = \'INST\'')[0]
end
get_parameter_values_from_db(params, params_def) click to toggle source
# File lib/banner_jobsub.rb, line 110
        def get_parameter_values_from_db(params, params_def)
  cur = @conn.exec('SELECT * FROM GJBPRUN WHERE GJBPRUN_JOB = :1 AND GJBPRUN_ONE_UP_NO = :2 ORDER BY GJBPRUN_NUMBER', @name, ENV['ONE_UP'])
  while (r = cur.fetch_hash)
    p_num = r['GJBPRUN_NUMBER'].to_i
    if p_num == 99
      @page_length = r['GJBPRUN_VALUE'].nil? ? nil : r['GJBPRUN_VALUE'].to_i
      next
    end
    if p_num > params.count then fail "FATAL: GJBPRUN parameter number #{p_num} greater than passed parameter list." end
    p = params[p_num - 1]
    if params_def[p_num - 1][:gjbpdef_single_ind] == 'S'
      @params[p] = r['GJBPRUN_VALUE']
    else
      @params[p] << r['GJBPRUN_VALUE']
    end
  end
  if cur.row_count == 0 then fail "FATAL: Unable to validate one up ##{ENV['ONE_UP']} with job #{@name}." end
  cur.close

  @conn.exec('DELETE FROM GJBPRUN WHERE GJBPRUN_JOB = :1 AND GJBPRUN_ONE_UP_NO = :2', @name, ENV['ONE_UP'])
end
get_parameter_values_from_file() click to toggle source
# File lib/banner_jobsub.rb, line 106
        def get_parameter_values_from_file
  YAML.load(IO.read("#{@name.downcase}.yaml")).each { |k, v| @params[k.to_sym] = v }
end
get_parameter_values_from_prompt(params, params_def) click to toggle source
# File lib/banner_jobsub.rb, line 132
        def get_parameter_values_from_prompt(params, params_def)
  params.each_index do |i|
    p = params[i]
    @params[p] = (print "Value for #{p}: "; gets.chomp)
    @params[p] = @params[p].split(',') if params_def[i][:gjbpdef_single_ind] == 'M'
  end
end
get_parameters(params) click to toggle source
# File lib/banner_jobsub.rb, line 85
        def get_parameters(params)
  @params = {}
  params_def = []
  cur = @conn.exec('SELECT * FROM GJBPDEF WHERE GJBPDEF_JOB = :1 ORDER BY GJBPDEF_NUMBER', @name)
  while (r = cur.fetch_hash)
    p_def = r.each_with_object({}) { |(k, v), m| m[k.downcase.to_sym] = v }
    p = params[p_def[:gjbpdef_number].to_i - 1]
    @params[p] = p_def[:gjbpdef_single_ind] == 'S' ? nil : []
    params_def << p_def
  end
  cur.close

  if ENV['ONE_UP']
    get_parameter_values_from_db(params, params_def)
  elsif File.exist?("#{@name.downcase}.yaml")
    get_parameter_values_from_file
  else
    get_parameter_values_from_prompt(params, params_def)
  end
end
set_db_connection() click to toggle source
# File lib/banner_jobsub.rb, line 157
        def set_db_connection
  @conn = OCI8.new(@config[:username], @config[:password], @config[:instance])
end
set_header() click to toggle source
# File lib/banner_jobsub.rb, line 183
            def set_header
      if !@config[:header].empty?
        @header = @config[:header]
      else
        inst = get_institution_name
        @header = <<EOH
#{Time.now.strftime('%d-%b-%Y %I:%M %p').upcase} #{inst.center(110)} PAGE: @<<<
PAGE_NUMBER
#{@name} #{@title.center(132)}
EOH
      end
    end
set_role_security() click to toggle source
# File lib/banner_jobsub.rb, line 161
        def set_role_security
  password = ''

  cursor = @conn.parse('begin bansecr.g$_security_pkg.g$_verify_password1_prd(:p_object,:p_version,:p_password, :p_role); end;')
  cursor.exec @name, [nil, String], [nil, String], [nil, String]

  return if cursor[3] == 'INSECURED'

  @conn.exec('begin :p_result := G$_SECURITY.G$_DECRYPT_FNC( :p_password, :p_seed ); end;', ['', String, 255], [cursor[3], String, 255], [@config[:seed_three], Fixnum]) { |*outvars| password = outvars[0] }

  cursor = @conn.parse('begin bansecr.g$_security_pkg.g$_verify_password1_prd(:p_object,:p_version,:p_password, :p_role); end;')
  cursor.exec @name, [nil, String], [password, String], [nil, String]

  @conn.exec('begin :p_result := G$_SECURITY.G$_DECRYPT_FNC( :p_password, :p_seed ); end;', ['', String, 255], [cursor[3], String, 255], [@config[:seed_one], Fixnum]) { |*outvars| password = outvars[0] }

  @conn.exec("begin DBMS_SESSION.SET_ROLE('#{cursor[4]} IDENTIFIED BY \"#{password}\"'); end;")
end