Module: Jirawatch::Jira::Provisioning

Included in:
Jirawatch, CLI::AuthenticatedCommand, CLI::Login
Defined in:
lib/jirawatch/jira/provisioning.rb

Instance Method Summary collapse

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 (username = nil, token = nil, site = nil)
  if username.nil? or token.nil? or site.nil?

    return nil unless File.exist? Jirawatch.configuration.

    File.open(Jirawatch.configuration.).each_line do |line|
      binding.local_variable_set line.split(' ')[0], line.split(' ')[1]
    end

  end

  options = {
      username: username,
      password: token,
      site: site,
      context_path: '',
      auth_type: :basic,
      read_timeout: 120
  }

  client = JIRA::Client.new(options)
  begin
    # Get some infos to check if login was successful
    client.ServerInfo.all.attrs["baseUrl"]
    return client
  rescue StandardError => e
    puts e.message
  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., "w") do |f|
    f.write ["username #{username}", "token #{token}", "site #{site}"].join "\n"
  end
  File.chmod 0600, Jirawatch.configuration.
end