Module: Jirawatch::Jira::Provisioning
- Included in:
- Jirawatch, CLI::AuthenticatedCommand, CLI::Login
- Defined in:
- lib/jirawatch/jira/provisioning.rb
Instance Method Summary collapse
- #login(username = nil, token = nil, site = nil) ⇒ Object
- #save_credentials(username, token, site) ⇒ Object
Instance Method Details
#login(username = nil, token = nil, site = nil) ⇒ Object
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 37 |
# File 'lib/jirawatch/jira/provisioning.rb', line 7 def login(username = nil, token = nil, site = nil) if username.nil? or token.nil? or site.nil? return nil unless File.exist? Jirawatch.configuration.login_file File.open(Jirawatch.configuration.login_file).each_line do |line| binding.local_variable_set line.split(' ')[0], line.split(' ')[1] end end = { username: username, password: token, site: site, context_path: '', auth_type: :basic, read_timeout: 120 } client = JIRA::Client.new() begin # Get some infos to check if login was successful client.ServerInfo.all.attrs["baseUrl"] return client rescue StandardError => e puts e. end nil end |
#save_credentials(username, token, site) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/jirawatch/jira/provisioning.rb', line 39 def save_credentials(username, token, site) File.open(Jirawatch.configuration.login_file, "w") do |f| f.write ["username #{username}", "token #{token}", "site #{site}"].join "\n" end File.chmod 0600, Jirawatch.configuration.login_file end |