jira-ruby 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95a9c55b6f750bc29bdb34f6af24b252bbbf04317ca31ed9e76753a4c257f465
4
- data.tar.gz: 56e109f946831308a8a7b30c699ebd5b6b5805c5724e3ec47ba3ac252d2df0f2
3
+ metadata.gz: 113ad755633d6eb87e63d7a97d3228f6649828547c01dee1ae1900ef0d575e2d
4
+ data.tar.gz: d59620f52976814ee7db58df10213bdb512f042a8b8214789ed07288f2899b65
5
5
  SHA512:
6
- metadata.gz: ba00e2efe10f65d2804c2c556774abab8c94d1fa746ca6c681cc7a967809bbb6309000b183049cdb9f8117dc2c8f0f60e22cbd77e6973736c7ca621989977509
7
- data.tar.gz: bcfad2a8bcc354211e860ef7912eaedd202f189ccbedb03679032468d85425cc134d9e69dc1f4f8f4b0b238fa761cddbe21683e256379aafe29a1ca4d9d8a743
6
+ metadata.gz: e523698732b5cef8a220259ccf5c42c568ac7eea435ee2ed2f2018cdd25959597d23337a67fac037e00be85a8838d9d32a2c79a156da008380699d2c9529cb03
7
+ data.tar.gz: cefe63455cb070951d73420dc1144b0c0a4651836427f507d218d3eb0780936e6a740842f6f2df8f68b14be8034bb196b4f5069d21ac0c3cd9e2a4292e43b456
data/README.md CHANGED
@@ -99,7 +99,7 @@ defaults to HTTP Basic Auth.
99
99
 
100
100
  Jira supports cookie based authentication whereby user credentials are passed
101
101
  to JIRA via a JIRA REST API call. This call returns a session cookie which must
102
- then be sent to all following JIRA REST API calls.
102
+ then be sent to all following JIRA REST API calls.
103
103
 
104
104
  To enable cookie based authentication, set `:auth_type` to `:cookie`,
105
105
  set `:use_cookies` to `true` and set `:username` and `:password` accordingly.
@@ -114,7 +114,7 @@ options = {
114
114
  :context_path => '',
115
115
  :auth_type => :cookie, # Set cookie based authentication
116
116
  :use_cookies => true, # Send cookies with each request
117
- :additional_cookies => ['AUTH=vV7uzixt0SScJKg7'] # Optional cookies to send
117
+ :additional_cookies => ['AUTH=vV7uzixt0SScJKg7'] # Optional cookies to send
118
118
  # with each request
119
119
  }
120
120
 
@@ -134,15 +134,40 @@ cookie to add to the request.
134
134
 
135
135
  Some authentication schemes that require additional cookies ignore the username
136
136
  and password sent in the JIRA REST API call. For those use cases, `:username`
137
- and `:password` may be omitted from `options`.
137
+ and `:password` may be omitted from `options`.
138
138
 
139
+ ## Configuring JIRA to use Personal Access Tokens Auth
140
+ If your JIRA system is configured to support Personal Access Token authorization, minor modifications are needed in how credentials are communicated to the server. Specifically, the paremeters `:username` and `:password` are not needed. Also, the parameter `:default_headers` is needed to contain the api_token, which can be obtained following the official documentation from [Atlassian](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html). Please note that the Personal Access Token can only be used as it is. If it is encoded (with base64 or any other encoding method) then the token will not work correctly and authentication will fail.
141
+
142
+ ```ruby
143
+ require 'jira-ruby'
144
+
145
+ # NOTE: the token should not be encoded
146
+ api_token = API_TOKEN_OBTAINED_FROM_JIRA_UI
147
+
148
+ options = {
149
+ :site => 'http://mydomain.atlassian.net:443/',
150
+ :context_path => '',
151
+ :username => '<the email you sign-in to Jira>',
152
+ :password => api_token,
153
+ :auth_type => :basic
154
+ }
155
+
156
+ client = JIRA::Client.new(options)
157
+
158
+ project = client.Project.find('SAMPLEPROJECT')
159
+
160
+ project.issues.each do |issue|
161
+ puts "#{issue.id} - #{issue.summary}"
162
+ end
163
+ ```
139
164
  ## Using the API Gem in a command line application
140
165
 
141
166
  Using HTTP Basic Authentication, configure and connect a client to your instance
142
167
  of JIRA.
143
168
 
144
169
  Note: If your Jira install is hosted on [atlassian.net](atlassian.net), it will have no context
145
- path by default. If you're having issues connecting, try setting context_path
170
+ path by default. If you're having issues connecting, try setting context_path
146
171
  to an empty string in the options hash.
147
172
 
