jira-ruby 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/jira-ruby.gemspec +1 -0
- data/lib/jira-ruby.rb +1 -0
- data/lib/jira/client.rb +7 -3
- data/lib/jira/jwt_client.rb +32 -0
- data/lib/jira/resource/board.rb +1 -1
- data/lib/jira/version.rb +1 -1
- data/spec/jira/client_spec.rb +48 -0
- data/spec/jira/resource/board_spec.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e2f1a7c44350f6423550154d1dd1929e38f5c2af002ebc463eef3bfa035b404
|
4
|
+
data.tar.gz: 4c2eb811cb02e66ff324a062fa27edaed2cf215b87cc89856a42dde1618fb3c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f0604ca0ad23f7a4204b920f4ec90ec816033c607db5686cde519a0a00668ddf13828f03769f07f0a6cd36bee51186b02164e91ed144cf0892b5cd124d5df8
|
7
|
+
data.tar.gz: 2c7866e454e455465103803030f1fb40708d1ff9e04c09975594423884c5f84ceb43afb7ba853209ac26e8c9e12a91d3268b80452f8fb3641eee4a1556a787a8
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ rake jira:generate_public_cert
|
|
50
50
|
|
51
51
|
On Mac OS,
|
52
52
|
|
53
|
-
* Follow the instructions under "Mac OSX Installer" here: https://developer.atlassian.com/
|
53
|
+
* Follow the instructions under "Mac OSX Installer" here: https://developer.atlassian.com/server/framework/atlassian-sdk/install-the-atlassian-sdk-on-a-linux-or-mac-system
|
54
54
|
* From within the archive directory, run:
|
55
55
|
|
56
56
|
```shell
|
@@ -153,14 +153,18 @@ require 'jira-ruby'
|
|
153
153
|
# Consider the use of :use_ssl and :ssl_verify_mode options if running locally
|
154
154
|
# for tests.
|
155
155
|
|
156
|
+
# NOTE basic auth no longer works with Jira, you must generate an API token, to do so you must have jira instance access rights. You can generate a token here: https://id.atlassian.com/manage/api-tokens
|
157
|
+
|
158
|
+
# You will see JIRA::HTTPError (JIRA::HTTPError) if you attempt to use basic auth with your user's password
|
159
|
+
|
156
160
|
username = "myremoteuser"
|
157
|
-
|
161
|
+
api_token = "myApiToken"
|
158
162
|
|
159
163
|
options = {
|
160
164
|
:username => username,
|
161
|
-
:password =>
|
162
|
-
:site => 'http://localhost:8080/',
|
163
|
-
:context_path => '/myjira',
|
165
|
+
:password => api_token,
|
166
|
+
:site => 'http://localhost:8080/', # or 'https://<your_subdomain>.atlassian.net'
|
167
|
+
:context_path => '/myjira', # often blank
|
164
168
|
:auth_type => :basic,
|
165
169
|
:read_timeout => 120
|
166
170
|
}
|
data/jira-ruby.gemspec
CHANGED
data/lib/jira-ruby.rb
CHANGED
data/lib/jira/client.rb
CHANGED
@@ -25,7 +25,8 @@ module JIRA
|
|
25
25
|
# :auth_type => :oauth,
|
26
26
|
# :proxy_address => nil,
|
27
27
|
# :proxy_port => nil,
|
28
|
-
# :additional_cookies => nil
|
28
|
+
# :additional_cookies => nil,
|
29
|
+
# :default_headers => {}
|
29
30
|
#
|
30
31
|
# See the JIRA::Base class methods for all of the available methods on these accessor
|
31
32
|
# objects.
|
@@ -52,7 +53,8 @@ module JIRA
|
|
52
53
|
use_ssl: true,
|
53
54
|
use_client_cert: false,
|
54
55
|
auth_type: :oauth,
|
55
|
-
http_debug: false
|
56
|
+
http_debug: false,
|
57
|
+
default_headers: {}
|
56
58
|
}.freeze
|
57
59
|
|
58
60
|
def initialize(options = {})
|
@@ -71,6 +73,8 @@ module JIRA
|
|
71
73
|
when :oauth, :oauth_2legged
|
72
74
|
@request_client = OauthClient.new(@options)
|
73
75
|
@consumer = @request_client.consumer
|
76
|
+
when :jwt
|
77
|
+
@request_client = JwtClient.new(@options)
|
74
78
|
when :basic
|
75
79
|
@request_client = HttpClient.new(@options)
|
76
80
|
when :cookie
|
@@ -241,7 +245,7 @@ module JIRA
|
|
241
245
|
protected
|
242
246
|
|
243
247
|
def merge_default_headers(headers)
|
244
|
-
{ 'Accept' => 'application/json' }.merge(headers)
|
248
|
+
{ 'Accept' => 'application/json' }.merge(@options[:default_headers]).merge(headers)
|
245
249
|
end
|
246
250
|
end
|
247
251
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'atlassian/jwt'
|
2
|
+
|
3
|
+
module JIRA
|
4
|
+
class JwtClient < HttpClient
|
5
|
+
def make_request(http_method, url, body = '', headers = {})
|
6
|
+
# When a proxy is enabled, Net::HTTP expects that the request path omits the domain name
|
7
|
+
path = request_path(url) + "?jwt=#{jwt_header(http_method, url)}"
|
8
|
+
|
9
|
+
request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
|
10
|
+
request.body = body unless body.nil?
|
11
|
+
|
12
|
+
response = basic_auth_http_conn.request(request)
|
13
|
+
@authenticated = response.is_a? Net::HTTPOK
|
14
|
+
store_cookies(response) if options[:use_cookies]
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def jwt_header(http_method, url)
|
21
|
+
claim = Atlassian::Jwt.build_claims \
|
22
|
+
@options[:issuer],
|
23
|
+
url,
|
24
|
+
http_method.to_s,
|
25
|
+
@options[:site],
|
26
|
+
(Time.now - 60).to_i,
|
27
|
+
(Time.now + (86400)).to_i
|
28
|
+
|
29
|
+
JWT.encode claim, @options[:shared_secret]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/jira/resource/board.rb
CHANGED
@@ -31,7 +31,7 @@ module JIRA
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def issues(params = {})
|
34
|
-
path = path_base(client) + "/board/#{id}/issue
|
34
|
+
path = path_base(client) + "/board/#{id}/issue"
|
35
35
|
response = client.get(url_with_query_params(path, params))
|
36
36
|
json = self.class.parse_json(response.body)
|
37
37
|
results = json['issues']
|
data/lib/jira/version.rb
CHANGED
data/spec/jira/client_spec.rb
CHANGED
@@ -207,6 +207,54 @@ describe JIRA::Client do
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
+
context 'with jwt authentication' do
|
211
|
+
subject do
|
212
|
+
JIRA::Client.new(
|
213
|
+
issuer: 'foo',
|
214
|
+
base_url: 'https://host.tld',
|
215
|
+
shared_secret: 'shared_secret_key',
|
216
|
+
auth_type: :jwt
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
before(:each) do
|
221
|
+
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
222
|
+
.with(query: hash_including(:jwt))
|
223
|
+
.to_return(status: 200, body: '[]', headers: {})
|
224
|
+
end
|
225
|
+
|
226
|
+
include_examples 'Client Common Tests'
|
227
|
+
include_examples 'HttpClient tests'
|
228
|
+
|
229
|
+
specify { expect(subject.request_client).to be_a JIRA::JwtClient }
|
230
|
+
|
231
|
+
it 'sets the username and password' do
|
232
|
+
expect(subject.options[:shared_secret]).to eq('shared_secret_key')
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'with a incorrect jwt key' do
|
236
|
+
before do
|
237
|
+
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
238
|
+
.with(query: hash_including(:jwt))
|
239
|
+
.to_return(status: 401, body: '[]', headers: {})
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'is not authenticated' do
|
243
|
+
expect(subject.authenticated?).to be_falsey
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'raises a JIRA::HTTPError when trying to fetch projects' do
|
247
|
+
expect { subject.Project.all }.to raise_error JIRA::HTTPError
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'only returns a true for #authenticated? once we have requested some data' do
|
252
|
+
expect(subject.authenticated?).to be_falsey
|
253
|
+
expect(subject.Project.all).to be_empty
|
254
|
+
expect(subject.authenticated?).to be_truthy
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
210
258
|
context 'oauth authentication' do
|
211
259
|
subject { JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar') }
|
212
260
|
|
@@ -89,7 +89,7 @@ eos
|
|
89
89
|
|
90
90
|
allow(issues_response).to receive(:body).and_return(api_json_issues)
|
91
91
|
allow(board).to receive(:id).and_return(84)
|
92
|
-
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/issue
|
92
|
+
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/issue')
|
93
93
|
.and_return(issues_response)
|
94
94
|
expect(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
|
95
95
|
|
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: 1.
|
4
|
+
version: 1.7.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:
|
12
|
+
date: 2019-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: atlassian-jwt
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: multipart-post
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,6 +230,7 @@ files:
|
|
216
230
|
- lib/jira/has_many_proxy.rb
|
217
231
|
- lib/jira/http_client.rb
|
218
232
|
- lib/jira/http_error.rb
|
233
|
+
- lib/jira/jwt_client.rb
|
219
234
|
- lib/jira/oauth_client.rb
|
220
235
|
- lib/jira/railtie.rb
|
221
236
|
- lib/jira/request_client.rb
|
@@ -369,7 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
384
|
version: '0'
|
370
385
|
requirements: []
|
371
386
|
rubyforge_project: jira-ruby
|
372
|
-
rubygems_version: 2.7.
|
387
|
+
rubygems_version: 2.7.6
|
373
388
|
signing_key:
|
374
389
|
specification_version: 4
|
375
390
|
summary: Ruby Gem for use with the Atlassian JIRA REST API
|