jenkins_api_client 1.4.3 → 1.4.4

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: 12ca18252ff9b7f0212bea5bbd93c97d53c71e40
4
- data.tar.gz: 245d727b1b2b6b0f284c19e4063ad807524b3bdb
3
+ metadata.gz: 945fb4dab2fb3402f9e696d7745a0c92d103ce24
4
+ data.tar.gz: dc9f51f9e56f52282f64fa9129640e2912d9eeab
5
5
  SHA512:
6
- metadata.gz: e2095ac27903424f5ff933517ccd929b4adc0a337f9f1b13b38ab931786bf14c0ed68b21dc07071ebc3d65b217a50bdd59c1112c43d41599dcff63949500376d
7
- data.tar.gz: 5b4454172411959a0c5f7f9b801fe8046eb214275f03ce04ba5c275999c59817cfc23e3a6f9fe8303437630eba213d2f99cc84f78389e94fbb572eb9ba873b07
6
+ metadata.gz: 3984eae2ddd8d37bacb9ce7f0d8b63ace787331f7c787ced740b3c09554998e300d586544b0ee4557a080de07ef150646f4539d1abb06296604ffadaf96dc960
7
+ data.tar.gz: 963b9bce2dfe6a5e2b513ca37c5dfe3421e08a91bd86ffbb26f8c914ba3ff8887155a6d61d631fc7e487b462ec35fe93008c2ca058c8ec6a31e260f97e60bd38
@@ -4,6 +4,10 @@ CHANGELOG
4
4
  upcoming
5
5
  --------
6
6
 
