require 'fileutils' require 'hws_settings' require 'p4_util' # These are helper methods that should be common to most modular 'Apps' in # Helix Web Services. module HWSHelpers # This will ensure that the environment contains a p4 handle that is # configured using our typical `hws_settings` options. # # It should be rare to actually require using this method. This is typically # generated by authentication middleware. # # The p4 is possibly *not* connected or logged in. def require_p4 unless !env['p4'].nil? p4 = P4Util.open_from_env(env) p4.connect env['p4'] = p4 end end # This ensures that the `p4` handle has an associated temporary client # workspace. # # The local temporary directory is saved under 'p4_root'. def require_p4_with_temp_client require_p4 env['p4_root'] = P4Util.create_temp_client(env['p4']) end def p4 env['p4'] || fail('require_p4 not called') end def user env['AUTH_CREDENTIALS'].first end end