<commit_before>---
title: 
layout: module
---

# XASecure

    module.exports = []
    module.exports.push 'masson/commons/java'
    module.exports.push 'masson/commons/mysql_client'

## Configuration

    module.exports.push (ctx) ->
      require('masson/commons/java').configure ctx
      require('../hive/server').configure ctx
      require('./policymgr').configure ctx
      policymgr = ctx.host_with_module 'ryba/xasecure/policymgr'
      xasecure = ctx.config.xasecure ?= {}
      throw new Error "Required property \"xasecure.hive_url\"" unless xasecure.hive_url?
      xasecure.hive ?= {}
      xasecure.hive['POLICY_MGR_URL'] = "http://#{policymgr}:6080"
      xasecure.hive['MYSQL_CONNECTOR_JAR'] = "usr/share/java/mysql-connector-java.jar"
      # xasecure.hive['REPOSITORY_NAME'] = "vagrant_hive"
      xasecure.hive['XAAUDIT.DB.HOSTNAME'] = xasecure.policymgr['db_host']
      xasecure.hive['XAAUDIT.DB.DATABASE_NAME'] ?= xasecure.policymgr['audit_db_name']
      xasecure.hive['XAAUDIT.DB.USER_NAME'] ?= xasecure.policymgr['audit_db_user']
      xasecure.hive['XAAUDIT.DB.PASSWORD'] ?= xasecure.policymgr['audit_db_password']

    module.exports.push name: 'XASecure Hive # Install', timeout: -1, callback: (ctx, next) ->
      {hive_conf_dir} = ctx.config.hdp
      {hive} = ctx.config.xasecure
      modified = false
      source = ctx.config.xasecure.hive_url
      do_upload = ->
        u = url.parse source
        ctx[if u.protocol is 'http:' then 'download' else 'upload']
          source: source
          destination: '/tmp'
          binary: true
        , (err, uploaded) ->
          return next err if err
          do_extract()
      do_extract = ->
        source = "/tmp/#{path.basename source}"
        ctx.extract
          source: source
          # destination: 
        , (err) ->
          return next err if err
          do_configure()
      do_configure = ->
        # ldapsearch -x -LLL -H ldaps://noev201i.noe.edf.fr -D cn=noeyy5j8,ou=systems,dc=edfgdf,dc=fr -w d.IPQUnI -b "dc=edfgdf,dc=fr" "objectClass=*" 
        source = "#{path.dirname source}/#{path.basename source, '.tar'}"
        write = for k, v of hive
          match: RegExp "^#{quote k}=.*$", 'mg'
          replace: "#{k}=#{v}"
        ctx.write
          destination: "#{source}/install.properties"
          write: write
          eof: true
        , (err, written) ->
          return next err if err
          do_install()
      do_install = ->
        ctx.execute
          cmd: "cd #{source} && ./install.sh"
          # cwd: "#{source}"
        , (err, executed) ->
          return next err if err
          do_conf()
      do_conf = ->
        # TODO, need to merge properties "hive.exec.pre.hooks", "hive.exec.post.hooks"
        ctx.hconfigure
          destination: "#{hive_conf_dir}/hive-site.xml"
          properties: 
            'hive.exec.pre.hooks': 'com.xasecure.authorization.hive.hooks.XaSecureHivePreExecuteRunHook'
            'hive.exec.post.hooks': 'com.xasecure.authorization.hive.hooks.XaSecureHivePostExecuteRunHook'
            'hive.semantic.analyzer.hook': 'com.xasecure.authorization.hive.hooks.XaSecureSemanticAnalyzerHook'
            # Overwrite com.xasecure.authentication.hive.LoginNameAuthenticator
            'hive.server2.custom.authentication.class': 'com.xasecure.authentication.hive.LoginNameAuthenticator'
            # Overwrite hive.exec.post.hooks,hive.exec.driver.run.hooks,hive.server2.authentication,hive.metastore.pre.event.listeners,hive.security.authorization.enabled,hive.security.authorization.manager,hive.semantic.analyzer.hook
            'hive.conf.restricted.list': 'hive.exec.driver.run.hooks,hive.server2.authentication,hive.metastore.pre.event.listeners,hive.security.authorization.enabled,hive.security.authorization.manager,hive.semantic.analyzer.hook,hive.exec.post.hooks'
          merge: true
        , (err, configured) ->
          return next err if err
          do_restart()
      do_restart = ->
        lifecycle.hive_metastore_restart ctx, (err) ->
          return next err if err
          lifecycle.hive_server2_restart ctx, (err) ->
            return next err if err
            next null, ctx.PASS
      do_upload()
<commit_msg>improve upload strategy<commit_after>---
title: 
layout: module
---

