Class: AtlConfig::JIRAConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/atl_config/jiraconfig.rb

Class Method Summary collapse

Class Method Details

.dbinfo(cfgxml) ⇒ DBInfo

Extracts database info from JIRA dbconfig.xml files.

Parameters:

  • cfgxml (String)

    XML Text of dbconfig.xml file

Returns:



7
8
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
# File 'lib/atl_config/jiraconfig.rb', line 7

def self.dbinfo(cfgxml)
	config = Nokogiri::XML(cfgxml)
	r = DBInfo.new
	r.datasource = config.xpath("/jira-database-config/jndi-datasource/jndi-name/text()").first&.to_s
	if !r.datasource then
		base = config.xpath("/jira-database-config/jdbc-datasource")
		r.user = base.xpath("username/text()").first&.to_s
		r.password = base.xpath("password/text()").first&.to_s
		# jdbcurl is the URL in Java/JDBC format. dburl is the URL in Ruby format
		r.jdbcurl = base.xpath("url/text()").first&.to_s
		# FIXME: it's probably more complex than this..
		r.dburl = r.jdbcurl.gsub("jdbc:postgresql", "postgres")
		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 #{dbtype}"
				end
			end
		r.database = urlparts[:database]
	end
	r
end