7
+ v1.4.4 [09-SEP-2016]
8
+ ----------------------
9
+ * [#213][] Add support for getting a user's API token.
10
+
7
11
  v1.4.3 [07-JUN-2016]
8
12
  ----------------------
9
13
  * [#207][] Add support for SOCKS proxies. Credit: [@dylanmckay][]
@@ -341,6 +345,7 @@ v0.0.1 [15-OCT-2012]
341
345
  [#188]: https://github.com/arangamani/jenkins_api_client/issues/188
342
346
  [#191]: https://github.com/arangamani/jenkins_api_client/issues/191
343
347
  [#207]: https://github.com/arangamani/jenkins_api_client/issues/207
348
+ [#213]: https://github.com/arangamani/jenkins_api_client/issues/213
344
349
  [@AndrewHanes]: https://github.com/AndrewHanes
345
350
  [@Loa]: https://github.com/Loa
346
351
  [@Niarfe]: https://github.com/Niarfe
data/Gemfile CHANGED
@@ -2,10 +2,11 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "nokogiri", "~> 1.6.0"
4
4
  gem "thor", ">= 0.16.0"
5
- gem "json", ">= 0"
6
5
  gem "terminal-table", ">= 1.4.0"
7
6
  gem "mixlib-shellout", ">= 1.1.0"
8
7
  gem 'socksify', ">= 1.7.0"
8
+ gem 'rack', '~> 1.0'
9
+ gem 'json', '~> 1.0'
9
10
 
10
11
  group :development do
11
12
  gem "bundler", ">= 1.0"
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: jenkins_api_client 1.4.3 ruby lib
5
+ # stub: jenkins_api_client 1.4.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "jenkins_api_client"
9
- s.version = "1.4.3"
9
+ s.version = "1.4.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kannan Manickam"]
14
- s.date = "2016-06-08"
14
+ s.date = "2016-09-10"
15
15
  s.description = "\nThis is a simple and easy-to-use Jenkins Api client with features focused on\nautomating Job configuration programaticaly and so forth"
16
16
  s.email = ["arangamani.kannan@gmail.com"]
17
17
  s.executables = ["jenkinscli"]
@@ -99,10 +99,11 @@ Gem::Specification.new do |s|
99
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
100
  s.add_runtime_dependency(%q<nokogiri>, ["~> 1.6.0"])
101
101
  s.add_runtime_dependency(%q<thor>, [">= 0.16.0"])
102
- s.add_runtime_dependency(%q<json>, [">= 0"])
103
102
  s.add_runtime_dependency(%q<terminal-table>, [">= 1.4.0"])
104
103
  s.add_runtime_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
105
104
  s.add_runtime_dependency(%q<socksify>, [">= 1.7.0"])
105
+ s.add_runtime_dependency(%q<rack>, ["~> 1.0"])
106
+ s.add_runtime_dependency(%q<json>, ["~> 1.0"])
106
107
  s.add_development_dependency(%q<bundler>, [">= 1.0"])
107
108
  s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
108
109
  s.add_development_dependency(%q<rspec>, ["~> 2.14.1"])
@@ -113,10 +114,11 @@ Gem::Specification.new do |s|
113
114
  else
114
115
  s.add_dependency(%q<nokogiri>, ["~> 1.6.0"])
115
116
  s.add_dependency(%q<thor>, [">= 0.16.0"])
116
- s.add_dependency(%q<json>, [">= 0"])
117
117
  s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
118
118
  s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
119
119
  s.add_dependency(%q<socksify>, [">= 1.7.0"])
120
+ s.add_dependency(%q<rack>, ["~> 1.0"])
121
+ s.add_dependency(%q<json>, ["~> 1.0"])
120
122
  s.add_dependency(%q<bundler>, [">= 1.0"])
121
123
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
122
124
  s.add_dependency(%q<rspec>, ["~> 2.14.1"])
@@ -128,10 +130,11 @@ Gem::Specification.new do |s|
128
130
  else
129
131
  s.add_dependency(%q<nokogiri>, ["~> 1.6.0"])
130
132
  s.add_dependency(%q<thor>, [">= 0.16.0"])
131
- s.add_dependency(%q<json>, [">= 0"])
132
133
  s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
133
134
  s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
134
135
  s.add_dependency(%q<socksify>, [">= 1.7.0"])
136
+ s.add_dependency(%q<rack>, ["~> 1.0"])
137
+ s.add_dependency(%q<json>, ["~> 1.0"])
135
138
  s.add_dependency(%q<bundler>, [">= 1.0"])
136
139
  s.add_dependency(%q<jeweler>, [">= 1.6.4"])
137
140
  s.add_dependency(%q<rspec>, ["~> 2.14.1"])
@@ -113,7 +113,17 @@ module JenkinsApi
113
113
  # }
114
114
  #
115
115
  def get(user_id)
116
- response = @client.api_get_request("/user/#{path_encode user_id}")
116
+ @client.api_get_request("/user/#{path_encode user_id}")
117
+ end
118
+
119
+ def get_api_token(user_id)
120
+ response = @client.api_get_request("/user/#{path_encode user_id}/configure", nil, '')
121
+ html = Nokogiri::HTML(response)
122
+ attr = html.xpath('//input[@id="apiToken"]/@value').first
123
+ if attr.nil?
124
+ raise Exceptions::ApiException.new(@logger, "Failed to get api token")
125
+ end
126
+ attr.value
117
127
  end
118
128
 
119
129
  end
@@ -27,7 +27,7 @@ module JenkinsApi
27
27
  # Minor version of the gem
28
28
  MINOR = 4
29
29
  # Tiny version of the gem used for patches
30
- TINY = 3
30
+ TINY = 4
31
31
  # Used for pre-releases
32
32
  PRE = nil
33
33
  # Version String of Jenkins API Client.
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby1.9.1
1
+ #!/usr/bin/env ruby
2
2
  # This script provides an easier way to login to Jenkins server API.
3
3
  # It logs you in with the credentials and server details you proided and then
4
4
  # starts an IRB session so you can interactively play with the API.
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  def get_from_stdin(prompt, mask = false)
20
20
  $stdout.write(prompt)
21
-
21
+
22
22
  begin
23
23
  Kernel::system "stty -echo" if mask == true
24
24
  ret = gets.chomp!
@@ -46,7 +46,7 @@ begin
46
46
  unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)
47
47
  client_opts[:password] = prompt_for_password()
48
48
  end
49
-
49
+
50
50
  @client = JenkinsApi::Client.new(client_opts)
51
51
  puts "logged-in to the Jenkins API, use the '@client' variable to use the client"
52
52
  end
@@ -2,6 +2,16 @@ require File.expand_path('../spec_helper', __FILE__)
2
2
 
3
3
  describe JenkinsApi::Client::User do
4
4
  context "With properly initialized Client" do
5
+ ADMIN_CONFIGURE_TEXT = <<__ADMIN_CONFIGURE
6
+ <!DOCTYPE html><html><head resURL="/static/70901acb" data-rooturl="" data-resurl="/static/70901acb">
7
+ <title>User ‘admin’ Configuration [Jenkins]</title>
8
+ <link rel="stylesheet" href="/static/70901acb/css/layout-common.css" type="text/css" />
9
+ <link rel="stylesheet" href="/static/70901acb/css/style.css" type="text/css" />
10
+ <input name="_.fullName" type="text" class="setting-input " value="admin" />/td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Description</td><td class="setting-main"><textarea name="_.description" rows="5" class="setting-input "></textarea><div class="textarea-handle"></div></td><td class="setting-help"><a helpURL="/help/user/description.html" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: Description" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><link rel='stylesheet' href='/adjuncts/70901acb/lib/form/section_.css' type='text/css' /><script src='/adjuncts/70901acb/lib/form/section_.js' type='text/javascript'></script><tr name="userProperty0" style="display:none" class="row-set-start row-group-start"></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">API Token</div></td></tr><tr name="userProperty1" style="display:none" class="row-set-start row-group-start"></tr><tr><td></td><td></td><td><script src='/adjuncts/70901acb/lib/form/advanced/advanced.js' type='text/javascript'></script><div style="text-align:left" class="advancedLink"><span style="display: none" id="id245"><img src="/static/70901acb/images/24x24/notepad.png" tooltip="One or more fields in this block have been edited." style="width: 24px; height: 24px; vertical-align: baseline" class="icon-notepad icon-md" /></span> <input type="button" value="Show API Token..." class="advanced-button advancedButton" /></div><table class="advancedBody"><tbody><tr><td class="setting-leftspace"> </td><td class="setting-name">User ID</td><td class="setting-main"><input readonly="readonly" name="_." type="text" class="setting-input " value="admin" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">API Token</td><td class="setting-main"><input readonly="readonly" name="_.apiToken" id="apiToken" type="text" class="setting-input " value="12345678" /></td><td class="setting-help"><a helpURL="/descriptor/jenkins.security.ApiTokenProperty/help/apiToken" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: API Token" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><tr><td class="setting-leftspace"> </td><td class="setting-name"></td><td class="setting-main"><div style="float:right"><input onclick="validateButton('/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/changeToken','',this)" type="button" value="Change API Token" class="yui-button validate-button" /></div><div style="display:none;"><img src="/static/70901acb/images/spinner.gif" />
11
+ <input name="email.address" type="text" class="setting-input " value="" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td colspan="2"></td><td class="setting-description">Your e-mail address, like <tt>joe.chin@sun.com</tt></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">My Views</div></td></tr><tr name="userProperty4" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Default View</td><td class="setting-main">
12
+ <input checkUrl="'/user/admin/my-views/viewExistsCheck?value='+encodeURIComponent(this.value)+'&amp;exists=true'" name="_.primaryViewName" type="text" class="setting-input validated " value="" /></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr><td colspan="2"></td><td class="setting-description">The view selected by default when navigating to the users private views</td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">SSH Public Keys</div></td></tr><tr name="userProperty7" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">SSH Public Keys</td><td class="setting-main"><textarea name="_.authorizedKeys" rows="5" class="setting-input "></textarea><div class="textarea-handle"></div></td><td class="setting-help"><a helpURL="/descriptor/org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl/help/authorizedKeys" href="#" class="help-button"><img src="/static/70901acb/images/16x16/help.png" alt="Help for feature: SSH Public Keys" style="width: 16px; height: 16px; " class="icon-help icon-sm" /></a></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="help-area"><td></td><td colspan="2"><div class="help">Loading...</div></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div class="section-header">Setting for search</div></td></tr><tr name="userProperty8" style="display:none" class="row-set-start row-group-start"></tr><tr><td class="setting-leftspace"> </td><td class="setting-name">Case-sensitivity</td><td class="setting-main"><input name="insensitiveSearch" type="checkbox" class=" " /><label class="attach-previous">Insensitive search tool</label></td><td class="setting-no-help"></td></tr><tr class="validation-error-area"><td colspan="2"></td><td></td><td></td></tr><tr class="row-set-end row-group-end"></tr><tr><td colspan="4"><div id="bottom-sticker"><div class="bottom-sticker-inner"><input name="Submit" type="submit" value="Save" class="submit-button primary" /><script src='/adjuncts/70901acb/lib/form/apply/apply.js' type='text/javascript'></script><input type="hidden" name="core:apply" value="" /><input name="Apply" type="button" value="Apply" class="apply-button applyButton" /></div></div></td></tr></table></form><script src='/adjuncts/70901acb/lib/form/confirm.js' type='text/javascript'></script></div></div><footer><div class="container-fluid"><div class="row"><div class="col-md-6" id="footer"></div><div class="col-md-18"><span class="page_generated">Page generated: Sep 10, 2016 12:54:41 AM UTC</span><span class="rest_api"><a href="api/">REST API</a></span><span class="jenkins_ver"><a href="http://jenkins-ci.org/">Jenkins ver. 2.7.4</a></span></div></div></div></footer></body></html>
13
+ __ADMIN_CONFIGURE
14
+
5
15
  FRED_TXT = <<__FRED
6
16
  {
7
17
  "absoluteUrl" : "https://myjenkins.example.com/jenkins/user/fred",
@@ -88,6 +98,7 @@ __USERLIST
88
98
  @client.stub(:api_get_request).with('/user/Fred%20Flintstone').and_return(FRED_JSON)
89
99
  @client.stub(:api_get_request).with('/user/fred').and_return(FRED_JSON)
90
100
  @client.stub(:api_get_request).with('/user/wilma').and_return(WILMA_JSON)
101
+ @client.stub(:api_get_request).with('/user/admin/configure', nil, '').and_return(ADMIN_CONFIGURE_TEXT)
91
102
  @user = JenkinsApi::Client::User.new(@client)
92
103
  end
93
104
 
@@ -121,6 +132,12 @@ __USERLIST
121
132
  end
122
133
  end
123
134
 
135
+ describe "#get_api_token" do
136
+ it "returns the user's API token" do
137
+ @user.get_api_token('admin').should eq('12345678')
138
+ end
139
+ end
140
+
124
141
  end
125
142
  end
126
143
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kannan Manickam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-08 00:00:00.000000000 Z
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.16.0
41
- - !ruby/object:Gem::Dependency
42
- name: json
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: terminal-table
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,34 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: 1.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement