Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
c03a98d2
Commit
c03a98d2
authored
Jul 05, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor of rundeck agent to use token auth
parent
37a15c11
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
21 deletions
+53
-21
agent.rb
lib/noah/agent.rb
+2
-0
base_agent.rb
lib/noah/agents/base_agent.rb
+1
-1
http_agent.rb
lib/noah/agents/http_agent.rb
+1
-1
rundeck_agent.rb
lib/noah/agents/rundeck_agent.rb
+47
-19
watchers.rb
lib/noah/models/watchers.rb
+2
-0
No files found.
lib/noah/agent.rb
View file @
c03a98d2
...
...
@@ -55,6 +55,8 @@ module Noah
begin
#self.instance_variable_get("@#{a}").send(:notify, e, m, @@watchers)
x
.
notify
(
e
,
m
,
@@watchers
.
clone
)
x
.
errback
{
|
e
|
self
.
set_deferred_status
(
:fail
,
"Error in
#{
x
.
class
.
to_s
}
:
#{
e
}
"
)}
x
.
callback
{
|
m
|
self
.
set_deferred_status
(
:success
);
iter
.
next
}
iter
.
next
rescue
Exception
=>
e
@logger
.
error
(
"
#{
agent
.
to_s
}
invocation failed with
#{
e
.
message
}
"
)
...
...
lib/noah/agents/base_agent.rb
View file @
c03a98d2
...
...
@@ -22,7 +22,7 @@ module Noah::Agents
work!
(
ep
,
message
)
iter
.
next
end
logger
.
info
(
"Dispatched message to
#{
worklist
.
size
}
#{
self
.
class
.
to_s
}
endpoints"
)
logger
.
info
(
"Dispatched message to
#{
worklist
.
size
}
#{
self
.
class
.
to_s
}
endpoints"
)
else
logger
.
info
(
"No work to do"
)
end
...
...
lib/noah/agents/http_agent.rb
View file @
c03a98d2
...
...
@@ -14,7 +14,7 @@ module Noah::Agents
logger
.
info
(
"Message posted to
#{
ep
}
successfully"
)
}
http
.
errback
{
logger
.
error
(
"Something went wrong with
#{
ep
}
"
)
logger
.
debug
(
"Error posting to
#{
ep
}
:
#{
http
.
response
}
.
"
)
}
end
...
...
lib/noah/agents/rundeck_agent.rb
View file @
c03a98d2
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'base_agent'
)
require
'em-http/middleware/cookie_jar'
require
'uri'
require
'nokogiri'
module
Noah::Agents
class
RunDeckAgent
<
Base
...
...
@@ -8,31 +7,60 @@ module Noah::Agents
PREFIX
=
"rundeck://"
NAME
=
self
.
class
.
to_s
DEFAULT_CONCURRENCY
=
50
SUPPORTED_PATHS
=
[
"refresh"
,
"run"
]
def
work!
(
ep
,
message
)
logger
.
info
(
"Sending message to (
#{
ep
}
)"
)
uri
=
URI
.
parse
(
ep
)
credentials
=
{
:j_username
=>
uri
.
user
,
:j_password
=>
uri
.
password
}
EM
::
HttpRequest
.
use
EM
::
Middleware
::
CookieJar
conn
=
EM
::
HttpRequest
.
new
(
"http://
#{
uri
.
host
}
:
#{
uri
.
port
}
/j_security_check"
)
http
=
conn
.
post
:body
=>
credentials
rd
=
rundeck_parser
(
ep
)
req
=
EM
::
HttpRequest
.
new
(
rd
[
:url
],
:connection_timeout
=>
2
,
:inactivity_timeout
=>
2
)
http
=
req
.
send
(
:"
#{
rd
[
:http_method
]
}
"
,
:head
=>
{
"X-RunDeck-Auth-Token"
=>
"
#{
rd
[
:token
]
}
"
})
http
.
callback
{
logger
.
info
(
"Logged in to RunDeck. Calling path"
)
conn2
=
EM
::
HttpRequest
.
new
(
"http://
#{
uri
.
host
}
:
#{
uri
.
port
}#{
uri
.
path
}
?
#{
uri
.
query
}
"
)
exec
=
conn2
.
get
exec
.
callback
{
logger
.
info
(
"Successfully called
#{
ep
}
"
)
logger
.
info
(
"Response from RunDeck:"
)
logger
.
info
(
"
#{
exec
.
response
}
"
)
}
exec
.
errback
{
logger
.
error
(
"Something went wrong with
#{
ep
}
"
)
}
logger
.
info
(
"Message posted to
#{
ep
}
"
)
rd_resp
=
rundeck_response
(
http
.
response
)
http
.
fail
(
"
#{
rd_resp
[
:message
]
}
"
)
if
rd_resp
[
:status
]
==
"error"
}
http
.
errback
{
logger
.
error
(
"Something went wrong with
#{
ep
}
"
)
logger
.
error
(
"Something went wrong with
#{
ep
}
:
#{
http
.
response
}
"
)
}
end
private
def
rundeck_parser
(
endpoint
)
rd
=
{}
logger
.
debug
(
"Parsing endpoint:
#{
endpoint
}
"
)
begin
rduri
=
URI
.
parse
(
endpoint
)
rescue
URI
::
InvalidURIError
logger
.
error
(
"Invalid callback destination"
)
end
rduri
.
user
.
nil?
?
self
.
fail
(
"Missing API Token"
)
:
rd
[
:token
]
=
rduri
.
user
# valid paths are:
# "/refresh/<project_name>"
# or
# "/run/<job_id>"
rduri
.
path
.
split
(
"/"
).
size
<
3
?
logger
.
error
(
"Path must contain job number"
)
:
action
=
rduri
.
path
.
split
(
"/"
)[
1
]
case
action
when
"run"
realpath
=
"api/1/job/
#{
rduri
.
path
.
split
(
"/"
)[
2
]
}
/run"
rd
[
:http_method
]
=
"get"
when
"refresh"
realpath
=
"api/2/project/
#{
rduri
.
path
.
split
(
"/"
)[
2
]
}
/resources/refresh"
rd
[
:http_method
]
=
"post"
else
logger
.
error
(
"I only handle jobs and refreshes for now. Sorry!"
)
end
rd
[
:url
]
=
"http://
#{
rduri
.
host
}
:
#{
rduri
.
port
}
/
#{
realpath
}
"
logger
.
debug
(
"Returning to work with params:
#{
rd
.
to_s
}
"
)
rd
end
def
rundeck_response
(
response
)
xml
=
Nokogiri
::
XML
.
parse
(
response
)
keys
=
xml
.
xpath
(
"//result"
).
collect
(
&
:keys
).
first
keys
.
member?
(
"error"
)
?
status
=
"error"
:
status
=
"success"
message
=
xml
.
xpath
(
"//result"
).
collect
(
&
:text
)
{
:status
=>
status
,
:message
=>
message
}
end
end
end
lib/noah/models/watchers.rb
View file @
c03a98d2
...
...
@@ -5,6 +5,8 @@ module Noah
attribute
:pattern
attribute
:endpoint
attribute
:name
counter
:failures
index
:pattern
index
:endpoint
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment