197. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/29/2017 4:53:40 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

197.1 Files compared

# Location File Last Modified
1 CTT-DM CIF Submission.zip\code\rails_prisme\lib\utilities prisme_utilities.rb Fri Mar 3 16:22:10 2017 UTC
2 CTT-DM CIF Submission.zip\code\rails_prisme\lib\utilities prisme_utilities.rb Wed Mar 29 19:32:29 2017 UTC

197.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 816
Changed 2 8
Inserted 0 0
Removed 0 0

197.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

197.4 Active regular expressions

No regular expressions were active.

197.5 Comparison detail

  1   require 'u ri'
  2  
  3   #methods f or Prisme,  but not K omet go he re, for Ko met visibi lity see h elpers.rb  in rails c ommon.
  4   module Pri smeUtiliti es
  5  
  6     KOMET_AP PLICATION  = /^rails_ komet/
  7     ISAAC_AP PLICATION  = /^isaac- rest/
  8     ALL_APPL ICATION =  /.*/
  9     VALID_AP PLICATIONS  = [KOMET_ APPLICATIO N, ISAAC_A PPLICATION , ALL_APPL ICATION]
  10  
  11     class <<  self
  12       #these  do leak i nternal st ate.  In m ost cases  you should  call the  correspond ing method  below to  get a defe nsive copy
  13       #of yo ur data st ructure
  14       attr_a ccessor :s soi_logout _url
  15       attr_a ccessor :c onfig #ser ver_config .yml
  16       attr_a ccessor :a itc_env #a itc_enviro nment.yml
  17     end
  18  
  19     def self .localize_ host(host)
  20       host.g sub!('0:0: 0:0:0:0:0: 1', 'local host')
  21       host.g sub!('127. 0.0.1', 'l ocalhost')
  22       host
  23     end
  24  
  25     def self .get_proxy _contexts( tomcat_ar: , applicat ion_type:)
  26       raise  ArgumentEr ror.new "A pplication _type must  be a memb er of Pris meUtilitie s::VALID_A PPLICATION S!" unless  VALID_APP LICATIONS. include? a pplication _type
  27       uri =  nil
  28       tomcat _ar.servic e_properti es.each do  |sp|
  29         if ( sp.key.eql ? PrismeSe rvice::CAR GO_REMOTE_ URL)
  30           ur i = URI sp .value
  31           br eak
  32         end
  33       end
  34       host =  uri.host
  35       port =  uri.port
  36       contex ts = []
  37       Prisme Utilities. proxy_urls .each do | k|
  38         uri  = URI k['i ncoming_ur l_path']
  39         port  = uri.por t
  40         $log .trace(uri .host + "  : " + port .to_s)
  41         cont exts << ur i.path if  (host.eql? (uri.host)  && port.t o_s.eql?(p ort.to_s))
  42         $log .warn("ser ver_config .yaml has  a configur ation with  no contex t!  Prisme  cannot us e it for a  deploy.")  if uri.pa th.eql? '/ '
  43       end
  44       $log.i nfo("conte xts has #{ contexts}" )
  45       $log.w arn("I cou ld not fin d a valid  proxy conf ig for hos t #{host}  with port  #{port}.   Check pris me's serve r_config.y ml") if co ntexts.emp ty?
  46       contex ts.map do  |e|
  47         e[0] .eql?('/')  ? e.rever se.chop.re verse : e
  48       end.re ject do |e |
  49         e.em pty?
  50       end.re ject do |e |
  51         e !~  applicati on_type
  52       end
  53     end
  54  
  55     def self .proxy_map pings
  56       URI.pr oxy_mappin gs
  57     end
  58  
  59     def self .load_yml_ file(confi g_file, er ror_messag e)
  60       begin
  61         if F ile.exists ?(config_f ile)
  62           ha sh = YAML. load_file( config_fil e)
  63         else
  64           $l og.debug(" Config fil e #{config _file} doe s not exis t!!")
  65         end
  66       rescue  => ex
  67         $log .error(err or_message )
  68         $log .error(ex. backtrace. join("\n") )
  69       end
  70       hash
  71     end
  72  
  73     def self .synch_gro up_data(du mp_data =  false)
  74       persis tent_group _file = "# {$PROPS['P RISME.data _directory ']}/group_ data.yml"
  75       group_ file = './ config/gro up_data.ym l'
  76       config _file = Fi le.exists? (persisten t_group_fi le) ? pers istent_gro up_file :  group_file
  77       groups  = PrismeU tilities:: load_yml_f ile(config _file, "Gr oup data m ight not h ave been c reated but  PRISME wi ll continu e to start .")
  78       if gro ups.nil?
  79         $log .info("No  group yaml  file aval iable for  loading!")
  80         retu rn
  81       end
  82       create d_groups =  0
  83       skippe d_groups =  0
  84       update d_sites =  0
  85       group_ ids = grou ps.map do  |group|
  86         grou p['id']
  87       end
  88       db_gro up_ids = V aGroup.all .to_a.map  do |e|
  89         e.id
  90       end
  91       groups _to_delete  = db_grou p_ids - gr oup_ids
  92       $log.a lways("Att empting to  delete th e followin g groups:  #{groups_t o_delete}" )
  93       delete d = VaGrou p.where('i d in (?)',  groups_to _delete).d estroy_all .length
  94       $log.a lways("Del eted #{del eted} grou ps.")
  95       groups .each do | group_hash |
  96         grou p = VaGrou p.new(grou p_hash)
  97         if ( VaGroup.ex ists? grou p.id)
  98           db _group = V aGroup.fin d(group.id )
  99           if  (db_group .eql? grou p)
  100              skipped_gr oups += 1
  101              $log.debug ("I am ski pping the  group from  #{config_ file} with  group id  #{group.id }.  It alr eady exist s.")
  102           el se
  103              #we need t o update d b_site, an d record t he update
  104              begin
  105                db_group .update! n ame: group .name, mem ber_sites:  group.mem ber_sites,  member_gr oups: grou p.member_g roups
  106                updated_ sites += 1
  107                $log.alw ays("I upd ated the g roup with  group id # {db_group. id}")
  108              rescue =>  ex
  109                $log.alw ays("Updat e failed f or the gro up with gr oup id #{d b_group.id }")
  110                $log.alw ays(ex.mes sage)
  111              end
  112           en d
  113         else
  114           sa ved = true
  115           be gin
  116              group.save !
  117              $log.alway s("I saved  the group  with grou p id #{gro up.id}")
  118           re scue => ex
  119              saved = fa lse
  120              $log.warn( "Save fail ed for #{g roup.inspe ct}")
  121              $log.warn( ex.message )
  122           en d
  123           cr eated_grou ps += 1 if  saved
  124           sk ipped_grou ps += 1 un less saved
  125         end
  126       end
  127       if dum p_data
  128         dump _file = Fi le.basenam e(config_f ile, '.*')
  129         dump _file = "# {$PROPS['P RISME.data _directory ']}/#{dump _file}_#{T ime.now.to _i}.yml"
  130         File .open(dump _file, 'w' ) do |f|
  131           f. write(VaGr oup.all.to _a.map do  |e|
  132              {'id' => e .va_site_i d, 'name'  => e.name,  'member_s ites' => e .get_site_ ids, 'memb er_groups'  => e.get_ group_ids}
  133           en d.to_yaml)
  134         end
  135       end
  136       r_val  = {created _groups: c reated_gro ups, skipp ed_groups:  skipped_g roups, upd ated_group s: updated _sites, de leted_grou ps: delete d}
  137       $log.a lways("Gro up final r esults: #{ r_val}")
  138       r_val
  139     end
  140  
  141     #todo Wh en the val idators fo r the site  model gro w change t o bang(!)  methods li ke synch_g roup_data  above
  142     def self .synch_sit e_data(dum p_data = f alse)
  143       persis tent_site_ file = "#{ $PROPS['PR ISME.data_ directory' ]}/site_da ta.yml"
  144       site_f ile = './c onfig/site _data.yml'
  145       config _file = Fi le.exists? (persisten t_site_fil e) ? persi stent_site _file : si te_file
  146       sites  = PrismeUt ilities::l oad_yml_fi le(config_ file, "Sit e data mig ht not hav e been cre ated but P RISME will  continue  to start." )
  147       if sit es.nil?
  148         $log .info("No  site yaml  file avali able for l oading!")
  149         retu rn
  150       end
  151       create d_sites =  0
  152       skippe d_sites =  0
  153       update d_sites =  0
  154       site_i ds = sites .map do |s ite|
  155         site ['va_site_ id']
  156       end
  157       db_sit e_ids = Va Site.all.t o_a.map do  |e|
  158         e.va _site_id
  159       end
  160       sites_ to_delete  = db_site_ ids - site _ids
  161       $log.a lways("Att empting to  delete th e followin g sites: # {sites_to_ delete}")
  162       delete d = VaSite .where('va _site_id i n (?)', si tes_to_del ete).destr oy_all.len gth
  163       $log.a lways("Del eted #{del eted} site s.")
  164       sites. each do |s ite_hash|
  165         site  = VaSite. new(site_h ash)
  166         if ( VaSite.exi sts? site. va_site_id )
  167           db _site = Va Site.find( site.va_si te_id)
  168           if  (db_site. eql? site)
  169              skipped_si tes += 1
  170              $log.debug ("I am ski pping the  site from  #{config_f ile} with  site id #{ site.va_si te_id}.  I t already  exists")
  171           el se
  172              #we need t o update d b_site, an d record t he update
  173              updated =  db_site.up date site_ hash
  174              updated_si tes += 1 i f updated
  175              $log.alway s("I updat ed the sit e with sit e id #{db_ site.va_si te_id}")
  176           en d
  177  
  178         else
  179           sa ved = site .save
  180           cr eated_site s += 1 if  saved
  181           sk ipped_site s += 1 unl ess saved
  182         end
  183       end
  184       if dum p_data
  185         dump _file = Fi le.basenam e(config_f ile, '.*')
  186         dump _file = "# {$PROPS['P RISME.data _directory ']}/#{dump _file}_#{T ime.now.to _i}.yml"
  187         File .open(dump _file, 'w' ) do |f|
  188           f. write(VaSi te.all.to_ a.map do | e|
  189              {'va_site_ id' => e.v a_site_id,  'name' =>  e.name, ' site_type'  => e.site _type, 'me ssage_type ' => e.mes sage_type}
  190           en d.to_yaml)
  191         end
  192       end
  193       r_val  = {created _sites: cr eated_site s, skipped _sites: sk ipped_site s, updated _sites: up dated_site s, deleted _sites: de leted}
  194       $log.a lways("Sit e final re sults: #{r _val}")
  195       r_val
  196     end
  197  
  198     def self .prisme_su per_user
  199       users  = load_yml _file("#{$ PROPS['PRI SME.data_d irectory'] }/prisme_s uper_user. yml", "Adm inistrativ e Users ha ve not bee n created  but PRISME  will cont inue to st art.")
  200       return  if users. nil?
  201       begin
  202         # if  the confi g file doe s not exis t then fal lback to t he file in  the confi g director y.
  203         user s['users'] .each do | u|
  204           su  = User.fi nd_or_crea te_by(emai l: u['emai l'], admin _role_chec k: true)
  205           su .password  = u['passw ord']
  206           su .save!
  207           su .add_role( Roles::SUP ER_USER)
  208         end
  209       rescue  => ex
  210         $log .error("No t all admi nistrative  Users hav e been cre ated but P RISME will  continue  to start.  The except ion is #{e x}")
  211         $log .error(ex. backtrace. join("\n") )
  212       end
  213     end
  214  
  215     def self .applicati on_urls
  216       server _config['a pplication _urls']
  217     end
  218  
  219     def self .get_proxy
  220       server _config['p roxy_confi g_root'][' apache_url _proxy']
  221     end
  222  
  223     def self .proxy_url s
  224       server _config['p roxy_confi g_root'][' proxy_urls ']
  225     end
  226  
  227     def self .aitc_envi ronment
  228       return  (HashWith Indifferen tAccess.ne w PrismeUt ilities.ai tc_env).de ep_dup unl ess Prisme Utilities. aitc_env.n il?
  229       Prisme Utilities. aitc_env =  PrismeUti lities.fet ch_yml 'ai tc_environ ment.yml'
  230       (HashW ithIndiffe rentAccess .new Prism eUtilities .aitc_env) .deep_dup
  231     end
  232  
  233     def self .server_co nfig
  234       return  (HashWith Indifferen tAccess.ne w PrismeUt ilities.co nfig).deep _dup unles s PrismeUt ilities.co nfig.nil?
  235       Prisme Utilities. config = P rismeUtili ties.fetch _yml 'serv er_config. yml'
  236       (HashW ithIndiffe rentAccess .new Prism eUtilities .config).d eep_dup
  237     end
  238  
  239     def self .ssoi_logo ut_path
  240       logout _url = Pri smeUtiliti es.ssoi_lo gout_url
  241       return  logout_ur l unless l ogout_url. nil?
  242       config _file = Pr ismeUtilit ies.server _config
  243       return  nil unles s config_f ile
  244       logout _url = con fig_file[A PPLICATION _URLS][SSO I_LOGOUT]
  245       Prisme Utilities. ssoi_logou t_url = UR I.valid_ur l?(url_str ing: logou t_url) ? l ogout_url  : nil
  246     end
  247  
  248     #Tells i f the give n uri is u p.  If bas ic authent ication is  required  and not pr ovided fal se will be  returned.
  249     #The met hod is lig ht weight  and only f etches the  headers o f a given  url.
  250     #Sample  invocation :
  251     #PrismeU tilities.u ri_up?(uri : 'http:// www.google .com')
  252     #PrismeU tilities.u ri_up?(uri : "https:/ /vadev.man tech.com:8 080/nexus/ content/re positories /termdata/ gov/vha/is aac/db/vet s/1.0/vets -1.0-all.c radle.zip" , user: 'u ser', pass word: 'pas sword')
  253     def self .uri_up?(u ri:, user:  nil, pass word: nil)
  254       if uri .is_a? Str ing
  255         uri  = URI uri
  256       else
  257         rais e "URI mus t be a a S tring URI  or a URI o bject" unl ess uri.is _a? URI
  258       end
  259       result  = false
  260       begin
  261         path  = uri.pat h.empty? ?  '/' : uri .path
  262         resu lt = Net:: HTTP.new(u ri.host, u ri.port)
  263         resu lt.use_ssl  = uri.sch eme.eql?(' https')
  264         head  = Net::HT TP::Head.n ew(path, n il)
  265         head .basic_aut h(user, pa ssword) if  user
  266         head ers = resu lt.request  head
  267         resu lt = heade rs.kind_of ?(Net::HTT PSuccess)
  268           #  Net::HTTP. new(u, p). head('/'). kind_of? N et::HTTPOK
  269       rescue  => ex
  270         $log .warn("I c ould not c heck the U RL #{uri.p ath} at po rt #{uri.p ort} again st path #{ uri.path}  because #{ ex}.")
  271         resu lt = false
  272       end
  273       result
  274     end
  275  
  276     def self .fetch_yml (base_file )
  277       yml_fi le = Prism eUtilities .which_fil e(base_fil e)
  278       if yml _file.nil?
  279         $log .warn("No  yml file f ound! #{ba se_file}")
  280         retu rn nil
  281       end
  282       # read  the yml f ile
  283       begin
  284         retu rn HashWit hIndiffere ntAccess.n ew YAML.lo ad(ERB.new (File.read (yml_file) ).result)
  285       rescue  => ex
  286         $log .error("Er ror readin g #{yml_fi le}, error  is #{ex}" )
  287         $log .error(ex. backtrace. join("\n") )
  288       end
  289       nil
  290     end
  291  
  292     #given a  base file  selects t he prismeD ata varian t over the  config va riant
  293     def self .which_fil e(base_fil e)
  294       # defa ult the co nfig file  location b ased on th e data_dir ectory pro perty
  295       file =  "#{$PROPS ['PRISME.d ata_direct ory']}/#{b ase_file}"
  296  
  297       # if t he config  file does  not exist  then fallb ack to the  file in t he config  directory.
  298       unless  File.exis ts?(file)
  299         file  = "./conf ig/#{base_ file}"
  300       end
  301       unless  File.exis ts? file
  302         $log .warn("#{b ase_file}  not found. ")
  303         retu rn nil
  304       end
  305       file
  306     end
  307  
  308   end
  309  
  310   module URI
  311     # these  keys are u sed in the  server_co nfig yaml  file to ma p incoming  urls to t heir corre sponding p roxy locat ion
  312     PROXY_CO NFIG_ROOT  = 'proxy_c onfig_root '
  313     APACHE_U RL_PROXY =  'apache_u rl_proxy'
  314     PROXY_UR LS = 'prox y_urls'
  315     INCOMING _URL_PATH  = 'incomin g_url_path '
  316     PROXY_LO CATION = ' proxy_loca tion'
  317  
  318     class <<  self
  319       attr_a ccessor :p roxy_mappi ngs
  320     end
  321  
  322     #**
  323     # this m ethod take s the modi fied match ing url pa ths and re turns the  proxy path
  324     def prox ify
  325       # prox y_mappings  are loade d one time  once all  of the url s listed a re valid.
  326       if URI .proxy_map pings.nil?
  327         conf ig_file =  PrismeUtil ities.serv er_config
  328         retu rn self un less confi g_file
  329  
  330         # re ad the con fig yml fi le and pul l out the  proxy_root  propertie s
  331         $log .debug('in itializing  the proxy  mappings  to:')
  332         URI. proxy_mapp ings = con fig_file[P ROXY_CONFI G_ROOT]
  333         $log .debug("PR OXY MAPPIN GS ARE: #{ URI.proxy_ mappings.i nspect}")
  334  
  335         # pu ll out the  apache ho st url and  validate  it
  336         apac he_host =  URI.proxy_ mappings[A PACHE_URL_ PROXY]
  337         $log .debug("ap ache host  is #{apach e_host}")
  338         vali d_urls = U RI.valid_u rl?(url_st ring: apac he_host)
  339  
  340         # pu ll out all  of the in coming url s and vali date them
  341         URI. proxy_mapp ings[PROXY _URLS].eac h do |url_ hash|
  342           ur l = url_ha sh[INCOMIN G_URL_PATH ]
  343           va lid_urls =  valid_url s & URI.va lid_url?(u rl_string:  url) # &  will not s hort circu it
  344         end
  345  
  346         # ba il out if  we have an y invalid  urls confi gured
  347         unle ss valid_u rls
  348           UR I.proxy_ma ppings = n il
  349           re turn self
  350         end
  351  
  352         # so rt the url s from lon gest to sh ortest for   proxifyi ng
  353         URI. proxy_mapp ings[PROXY _URLS].sor t! do |a,  b|
  354           b[ INCOMING_U RL_PATH].l ength <=>  a[INCOMING _URL_PATH] .length
  355         end
  356  
  357         # fr eeze the c onfigurati on
  358         URI. proxy_mapp ings.freez e
  359         $log .debug(URI .proxy_map pings.insp ect)
  360       end
  361  
  362       # ensu re that th e apache u rl has lea ding and t railing sl ashes
  363       apache _path = UR I.proxy_ma ppings[APA CHE_URL_PR OXY].clone
  364       apache _path << ' /' unless  apache_pat h.last.eql ? '/'
  365  
  366       # iter ate the in coming url s for a ma tch that n eeds to be  proxified
  367       URI.pr oxy_mappin gs[PROXY_U RLS].each  do |url_ha sh|
  368         inco ming_url =  url_hash[ INCOMING_U RL_PATH]
  369         loca tion = url _hash[PROX Y_LOCATION ]
  370         clon e = self.c lone
  371  
  372         if ( clone.to_s .starts_wi th?(incomi ng_url) ||  (clone.to _s + '/'). starts_wit h?(incomin g_url))
  373           #w e found ou r match!!
  374           ap ache_uri =  URI(apach e_path)
  375           cl one.path < < '/' unle ss clone.p ath.last.e ql? '/'
  376  
  377           #  get the in coming url  as a URI,  check for matting an d pull out  the conte xt
  378           ma tched_uri  = URI(inco ming_url)
  379           ma tched_uri. path << '/ ' if match ed_uri.pat h.empty?
  380           ma tched_uri. path << '/ ' unless m atched_uri .path.last .eql? '/'
  381           co ntext = ma tched_uri. path
  382  
  383           #  if we have  a locatio n that con tains a co ntext then  ensure le ading and  trailing s lashes
  384           un less locat ion.eql? ' /'
  385              location =  '/' + loc ation unle ss locatio n.first.eq l? '/'
  386              location < < '/' unle ss locatio n.last.eql ? '/'
  387           en d
  388  
  389           #  operating  off of the  clone sub stitute th e context  with the l ocation an d ensure t hat the
  390           #  scheme, po rt, and ho st for the  clone lin es up with  the proxy  configura tion for a pache
  391           cl one.path.s ub!(contex t, locatio n)
  392           cl one.scheme  = apache_ uri.scheme
  393           cl one.port =  apache_ur i.port
  394           cl one.host =  apache_ur i.host
  395           re turn clone
  396         end
  397       end
  398       $log.w arn("No pr oxy mappin g found fo r #{self},  returning  self.")
  399       self
  400     end
  401   end
  402   #load('./l ib/utiliti es/prisme_ utilities. rb')
  403   # PrismeUt ilities.ai tc_environ ment
  404   # URI('htt ps://cris. com').prox ify
  405   # URI.prox y_mappings  = nil
  406  
  407   #works:
  408   # URI('htt ps:// DNS . DNS     : PORT /komet_b/f oo/faa').p roxify
  409  
  410   #irb(main) :011:0> UR I('https:/ / DNS . DNS     : PORT /komet_b/' ).proxify
  411   #=> #<URI: :HTTPS htt ps:// DNS . DNS     /server_1_ rails_fazz le/>
  412       irb(main): 012:0> URI ('https:// DNS . DNS     : PORT /komet_b') .proxify