148
173
  ```ruby
data/Rakefile CHANGED
@@ -14,13 +14,13 @@ desc 'Prepare and run rspec tests'
14
14
  task :prepare do
15
15
  rsa_key = File.expand_path('rsakey.pem')
16
16
  unless File.exist?(rsa_key)
17
- raise 'rsakey.pem does not exist, tests will fail. Run `rake jira:generate_public_cert` first'
17
+ Rake::Task['jira:generate_public_cert'].invoke
18
18
  end
19
19
  end
20
20
 
21
21
  desc 'Run RSpec tests'
22
22
  # RSpec::Core::RakeTask.new(:spec)
23
- RSpec::Core::RakeTask.new(:spec) do |task|
23
+ RSpec::Core::RakeTask.new(:spec, [] => [:prepare]) do |task|
24
24
  task.rspec_opts = ['--color', '--format', 'doc']
25
25
  end
26
26
 
data/lib/jira/client.rb CHANGED
@@ -40,6 +40,7 @@ module JIRA
40
40
  # :key_path => nil,
41
41
  # :ssl_client_cert => nil,
42
42
  # :ssl_client_key => nil
43
+ # :ca_file => nil
43
44
  #
44
45
  # See the JIRA::Base class methods for all of the available methods on these accessor
45
46
  # objects.
@@ -59,6 +59,7 @@ module JIRA
59
59
  http_conn.verify_mode = @options[:ssl_verify_mode]
60
60
  http_conn.ssl_version = @options[:ssl_version] if @options[:ssl_version]
61
61
  http_conn.read_timeout = @options[:read_timeout]
62
+ http_conn.ca_file = @options[:ca_file] if @options[:ca_file]
62
63
  http_conn
63
64
  end
64
65
 
@@ -46,7 +46,7 @@ module JIRA
46
46
  # Returns the current request token if it is set, else it creates
47
47
  # and sets a new token.
48
48
  def request_token(options = {}, *arguments, &block)
49
- @request_token ||= get_request_token(options, *arguments, block)
49
+ @request_token ||= get_request_token(options, *arguments, &block)
50
50
  end
51
51
 
52
52
  # Sets the request token from a given token and secret.
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = '2.2.0'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
@@ -285,6 +285,11 @@ describe JIRA::HttpClient do
285
285
  expect(basic_client_cert_client.http_conn(uri)).to eq(http_conn)
286
286
  end
287
287
 
288
+ it 'can use a certificate authority file' do
289
+ client = JIRA::HttpClient.new(JIRA::Client::DEFAULT_OPTIONS.merge(ca_file: '/opt/custom.ca.pem'))
290
+ expect(client.http_conn(client.uri).ca_file).to eql('/opt/custom.ca.pem')
291
+ end
292
+
288
293
  it 'returns a http connection' do
289
294
  http_conn = double
290
295
  uri = double
@@ -35,6 +35,26 @@ describe JIRA::OauthClient do
35
35
  expect(oauth_client.get_request_token).to eq(request_token)
36
36
  end
37
37
 
38
+ it 'could pre-process the response body in a block' do
39
+ response = Net::HTTPSuccess.new(1.0, '200', 'OK')
40
+ allow_any_instance_of(OAuth::Consumer).to receive(:request).and_return(response)
41
+ allow(response).to receive(:body).and_return('&oauth_token=token&oauth_token_secret=secret&password=top_secret')
42
+
43
+ result = oauth_client.request_token do |response_body|
44
+ CGI.parse(response_body).each_with_object({}) do |(k, v), h|
45
+ next if k == 'password'
46
+
47
+ h[k.strip.to_sym] = v.first
48
+ end
49
+ end
50
+
51
+ expect(result).to be_an_instance_of(OAuth::RequestToken)
52
+ expect(result.consumer).to eql(oauth_client.consumer)
53
+ expect(result.params[:oauth_token]).to eql('token')
54
+ expect(result.params[:oauth_token_secret]).to eql('secret')
55
+ expect(result.params[:password]).to be_falsey
56
+ end
57
+
38
58
  it 'allows setting the request token' do
39
59
  token = double
40
60
  expect(OAuth::RequestToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
@@ -58,7 +78,7 @@ describe JIRA::OauthClient do
58
78
  request_token = OAuth::RequestToken.new(oauth_client.consumer)
59
79
  allow(oauth_client).to receive(:get_request_token).and_return(request_token)
60
80
  mock_access_token = double
61
- expect(request_token).to receive(:get_access_token).with(oauth_verifier: 'abc123').and_return(mock_access_token)
81
+ expect(request_token).to receive(:get_access_token).with({ oauth_verifier: 'abc123' }).and_return(mock_access_token)
62
82
  oauth_client.init_access_token(oauth_verifier: 'abc123')
63
83
  expect(oauth_client.access_token).to eq(mock_access_token)
64
84
  end
@@ -159,4 +179,4 @@ describe JIRA::OauthClient do
159
179
  end
160
180
  end
161
181
  end
162
- end
182
+ end
@@ -36,7 +36,7 @@ describe JIRA::Resource::IssuePickerSuggestions do
36
36
  .and_return(response)
37
37
 
38
38
  expect(client).to receive(:IssuePickerSuggestions).and_return(issue_picker_suggestions)
39
- expect(issue_picker_suggestions).to receive(:build).with('sections' => [{ 'id' => 'cs' }])
39
+ expect(issue_picker_suggestions).to receive(:build).with({ 'sections' => [{ 'id' => 'cs' }] })
40
40
 
41
41
  JIRA::Resource::IssuePickerSuggestions.all(client, 'query')
42
42
  end
@@ -47,7 +47,7 @@ describe JIRA::Resource::Issue do
47
47
  .and_return(empty_response)
48
48
 
49
49
  expect(client).to receive(:Issue).and_return(issue)
50
- expect(issue).to receive(:build).with('id' => '1', 'summary' => 'Bugs Everywhere')
50
+ expect(issue).to receive(:build).with({ 'id' => '1', 'summary' => 'Bugs Everywhere' })
51
51
 
52
52
  issues = JIRA::Resource::Issue.all(client)
53
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-12-31 00:00:00.000000000 Z
12
+ date: 2023-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -390,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
390
  - !ruby/object:Gem::Version
391
391
  version: '0'
392
392
  requirements: []
393
- rubygems_version: 3.1.6
393
+ rubygems_version: 3.3.7
394
394
  signing_key:
395
395
  specification_version: 4
396
396
  summary: Ruby Gem for use with the Atlassian JIRA REST API