# XASecure

    module.exports = []
    module.exports.push 'masson/commons/java'
    module.exports.push 'masson/commons/mysql_client'

## Configuration

    module.exports.push (ctx) ->
      require('masson/commons/java').configure ctx
      require('../hive/server').configure ctx
      require('./policymgr').configure ctx
      policymgr = ctx.host_with_module 'ryba/xasecure/policymgr'
      xasecure = ctx.config.xasecure ?= {}
      throw new Error "Required property \"xasecure.hive_url\"" unless xasecure.hive_url?
      xasecure.hive ?= {}
      xasecure.hive['POLICY_MGR_URL'] = "http://#{policymgr}:6080"
      xasecure.hive['MYSQL_CONNECTOR_JAR'] = "usr/share/java/mysql-connector-java.jar"
      # xasecure.hive['REPOSITORY_NAME'] = "vagrant_hive"
      xasecure.hive['XAAUDIT.DB.HOSTNAME'] = xasecure.policymgr['db_host']
      xasecure.hive['XAAUDIT.DB.DATABASE_NAME'] ?= xasecure.policymgr['audit_db_name']
      xasecure.hive['XAAUDIT.DB.USER_NAME'] ?= xasecure.policymgr['audit_db_user']
      xasecure.hive['XAAUDIT.DB.PASSWORD'] ?= xasecure.policymgr['audit_db_password']

    module.exports.push name: 'XASecure HDFS # Upload', timeout: -1, callback: (ctx, next) ->
      {hive_url} = ctx.config.xasecure
      do_upload = ->
        ctx[if url.parse(hive_url).protocol is 'http:' then 'download' else 'upload']
          source: hive_url
          destination: '/var/tmp'
          binary: true
          not_if_exists: "/var/tmp/#{path.basename hive_url, '.tar'}"
        , (err, uploaded) ->
          return next err, ctx.PASS if err or not uploaded
          modified = true
          do_extract()
      do_extract = ->
        ctx.extract
          source: "/var/tmp/#{path.basename hive_url}"
        , (err) ->
          return next err, ctx.OK
      do_upload()

    module.exports.push name: 'XASecure Hive # Install', timeout: -1, callback: (ctx, next) ->
      {hive_conf_dir} = ctx.config.hdp
      {hive, hive_url} = ctx.config.xasecure
      modified = false
      do_configure = ->
        write = for k, v of hive
          match: RegExp "^#{quote k}=.*$", 'mg'
          replace: "#{k}=#{v}"
        ctx.write
          destination: "/var/tmp/#{path.basename hive_url, '.tar'}/install.properties"
          write: write
          eof: true
        , (err, written) ->
          return next err if err
          do_install()
      do_install = ->
        ctx.execute
          cmd: "cd /var/tmp/#{path.basename hive_url, '.tar'} && ./install.sh"
        , (err, executed) ->
          return next err if err
          do_conf()
      do_conf = ->
        # TODO, need to merge properties "hive.exec.pre.hooks", "hive.exec.post.hooks"
        ctx.hconfigure
          destination: "#{hive_conf_dir}/hive-site.xml"
          properties: 
            'hive.exec.pre.hooks': 'com.xasecure.authorization.hive.hooks.XaSecureHivePreExecuteRunHook'
            'hive.exec.post.hooks': 'com.xasecure.authorization.hive.hooks.XaSecureHivePostExecuteRunHook'
            'hive.semantic.analyzer.hook': 'com.xasecure.authorization.hive.hooks.XaSecureSemanticAnalyzerHook'
            # Overwrite com.xasecure.authentication.hive.LoginNameAuthenticator
            'hive.server2.custom.authentication.class': 'com.xasecure.authentication.hive.LoginNameAuthenticator'
            # Overwrite hive.exec.post.hooks,hive.exec.driver.run.hooks,hive.server2.authentication,hive.metastore.pre.event.listeners,hive.security.authorization.enabled,hive.security.authorization.manager,hive.semantic.analyzer.hook
            'hive.conf.restricted.list': 'hive.exec.driver.run.hooks,hive.server2.authentication,hive.metastore.pre.event.listeners,hive.security.authorization.enabled,hive.security.authorization.manager,hive.semantic.analyzer.hook,hive.exec.post.hooks'
          merge: true
        , (err, configured) ->
          return next err if err
          do_restart()
      do_restart = ->
        lifecycle.hive_metastore_restart ctx, (err) ->
          return next err if err
          lifecycle.hive_server2_restart ctx, (err) ->
            return next err if err
            next null, ctx.PASS
      do_configure()

{'fraction_non_alphanumeric': 0.13342813129517717, 'fraction_numerical': 0.0028439388553146107, 'mean_word_length': 2.5702199661590526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3065824', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2908, 'n_words': 451}