<commit_before><?php

namespace SAS\IRAD\MailForwardingBundle\AuthCheck;

use Symfony\Component\HttpFoundation\Session\Session;
use SAS\IRAD\PersonInfoBundle\PersonInfo\PersonInfoInterface;


class AuthCheckService {
    
    private $auth_script;
    private $session;
    
    public function __construct(Session $session, $params) {
        $this->session     = $session;
        $this->auth_script = $params['auth_script'];
    }
    
    
    /**
     * Run authcheck for given user (use one hour cache)
     * @param PersonInfoInterface
     * @return boolean
     */
    public function authCheck(PersonInfoInterface $personInfo) {
        
        $penn_id = $personInfo->getPennId();
        $pennkey = $personInfo->getPennkey();
        
        if ( $cache = $this->session->get("authCheck/$pennkey/$penn_id") ) {
            if ( $cache['expires_on'] > time() ) {
                return $cache['data'];
            }
        }
            
        $cmd  = "{$this->auth_script} $pennkey $penn_id";
        $data = shell_exec( escapeshellcmd($cmd) );

        $result = new AuthCheckResult($data);
        
        ## did ssh return a failure
        if ( $result->getValue('ssh_script_run') != 'success' ) {
            error_log("Error running $cmd to get account details");
            throw new \Exception("Error running $cmd to get account details");
        }        
        
        $info = array('expires_on' => time() + 3600,
                      'data'       => $result);
        
        $this->session->set("authCheck/$pennkey/$penn_id", $info);        
        return $result;
    }
    
}<commit_msg>Make authCheck key cache dependent on prod/dev version of script<commit_after><?php

namespace SAS\IRAD\MailForwardingBundle\AuthCheck;

use Symfony\Component\HttpFoundation\Session\Session;
use SAS\IRAD\PersonInfoBundle\PersonInfo\PersonInfoInterface;


class AuthCheckService {
    
    private $auth_script;
    private $session;
    
    public function __construct(Session $session, $params) {
        $this->session     = $session;
        $this->auth_script = $params['auth_script'];
    }
    
    
    /**
     * Run authcheck for given user (use one hour cache)
     * @param PersonInfoInterface
     * @return boolean
     */
    public function authCheck(PersonInfoInterface $personInfo) {
        
        $penn_id = $personInfo->getPennId();
        $pennkey = $personInfo->getPennkey();
        
        if ( $cache = $this->session->get("{$this->auth_script}/$pennkey/$penn_id") ) {
            if ( $cache['expires_on'] > time() ) {
                return $cache['data'];
            }
        }
            
        $cmd  = "{$this->auth_script} $pennkey $penn_id";
        $data = shell_exec( escapeshellcmd($cmd) );

        $result = new AuthCheckResult($data);
        
        ## did ssh return a failure
        if ( $result->getValue('ssh_script_run') != 'success' ) {
            error_log("Error running $cmd to get account details");
            throw new \Exception("Error running $cmd to get account details");
        }        
        
        $info = array('expires_on' => time() + 3600,
                      'data'       => $result);
        
        $this->session->set("{$this->auth_script}/$pennkey/$penn_id", $info);  
        return $result;
    }
    
}
{'fraction_non_alphanumeric': 0.1297801866907558, 'fraction_numerical': 0.002408912978018669, 'mean_word_length': 2.11340206185567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6815825', 'n_tokens_mistral': 985, 'n_tokens_neox': 961, 'n_words': 199}