Class: AtlConfig::ServerXML
- Inherits:
-
Object
- Object
- AtlConfig::ServerXML
- Defined in:
- lib/atl_config/serverxml.rb
Class Method Summary collapse
-
.dbinfo(cfgxml, dsname) ⇒ DBInfo
Extracts database info from a datasource definition in a Tomcat
server.xml
files.
Class Method Details
.dbinfo(cfgxml, dsname) ⇒ DBInfo
Extracts database info from a datasource definition in a Tomcat server.xml
files.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/atl_config/serverxml.rb', line 9 def self.dbinfo(cfgxml, dsname) config = Nokogiri::XML(cfgxml) dsname = dsname.gsub(/^java:comp\/env\//, '') datasource = config.xpath("/Server/Service/Engine[@name='Standalone']/Host[@name='localhost']/Context/Resource[@name='#{dsname}']").first if datasource then r = DBInfo.new r.user = datasource.xpath("@username")&.to_s r.password = datasource.xpath("@password")&.to_s r.jdbcurl = datasource.xpath("@url")&.to_s r.dburl = r.jdbcurl.gsub("jdbc:postgresql", "postgres") if r.jdbcurl then urlparts = AtlConfig::JDBCURL.parse(r.jdbcurl) r.dbtype = urlparts[:dbtype] r.host = urlparts[:host] r.port = if urlparts[:port] then urlparts[:port].to_i else case r.dbtype when 'postgresql' 5432 when 'mysql' 3306 else raise "Unhandled db type #{r.dbtype}" end end r.database = urlparts[:database] end r else nil end end |