jenkins2 0.0.3 → 0.1.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
  SHA1:
3
- metadata.gz: 1ba54e27b6825938f528fce8c70d77c74b924769
4
- data.tar.gz: 6c1bb33d1c0222772ecef7c8064bcb1c55ff6fc2
3
+ metadata.gz: 89eb3788e74b3dca921bb2f0cbe47532563fda46
4
+ data.tar.gz: e1f46c1ccabb5c259cc650dc9cdf1041ca627429
5
5
  SHA512:
6
- metadata.gz: fc3ab9903dd6572e041fe80043dc7bde7894ff3d0949a93e1da0322f43b50a7e28d531f708d02194d2c9603d05d21640f3e053eb06b63a27787262c50e45ff7a
7
- data.tar.gz: 207f188a8535039a6fb918aa1beaef81042355def49050b9bd4c468deb3badc67c26d71cbb34df6d04a1452192d1b689b5fc480479cfe348bba8ff23366324a5
6
+ metadata.gz: dd24ec55acd234fa995b76b35a826a67058fc59df0f4cec26319780bcfce28547f955f39ebc4b598a365c0a06429fca2598868eb8b2198fceea33ae01e5f5e55
7
+ data.tar.gz: 9743457399f767bba6cea77a0e7d61bafd9207ca5da14fac17891f6230256984bc6c545f5236a48c80008f7000339e01a5cf2770ca2f950714c0ce58fe7cd0a1
@@ -1,7 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.1.0](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.1.0) (2017-10-11)
4
+
5
+ ### Enhancements
6
+
7
+ - Support Crumbs
8
+ - Can forcefully restart Jenkins
9
+
3
10
  ## [v0.0.2](https://bitbucket.org/DracoAter/jenkins2/commits/tag/v0.0.2) (2016-10-25)
11
+
4
12
  ### Enhancements
13
+
5
14
  - Hopefully this gem is now usable
6
15
  - Get Jenkins version
7
16
  - Prepare for / cancel Jenkins shutdown
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'openssl'
2
3
  require 'json'
3
4
 
4
5
  require_relative 'log'
@@ -23,6 +24,7 @@ module Jenkins2
23
24
  @server = args[:server]
24
25
  @user = args[:user]
25
26
  @key = args[:key]
27
+ @crumb = nil
26
28
  end
27
29
 
28
30
  # Returns Jenkins version
@@ -36,6 +38,12 @@ module Jenkins2
36
38
  api_request( :post, '/quietDown' )
37
39
  end
38
40
 
41
+ # Forcefully restart Jenkins NOW!
42
+ # Parameters are ignored
43
+ def restart!( **args )
44
+ api_request( :post, '/restart' )
45
+ end
46
+
39
47
  # Cancels the effect of +prepare-for-shutdown+ command.
40
48
  # Parameters are ignored
41
49
  def cancel_shutdown( **args )
@@ -74,12 +82,28 @@ module Jenkins2
74
82
  when :post then Net::HTTP::Post
75
83
  end.new( URI File.join( @server, URI.escape( path ) ) )
76
84
  Log.debug { "Request: #{method} #{req.uri}" }
77
- req.basic_auth @user, @key if credentials_provided?
85
+ req.basic_auth @user, @key
78
86
  yield req if block_given?
79
87
  req.content_type ||= 'application/x-www-form-urlencoded'
80
88
  Log.debug { "Request content_type: #{req.content_type}, body: #{req.body}" }
81
- response = Net::HTTP.start( req.uri.hostname, req.uri.port ){ |http| http.request req }
82
- handle_response( response, reply_with )
89
+ begin
90
+ req[@crumb["crumbRequestField"]] = @crumb["crumb"] if @crumb
91
+ response = Net::HTTP.start( req.uri.hostname, req.uri.port, use_ssl: req.uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE ) do |http|
92
+ http.request req
93
+ end
94
+ handle_response( response, reply_with )
95
+ rescue Net::HTTPServerException => e
96
+ if e.message == "403 \"No valid crumb was included in the request\""
97
+ update_crumbs
98
+ retry
99
+ else
100
+ raise
101
+ end
102
+ end
103
+ end
104
+
105
+ def update_crumbs
106
+ @crumb = api_request( :get, '/crumbIssuer/api/json' )
83
107
  end
84
108
 
85
109
  def handle_response( response, reply_with )
@@ -94,16 +118,10 @@ module Jenkins2
94
118
  when Net::HTTPRedirection
95
119
  response['location']
96
120
  when Net::HTTPClientError, Net::HTTPServerError
97
- Log.error { "Response: #{response.code}, #{response.body}" }
98
121
  response.value
99
122
  else
100
- Log.error { "Response: #{response.code}, #{response.body}" }
101
123
  response.value
102
124
  end
103
125
  end
104
-
105
- def credentials_provided?
106
- @user and @key
107
- end
108
126
  end
109
127
  end
@@ -1,3 +1,3 @@
1
1
  module Jenkins2
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juri Timošin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-kitchen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.17'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: kitchen-lxd
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
83
111
  description: Command line interface and API client for Jenkins 2. Allows manipulating
84
112
  nodes, jobs, plugins, credentials. See README.md for details.
85
113
  email: draco.ater@gmail.com
@@ -124,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
152
  version: '0'
125
153
  requirements: []
126
154
  rubyforge_project:
127
- rubygems_version: 2.6.11
155
+ rubygems_version: 2.5.2
128
156
  signing_key:
129
157
  specification_version: 4
130
158
  summary: Command line interface and API client for Jenkins 2.