rundeck 0.0.3.pre → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +0 -10
- data/.travis.yml +1 -1
- data/lib/rundeck/client.rb +61 -3
- data/lib/rundeck/client/execution.rb +194 -0
- data/lib/rundeck/client/{jobs.rb → job.rb} +19 -36
- data/lib/rundeck/client/{keys.rb → key.rb} +42 -20
- data/lib/rundeck/configuration.rb +5 -1
- data/lib/rundeck/objectified_hash.rb +13 -3
- data/lib/rundeck/request.rb +7 -1
- data/lib/rundeck/version.rb +1 -1
- data/rundeck.gemspec +2 -1
- data/spec/cassettes/12/abort_execution_not_running.yml +41 -0
- data/spec/cassettes/12/abort_execution_valid.yml +41 -0
- data/spec/cassettes/12/abort_executions_invalid.yml +41 -0
- data/spec/cassettes/12/bulk_delete_executions_invalid.yml +46 -0
- data/spec/cassettes/12/bulk_delete_executions_valid.yml +41 -0
- data/spec/cassettes/12/create_private_key.yml +64 -0
- data/spec/cassettes/12/create_public_key.yml +38 -0
- data/spec/cassettes/12/delete_execution_invalid.yml +41 -0
- data/spec/cassettes/12/delete_execution_valid.yml +32 -0
- data/spec/cassettes/12/delete_job_executions.yml +41 -0
- data/spec/cassettes/12/delete_job_executions_invalid.yml +41 -0
- data/spec/cassettes/12/delete_job_invalid.yml +41 -0
- data/spec/cassettes/12/delete_job_valid.yml +32 -0
- data/spec/cassettes/12/delete_key_invalid.yml +41 -0
- data/spec/cassettes/12/delete_key_private.yml +32 -0
- data/spec/cassettes/12/delete_key_public.yml +32 -0
- data/spec/cassettes/12/execution_invalid.yml +41 -0
- data/spec/cassettes/12/execution_query_invalid.yml +39 -0
- data/spec/cassettes/12/execution_query_no_params_valid.yml +124 -0
- data/spec/cassettes/12/execution_state_invalid.yml +41 -0
- data/spec/cassettes/12/execution_state_valid.yml +39 -0
- data/spec/cassettes/12/execution_valid.yml +60 -0
- data/spec/cassettes/12/export_job_xml.yml +234 -0
- data/spec/cassettes/12/export_job_yaml.yml +228 -0
- data/spec/cassettes/12/import_job_xml.yml +69 -0
- data/spec/cassettes/12/import_job_yaml.yml +63 -0
- data/spec/cassettes/12/job.yml +84 -0
- data/spec/cassettes/12/job_executions.yml +96 -0
- data/spec/cassettes/12/jobs.yml +76 -0
- data/spec/cassettes/12/key_contents_direct.yml +67 -0
- data/spec/cassettes/12/key_contents_multiple.yml +38 -0
- data/spec/cassettes/12/key_contents_private.yml +35 -0
- data/spec/cassettes/12/key_metadata_direct.yml +35 -0
- data/spec/cassettes/12/key_metadata_multiple.yml +38 -0
- data/spec/cassettes/12/keys_direct.yml +35 -0
- data/spec/cassettes/12/keys_multiple.yml +38 -0
- data/spec/cassettes/12/keys_none.yml +34 -0
- data/spec/cassettes/12/run_job_invalid.yml +44 -0
- data/spec/cassettes/12/run_job_valid.yml +77 -0
- data/spec/cassettes/12/running_jobs_multiple.yml +70 -0
- data/spec/cassettes/12/running_jobs_none.yml +39 -0
- data/spec/cassettes/12/running_jobs_single.yml +55 -0
- data/spec/cassettes/12/update_private_key.yml +96 -0
- data/spec/cassettes/12/update_public_key.yml +70 -0
- data/spec/rundeck/client/execution_spec.rb +346 -0
- data/spec/rundeck/client/job_spec.rb +175 -0
- data/spec/rundeck/client/key_spec.rb +223 -0
- data/spec/spec_helper.rb +15 -60
- data/spec/support/helpers.rb +136 -0
- metadata +118 -35
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/job.xml +0 -17
- data/spec/fixtures/job_executions.xml +0 -31
- data/spec/fixtures/job_run.xml +0 -16
- data/spec/fixtures/jobs_import.xml +0 -23
- data/spec/fixtures/jobs_my_project.xml +0 -14
- data/spec/fixtures/jobs_xml.xml +0 -32
- data/spec/fixtures/jobs_yaml.xml +0 -22
- data/spec/fixtures/key_contents_public.xml +0 -1
- data/spec/fixtures/key_private.xml +0 -8
- data/spec/fixtures/key_public.xml +0 -7
- data/spec/fixtures/keys.xml +0 -27
- data/spec/rundeck/client/jobs_spec.rb +0 -181
- data/spec/rundeck/client/keys_spec.rb +0 -216
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff00bf23f1fde03b1f603132d506ae0695e02827
|
4
|
+
data.tar.gz: fb4a1f1a7b74dac64e73e03a5c23d2acdd089d99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51e3995a9bb9ac36d5fe7522e9e98ca6d685b65d6b11b9fbf453c32c34883852976651fedf0fbf85b1fbf70d84291629681fca273ad358bdfc8c224ac57c3d9
|
7
|
+
data.tar.gz: 57094ebfae59988afb663fadda7ae78e0244feda93da93dc77e586dad0f20f08787999ede8de7a73014a7ff211b23eaf427fa1809a2b2ec872eb77eb2cfd9018
|
data/.rubocop.yml
CHANGED
@@ -5,3 +5,13 @@ inherit_from: .rubocop_todo.yml
|
|
5
5
|
# Lots of crappy false-positives from this cop. Go home!
|
6
6
|
GuardClause:
|
7
7
|
Enabled: false
|
8
|
+
|
9
|
+
# Sometimes the method is legitimately longer but not complex.
|
10
|
+
# See spec/support/helpers.rb#job_xml
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 30
|
13
|
+
|
14
|
+
# I am a big fan of lines 80 chars and less. However, in some cases it makes
|
15
|
+
# sense to let the line exceed that length, especially in specs.
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 500
|
data/.rubocop_todo.yml
CHANGED
@@ -9,16 +9,6 @@
|
|
9
9
|
Metrics/CyclomaticComplexity:
|
10
10
|
Max: 10
|
11
11
|
|
12
|
-
# Offense count: 1
|
13
|
-
# Configuration parameters: AllowURI.
|
14
|
-
Metrics/LineLength:
|
15
|
-
Max: 159
|
16
|
-
|
17
|
-
# Offense count: 1
|
18
|
-
# Configuration parameters: CountComments.
|
19
|
-
Metrics/MethodLength:
|
20
|
-
Max: 12
|
21
|
-
|
22
12
|
# Offense count: 2
|
23
13
|
Style/Documentation:
|
24
14
|
Severity: warning
|
data/.travis.yml
CHANGED
data/lib/rundeck/client.rb
CHANGED
@@ -1,15 +1,73 @@
|
|
1
1
|
module Rundeck
|
2
2
|
# Wrapper for the Rundeck REST API.
|
3
3
|
class Client < API
|
4
|
+
# Macros to simplify client method documentation.
|
5
|
+
|
6
|
+
# @!macro [new] options
|
7
|
+
# @param [Hash] options A set of options passed directly to HTTParty. See
|
8
|
+
# http://rubydoc.info/gems/httparty/HTTParty/ClassMethods
|
9
|
+
# @option options [Hash] :query The parameters to pass with the request
|
10
|
+
# Use this hash to specify Rundeck parameters.
|
11
|
+
# - +query: { project: 'anvils', id: '123456' }+
|
12
|
+
|
13
|
+
# @!macro [new] exceptions
|
14
|
+
# @raise [Rundeck::Error::BadRequest] 400 error - Most likely indicates a
|
15
|
+
# required parameter is missing.
|
16
|
+
# @raise [Rundeck::Error::Unauthorized] 401 error - Unauthorized
|
17
|
+
# @raise [Rundeck::Error::Forbidden] 403 forbidden - ACL policies prevent
|
18
|
+
# accessing the given resource
|
19
|
+
# @raise [Rundeck::Error::NotFound] 404 not found - Indicates a resource
|
20
|
+
# could not be found at the location
|
21
|
+
# @raise [Rundeck::Error::MethodNotAllowed] 405 method not allowed - The
|
22
|
+
# request method is not allowed. This probably indicates a
|
23
|
+
# misconfiguration in a reverse proxy, such as Nginx or Apache
|
24
|
+
# @raise [Rundeck::Error::Conflict] 409 conflict - A conflicting resource
|
25
|
+
# exists.
|
26
|
+
# @raise [Rundeck::Error::InternalServerError] 500 server error -
|
27
|
+
# Indicates the Rundeck server experienced an error.
|
28
|
+
# @raise [Rundeck::Error::BadGateway] 502 bad gateway - Indicates
|
29
|
+
# something probably isn't working right or is misconfigured on the
|
30
|
+
# Rundeck server.
|
31
|
+
# @raise [Rundeck::Error::ServiceUnavailable] 503 error - Indicates an
|
32
|
+
# issue on the Rundeck server.
|
33
|
+
|
34
|
+
# @!macro [new] has_optional_params
|
35
|
+
# @note This method has optional Rundeck parameters that can be passed
|
36
|
+
# to the options parameter. See Rundeck API documentation
|
37
|
+
# for more information.
|
38
|
+
# - +query: { param1: 'value', param2: 'value' }+
|
39
|
+
|
40
|
+
# @!macro [new] has_required_params
|
41
|
+
# @note This method has required Rundeck parameters that can be passed
|
42
|
+
# to the options parameter. See Rundeck API documentation
|
43
|
+
# for more information.
|
44
|
+
# - +query: { param1: 'value', param2: 'value' }+
|
45
|
+
|
46
|
+
# @!macro [new] has_required_and_optional_params
|
47
|
+
# @note This method has both required and optional Rundeck parameters that
|
48
|
+
# can be passed to the options parameter. See Rundeck API documentation
|
49
|
+
# for more information.
|
50
|
+
# - +query { param1: 'value', param2: 'value' }+
|
51
|
+
|
4
52
|
Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
|
5
53
|
|
6
|
-
include
|
7
|
-
include
|
54
|
+
include Execution
|
55
|
+
include Job
|
56
|
+
include Key
|
8
57
|
|
58
|
+
# Turn a hash into an object for easy accessibility.
|
59
|
+
#
|
60
|
+
# @note This method will objectify nested hashes/arrays.
|
61
|
+
#
|
62
|
+
# @param [Hash, Array] result An array or hash of results to turn into
|
63
|
+
# an object
|
64
|
+
# @return [Rundeck::ObjectifiedHash] if +result+ was a hash
|
65
|
+
# @return [Rundeck::ObjectifiedHash] if +result+ was an array
|
66
|
+
# @raise [Array<Rundeck::Error::Parsing>] Error objectifying array or hash
|
9
67
|
def objectify(result)
|
10
68
|
if result.is_a?(Hash)
|
11
69
|
ObjectifiedHash.new(result)
|
12
|
-
elsif result.is_a?
|
70
|
+
elsif result.is_a?(Array)
|
13
71
|
result.map! { |e| ObjectifiedHash.new(e) }
|
14
72
|
elsif result.nil?
|
15
73
|
nil
|
@@ -0,0 +1,194 @@
|
|
1
|
+
module Rundeck
|
2
|
+
class Client
|
3
|
+
# Defines methods related to executions.
|
4
|
+
module Execution
|
5
|
+
# Execute a job
|
6
|
+
#
|
7
|
+
# @!macro has_optional_params
|
8
|
+
#
|
9
|
+
# @see http://rundeck.org/docs/api/index.html#running-a-job
|
10
|
+
# Rundeck API documentation for 'POST /api/12/job/[ID]/executions'
|
11
|
+
# endpoint
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Rundeck.execute_job('c07518ef-b697-4792-9a59-5b4f08855b67')
|
15
|
+
# Rundeck.run_job('c07518ef-b697-4792-9a59-5b4f08855b67')
|
16
|
+
#
|
17
|
+
# @param [String] id Job id
|
18
|
+
# @!macro options
|
19
|
+
# @return [Rundeck::ObjectifiedHash]
|
20
|
+
# @!macro exceptions
|
21
|
+
def execute_job(id, options = {})
|
22
|
+
objectify post("/job/#{id}/executions", options)['result']['executions']['execution']
|
23
|
+
end
|
24
|
+
alias_method :run_job, :execute_job
|
25
|
+
|
26
|
+
# Get executions for a specific job.
|
27
|
+
#
|
28
|
+
# @!macro has_optional_params
|
29
|
+
#
|
30
|
+
# @see http://rundeck.org/docs/api/index.html#getting-executions-for-a-job
|
31
|
+
# Rundeck API documentation for 'GET /api/1/job/[ID]/executions'
|
32
|
+
# endpoint
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Rundeck.job_executions('c07518ef-b697-4792-9a59-5b4f08855b67')
|
36
|
+
#
|
37
|
+
# @param [String] id Job id
|
38
|
+
# @!macro options
|
39
|
+
# @return [Rundeck::ObjectifiedHash]
|
40
|
+
# @!macro exceptions
|
41
|
+
def job_executions(id, options = {})
|
42
|
+
r = get("/job/#{id}/executions", options)['result']['executions']['execution']
|
43
|
+
objectify r
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get all running job executions
|
47
|
+
#
|
48
|
+
# @!macro has_required_params
|
49
|
+
#
|
50
|
+
# @see http://rundeck.org/docs/api/index.html#listing-running-executions
|
51
|
+
# Rundeck API documentation for 'GET /api/1/executions/running' endpoint
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# Rundeck.running_job_executions('anvils')
|
55
|
+
#
|
56
|
+
# @param [String] project List running executions from this project
|
57
|
+
# @!macro options
|
58
|
+
# @return [nil] if no running executions
|
59
|
+
# @return [Rundeck::ObjectifiedHash] if a single running job execution
|
60
|
+
# @return [Array<Rundeck::ObjectifiedHash>] if multiple running job executions
|
61
|
+
# @!macro exceptions
|
62
|
+
# def running_job_executions(project, options = {})
|
63
|
+
# options[:query] = {} if options[:query].nil?
|
64
|
+
# options[:query]['project'] = project
|
65
|
+
# r = get('/executions/running', options)
|
66
|
+
#
|
67
|
+
# if objectify(r['result']['executions']).count != '0'
|
68
|
+
# objectify r['result']['executions']['execution']
|
69
|
+
# else
|
70
|
+
# nil
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
# Delete all executions for a specific job
|
75
|
+
#
|
76
|
+
# @see http://rundeck.org/docs/api/index.html#delete-all-executions-for-a-job
|
77
|
+
# Rundeck API documentation for 'DELETE /api/12/job/[ID]/executions'
|
78
|
+
# endpoint
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# Rundeck.delete_job_executions('c07518ef-b697-4792-9a59-5b4f08855b67')
|
82
|
+
#
|
83
|
+
# @param [String] id Job id
|
84
|
+
# @!macro options
|
85
|
+
# @return [Rundeck::ObjectifiedHash]
|
86
|
+
# @!macro exceptions
|
87
|
+
def delete_job_executions(id, options = {})
|
88
|
+
objectify delete("/job/#{id}/executions", options)['deleteExecutions']
|
89
|
+
end
|
90
|
+
|
91
|
+
# Delete an execution
|
92
|
+
#
|
93
|
+
# @see http://rundeck.org/docs/api/index.html#delete-an-execution
|
94
|
+
# Rundeck API documentation for 'DELETE /api/12/execution/[ID]' endpoint
|
95
|
+
#
|
96
|
+
# @param [String] id Execution id
|
97
|
+
# @!macro options
|
98
|
+
# @return [nil] If the delete was successful
|
99
|
+
# @!macro exceptions
|
100
|
+
def delete_execution(id, options = {})
|
101
|
+
delete("/execution/#{id}", options)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Abort a running execution
|
105
|
+
#
|
106
|
+
# @!macro has_optional_params
|
107
|
+
#
|
108
|
+
# @see http://rundeck.org/docs/api/index.html#aborting-executions
|
109
|
+
# Rundeck API documentation for 'POST /api/1/execution/[ID]/abort'
|
110
|
+
# endpoint
|
111
|
+
#
|
112
|
+
# @param [String] id Execution id
|
113
|
+
# @!macro options
|
114
|
+
# @return [Rundeck::ObjectifiedHash]
|
115
|
+
# @!macro exceptions
|
116
|
+
def abort_execution(id, options = {})
|
117
|
+
objectify post("/execution/#{id}/abort", options)['abort']
|
118
|
+
end
|
119
|
+
|
120
|
+
# Get info for an execution
|
121
|
+
#
|
122
|
+
# @see http://rundeck.org/docs/api/index.html#execution-info
|
123
|
+
# Rundeck API documentation for 'GET /api/1/execution/[ID]' endpoint
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# Rundeck.execution('c07518ef-b697-4792-9a59-5b4f08855b67'')
|
127
|
+
#
|
128
|
+
# @param [String] id Execution id
|
129
|
+
# @!macro options
|
130
|
+
# @return [Rundeck::ObjectifiedHash]
|
131
|
+
# @!macro exceptions
|
132
|
+
def execution(id, options = {})
|
133
|
+
objectify get("/execution/#{id}", options)['result']['executions']['execution']
|
134
|
+
end
|
135
|
+
|
136
|
+
# Bulk delete executions
|
137
|
+
#
|
138
|
+
# @see http://rundeck.org/docs/api/index.html#bulk-delete-executions
|
139
|
+
# Rundeck API documentation for 'POST /api/12/executions/delete'
|
140
|
+
#
|
141
|
+
# @param [String] ids An array of execution ids to delete
|
142
|
+
# @!macro options
|
143
|
+
# @return [Rundeck::ObjectifiedHash]
|
144
|
+
# @raise [Rundeck::Error::InvalidAttribites] if ids is not an array
|
145
|
+
# @!macro exceptions
|
146
|
+
def bulk_delete_executions(ids, options = {})
|
147
|
+
unless ids.is_a?(Array)
|
148
|
+
fail Rundeck::Error::InvalidAttributes, '`ids` must be an array of ids'
|
149
|
+
end
|
150
|
+
|
151
|
+
options[:query] = {} if options[:query].nil?
|
152
|
+
options[:query].merge!(ids: ids.join(','))
|
153
|
+
objectify post('/executions/delete', options)['deleteExecutions']
|
154
|
+
end
|
155
|
+
|
156
|
+
# Get the state of an execution
|
157
|
+
#
|
158
|
+
# @see http://rundeck.org/docs/api/index.html#execution-state
|
159
|
+
# Rundeck API documentation for 'GET /api/12/execution/[ID]/state'
|
160
|
+
#
|
161
|
+
# @param [String] id Execution ID
|
162
|
+
# @!macro options
|
163
|
+
# @return [Rundeck::ObjectifiedHash]
|
164
|
+
# @!macro exceptions
|
165
|
+
def execution_state(id, options = {})
|
166
|
+
objectify get("/execution/#{id}/state", options)['result']['executionState']
|
167
|
+
end
|
168
|
+
|
169
|
+
# Query for executions based on job or execution details.
|
170
|
+
#
|
171
|
+
# @note This method maps to an advanced Rundeck endpoint. View the Rundeck
|
172
|
+
# API documentation and understand what query parameters are required.
|
173
|
+
# Responses may include paging details. Recall this method with the
|
174
|
+
# next set of paging values to retrieve more elements.
|
175
|
+
#
|
176
|
+
# @see http://rundeck.org/docs/api/index.html#execution-query
|
177
|
+
# Rundeck API documentation for 'GET /api/12/executions'
|
178
|
+
# def execution_query(project, options = {})
|
179
|
+
# options[:query] = {} if options[:query].nil?
|
180
|
+
# options[:query]['project'] = project
|
181
|
+
#
|
182
|
+
# objectify get('/executions', options)['result']
|
183
|
+
# end
|
184
|
+
|
185
|
+
# def execution_output()
|
186
|
+
#
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# def execution_output_with_state()
|
190
|
+
#
|
191
|
+
# end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
1
|
module Rundeck
|
2
2
|
class Client
|
3
|
-
# Defines methods related to
|
4
|
-
module
|
3
|
+
# Defines methods related to jobs.
|
4
|
+
module Job
|
5
5
|
# Gets a list of jobs for a specific project.
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
# Rundeck.jobs('project')
|
9
9
|
#
|
10
10
|
# @param [String] project Project name
|
11
|
-
#
|
11
|
+
# @!macro options
|
12
12
|
# @return [Array<Rundeck::ObjectifiedHash>]
|
13
|
+
# @!macro exceptions
|
13
14
|
def jobs(project, options = {})
|
14
15
|
objectify get("/project/#{project}/jobs", options)['jobs']['job']
|
15
16
|
end
|
@@ -19,49 +20,27 @@ module Rundeck
|
|
19
20
|
# @example Rundeck.job('c07518ef-b697-4792-9a59-5b4f08855b67')
|
20
21
|
#
|
21
22
|
# @param [String] id Job id
|
22
|
-
#
|
23
|
+
# @!macro options
|
23
24
|
# @return [Rundeck::ObjectifiedHash]
|
25
|
+
# @!macro exceptions
|
24
26
|
def job(id, options = {})
|
25
27
|
objectify get("/job/#{id}", options)['joblist']['job']
|
26
28
|
end
|
27
29
|
|
28
30
|
# Delete a job
|
29
31
|
#
|
32
|
+
# @TODO: What does this return?!
|
33
|
+
#
|
30
34
|
# @example
|
31
35
|
# Rundeck.delete_job('c07518ef-b697-4792-9a59-5b4f08855b67')
|
32
36
|
#
|
33
37
|
# @param [String] id Job id
|
34
|
-
#
|
35
|
-
#
|
38
|
+
# @!macro options
|
39
|
+
# @!macro exceptions
|
36
40
|
def delete_job(id, options = {})
|
37
41
|
delete("/job/#{id}", options)
|
38
42
|
end
|
39
43
|
|
40
|
-
# Get executions for a specific job
|
41
|
-
#
|
42
|
-
# @example
|
43
|
-
# Rundeck.job_executions('c07518ef-b697-4792-9a59-5b4f08855b67')
|
44
|
-
#
|
45
|
-
# @param [String] id Job id
|
46
|
-
# @param [Hash] options A set of options passed directly to HTTParty
|
47
|
-
# @return [Rundeck::ObjectifiedHash]
|
48
|
-
def job_executions(id, options = {})
|
49
|
-
r = get("/job/#{id}/executions", options)['result']['executions']['execution']
|
50
|
-
objectify r
|
51
|
-
end
|
52
|
-
|
53
|
-
# Run a job
|
54
|
-
#
|
55
|
-
# @example
|
56
|
-
# Rundeck.run_job('c07518ef-b697-4792-9a59-5b4f08855b67', 'DEBUG')
|
57
|
-
#
|
58
|
-
# @param [String] id Job id
|
59
|
-
# @param [Hash] options A set of options passed directly to HTTParty
|
60
|
-
# @return [Rundeck::ObjectifiedHash]
|
61
|
-
def run_job(id, options = {})
|
62
|
-
objectify post("/job/#{id}/executions", options)['result']['executions']['execution']
|
63
|
-
end
|
64
|
-
|
65
44
|
# Import a job or multiple jobs
|
66
45
|
#
|
67
46
|
# @example
|
@@ -78,9 +57,11 @@ module Rundeck
|
|
78
57
|
# Rundeck.import_jobs(job, 'xml')
|
79
58
|
#
|
80
59
|
# @param [String] content The job definition(s) as yaml or xml
|
81
|
-
# @param [String] format The import format. 'yaml|xml', defaults to
|
82
|
-
#
|
60
|
+
# @param [String] format The import format. 'yaml|xml', defaults to
|
61
|
+
# 'yaml'
|
62
|
+
# @!macro options
|
83
63
|
# @return [Rundeck::ObjectifiedHash]
|
64
|
+
# @!macro exceptions
|
84
65
|
def import_jobs(content, format = 'yaml', options = {})
|
85
66
|
unless format =~ /yaml|xml/
|
86
67
|
fail Error::InvalidAttributes, 'format must be yaml or xml'
|
@@ -101,9 +82,11 @@ module Rundeck
|
|
101
82
|
# Rundeck.export_jobs('project')
|
102
83
|
#
|
103
84
|
# @param [String] project Project name
|
104
|
-
# @param [String] format The export format. 'yaml
|
105
|
-
#
|
106
|
-
# @return [String]
|
85
|
+
# @param [String] format The export format. Either 'yaml' or 'xml'
|
86
|
+
# @!macro options
|
87
|
+
# @return [String] a string representation of the job in either xml or
|
88
|
+
# yaml
|
89
|
+
# @!macro exceptions
|
107
90
|
def export_jobs(project, format = 'yaml', options = {})
|
108
91
|
unless format =~ /yaml|xml/
|
109
92
|
fail Error::InvalidAttributes, 'format must be yaml or xml'
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Rundeck
|
2
2
|
class Client
|
3
3
|
# Defines methods related to projects.
|
4
|
-
module
|
4
|
+
module Key
|
5
|
+
# The endpoint for key storage
|
5
6
|
STORAGE_KEYS_PATH = '/storage/keys'
|
7
|
+
private_constant :STORAGE_KEYS_PATH
|
6
8
|
|
7
9
|
# Gets a list of keys at a specific path.
|
8
10
|
#
|
@@ -10,12 +12,15 @@ module Rundeck
|
|
10
12
|
# Rundeck.keys('path')
|
11
13
|
#
|
12
14
|
# @param [String] path A key storage path
|
13
|
-
#
|
15
|
+
# @!macro options
|
14
16
|
# @return [Array<Rundeck::ObjectifiedHash>]
|
17
|
+
# @!macro exceptions
|
18
|
+
# @raise [Rundeck::Error::InvalidAttributes] if the path is a direct key
|
19
|
+
# path
|
15
20
|
def keys(path = '', options = {})
|
16
21
|
r = get("#{STORAGE_KEYS_PATH}/#{path}", options)
|
17
22
|
|
18
|
-
#
|
23
|
+
# In case a user provides a direct path to a key, error.
|
19
24
|
if r['resource']['contents']
|
20
25
|
objectify r['resource']['contents']['resource']
|
21
26
|
else
|
@@ -31,8 +36,11 @@ module Rundeck
|
|
31
36
|
# Rundeck.key_metadata('path/to/key1')
|
32
37
|
#
|
33
38
|
# @param [String] path A key storage path, including key name
|
34
|
-
#
|
39
|
+
# @!macro options
|
35
40
|
# @return [Rundeck::ObjectifiedHash]
|
41
|
+
# @!macro exceptions
|
42
|
+
# @raise [Rundeck::Error::InvalidAttributes] if the path is a direct key
|
43
|
+
# path
|
36
44
|
def key_metadata(path, options = {})
|
37
45
|
r = get("#{STORAGE_KEYS_PATH}/#{path}", options)
|
38
46
|
|
@@ -54,13 +62,15 @@ module Rundeck
|
|
54
62
|
# Rundeck.key_contents('path/to/key1')
|
55
63
|
#
|
56
64
|
# @param [String] path A key storage path, including key name
|
57
|
-
#
|
65
|
+
# @!macro options
|
58
66
|
# @return [Rundeck::ObjectifiedHash]
|
67
|
+
# @!macro exceptions
|
59
68
|
def key_contents(path, options = {})
|
60
69
|
# Check if key exists first. Otherwise we could return some
|
61
70
|
# weird strings. Also, raise error if user is trying to get a
|
62
71
|
# private key.
|
63
|
-
|
72
|
+
key_content_type = key_metadata(path, options).rundeck_content_type
|
73
|
+
if key_content_type == content_type('private')
|
64
74
|
fail Error::Unauthorized,
|
65
75
|
'You are not allowed to retrieve the contents of a private key'
|
66
76
|
end
|
@@ -79,8 +89,9 @@ module Rundeck
|
|
79
89
|
#
|
80
90
|
# @param [String] path A key storage path
|
81
91
|
# @param [String] key The entire private key value
|
82
|
-
#
|
92
|
+
# @!macro options
|
83
93
|
# @return [Rundeck::ObjectifiedHash]
|
94
|
+
# @!macro exceptions
|
84
95
|
def create_private_key(path, key, options = {})
|
85
96
|
create_or_update_key(path, key, 'private', 'post', options)
|
86
97
|
end
|
@@ -93,11 +104,13 @@ module Rundeck
|
|
93
104
|
#
|
94
105
|
# @param [String] path A key storage path
|
95
106
|
# @param [String] key The entire private key value
|
96
|
-
#
|
107
|
+
# @!macro options
|
97
108
|
# @return [Rundeck::ObjectifiedHash]
|
109
|
+
# @!macro exceptions
|
110
|
+
# @raise [Rundeck::Error::NotFound] if the key was not found
|
98
111
|
def update_private_key(path, key, options = {})
|
99
112
|
key_check(path, 'private', options)
|
100
|
-
create_or_update_key(path, key, '
|
113
|
+
create_or_update_key(path, key, 'private', 'put', options)
|
101
114
|
end
|
102
115
|
|
103
116
|
# Create a public key
|
@@ -108,8 +121,9 @@ module Rundeck
|
|
108
121
|
#
|
109
122
|
# @param [String] path A key storage path
|
110
123
|
# @param [String] key The entire private key value
|
111
|
-
#
|
112
|
-
# @return [
|
124
|
+
# @!macro options
|
125
|
+
# @return [Rundeck::ObjectifiedHash]
|
126
|
+
# @!macro exceptions
|
113
127
|
def create_public_key(path, key, options = {})
|
114
128
|
create_or_update_key(path, key, 'public', 'post', options)
|
115
129
|
end
|
@@ -122,8 +136,10 @@ module Rundeck
|
|
122
136
|
#
|
123
137
|
# @param [String] path A key storage path
|
124
138
|
# @param [String] key The entire private key value
|
125
|
-
#
|
126
|
-
# @return [
|
139
|
+
# @!macro options
|
140
|
+
# @return [Rundeck::ObjectifiedHash]
|
141
|
+
# @!macro exceptions
|
142
|
+
# @raise [Rundeck::Error::NotFound] if the key was not foun
|
127
143
|
def update_public_key(path, key, options = {})
|
128
144
|
key_check(path, 'public', options)
|
129
145
|
create_or_update_key(path, key, 'public', 'put', options)
|
@@ -135,17 +151,19 @@ module Rundeck
|
|
135
151
|
# Rundeck.delete_key('path/to/key')
|
136
152
|
#
|
137
153
|
# @param [String] path A key storage path
|
138
|
-
#
|
154
|
+
# @!macro options
|
139
155
|
# @return [nil]
|
156
|
+
# @!macro exceptions
|
140
157
|
def delete_key(path, options = {})
|
141
158
|
delete("#{STORAGE_KEYS_PATH}/#{path}", options)
|
142
159
|
end
|
143
160
|
|
144
161
|
private
|
145
162
|
|
146
|
-
def key_check(path,
|
163
|
+
def key_check(path, key_type, options)
|
164
|
+
content_type = content_type(key_type)
|
147
165
|
# Check existence and type
|
148
|
-
if key_metadata(path, options).
|
166
|
+
if key_metadata(path, options).rundeck_content_type != content_type
|
149
167
|
fail Error::NotFound,
|
150
168
|
"A #{type} key was not found at the specified path."
|
151
169
|
end
|
@@ -163,10 +181,14 @@ module Rundeck
|
|
163
181
|
end
|
164
182
|
|
165
183
|
def key_type_headers(type, options)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
184
|
+
options.merge!(headers: { 'Content-Type' => content_type(type) })
|
185
|
+
end
|
186
|
+
|
187
|
+
def content_type(key_type)
|
188
|
+
if key_type == 'private'
|
189
|
+
'application/octet-stream'
|
190
|
+
elsif key_type == 'public'
|
191
|
+
'application/pgp-key'
|
170
192
|
else
|
171
193
|
fail Error::InvalidAttributes,
|
172
194
|
'Invalid key type specified. Must be public or private.'
|