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.



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
# 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
		url = base.xpath("url/text()").first&.to_s
		urlparts = AtlConfig::JDBCURL.parse(url)
		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