huginn_fisheye_agent 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/lib/huginn_fisheye_agent.rb +4 -0
- data/lib/huginn_fisheye_agent/fisheye_agent.rb +118 -0
- data/spec/fisheye_agent_spec.rb +13 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f0de24e74834e4191c4ced64d7384ecc166b41a
|
4
|
+
data.tar.gz: f8bd32c7038293528f20cd9a7ffe0279a09a05e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4eca01938902744ae0e153dcd567dafd8dc9c430c33231778e539a9d1e98cdd0778b02bd6c2682c4e7b2d77f50de421599efa3e3158a0f6df16aa7e4cdd3a822
|
7
|
+
data.tar.gz: bbb6dc0a668ceb00e4287ec7a7f56fe5e8fa64bb97bd61746bc7eeb5424d336ac1e12eb3f178e8ad86e53864e80a9424624ded0ab531a6fd3454d62ee3893b5e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2019 Justin Hammond
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module Agents
|
4
|
+
class FisheyeAgent < Agent
|
5
|
+
include WebRequestConcern
|
6
|
+
include FormConfigurable
|
7
|
+
|
8
|
+
|
9
|
+
can_dry_run!
|
10
|
+
no_bulk_receive!
|
11
|
+
cannot_be_scheduled!
|
12
|
+
|
13
|
+
description <<-MD
|
14
|
+
Trigger Atlassian Fisheye to index a repository (for example, after new commits are pushed)
|
15
|
+
|
16
|
+
`fisheye_url` is the address of the Fisheye Instance you want to trigger
|
17
|
+
|
18
|
+
`fisheye_token` is the Rest API Token for the Fisheye Instance (Found under Admin->Security Settings->Authentication in Fisheye)
|
19
|
+
|
20
|
+
`fisheye_repository` is the repository you want to trigger the index on
|
21
|
+
|
22
|
+
If `merge_event` is true, then the response is merged with the original payload
|
23
|
+
|
24
|
+
MD
|
25
|
+
|
26
|
+
def default_options
|
27
|
+
{
|
28
|
+
'fisheye_url' => 'https://fisheye.example.com',
|
29
|
+
'fisheye_token' => 'XXX',
|
30
|
+
'fisheye_repository' => 'XXX-XXX',
|
31
|
+
'merge_event' => 'false'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
form_configurable :fisheye_url, type: :text
|
36
|
+
form_configurable :fisheye_token, type: :text
|
37
|
+
form_configurable :fisheye_repository, type: :text
|
38
|
+
form_configurable :merge_event, type: :boolean
|
39
|
+
|
40
|
+
|
41
|
+
SCHEMES = %w(http https)
|
42
|
+
|
43
|
+
def valid_url?(url)
|
44
|
+
parsed = Addressable::URI.parse(url) or return false
|
45
|
+
SCHEMES.include?(parsed.scheme)
|
46
|
+
rescue Addressable::URI::InvalidURIError
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_options
|
51
|
+
if options['merge_event'].present? && !%[true false].include?(options['merge_event'].to_s)
|
52
|
+
errors.add(:base, "Oh no!!! if provided, merge_event must be 'true' or 'false'")
|
53
|
+
end
|
54
|
+
errors.add(:base, "Fisheye URL Missing") unless options['fisheye_url'].present?
|
55
|
+
errors.add(:base, "Fisheye Token Missing") unless options['fisheye_token'].present?
|
56
|
+
errors.add(:base, "Fisheye Repository Missing") unless options['fisheye_repository'].present?
|
57
|
+
end
|
58
|
+
|
59
|
+
def working?
|
60
|
+
return false if recent_error_logs?
|
61
|
+
|
62
|
+
if interpolated['expected_receive_period_in_days'].present?
|
63
|
+
return false unless last_receive_at && last_receive_at > interpolated['expected_receive_period_in_days'].to_i.days.ago
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def check
|
68
|
+
receive(interpolated)
|
69
|
+
end
|
70
|
+
|
71
|
+
def receive(incoming_events)
|
72
|
+
incoming_events.each do |event|
|
73
|
+
handle(event)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle(event)
|
78
|
+
fisheye_url = interpolated(event)["fisheye_url"] + '/rest-service-fecru/admin/repositories/'+ interpolated(event)["fisheye_repository"] + '/incremental-index'
|
79
|
+
if not valid_url?(fisheye_url)
|
80
|
+
log("Invalid URL #{fisheye_url}")
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
fisheye_headers = {'Content-Type' => 'application/json; charset=utf-8', 'X-Api-Key' => interpolated(event)["fisheye_token"] }
|
85
|
+
fisheye_body = ''
|
86
|
+
response = faraday.run_request(:put, fisheye_url, fisheye_body, fisheye_headers)
|
87
|
+
case response.status
|
88
|
+
when 202
|
89
|
+
log("Succesfully Trigger incremental index of Repository " + interpolated(event)["fisheye_repository"])
|
90
|
+
when 204
|
91
|
+
log("Succesfully Trigger incremental index of Repository " + interpolated(event)["fisheye_repository"])
|
92
|
+
when 401
|
93
|
+
log("Invalid Authentication Token Body: #{response.body}")
|
94
|
+
return
|
95
|
+
when 404
|
96
|
+
log("Repository Doesn't Exist: Repo: " + interpolated(event)["fisheye_repository"] + " Body: #{response.body}")
|
97
|
+
return
|
98
|
+
when 405
|
99
|
+
log("Repository is disabled: Repo: " + interpolated(event)["fisheye_repository"] + " Body: #{response.body}")
|
100
|
+
return
|
101
|
+
else
|
102
|
+
log("Invalid Response from Fisheye: Status: #{response.status} Body: #{response.body}")
|
103
|
+
return
|
104
|
+
end
|
105
|
+
if boolify(interpolated['merge_event'])
|
106
|
+
create_event payload: event.payload.merge(
|
107
|
+
fisheeye_response: {
|
108
|
+
body: response.body,
|
109
|
+
headers: response.headers,
|
110
|
+
status: response.status
|
111
|
+
}
|
112
|
+
)
|
113
|
+
else
|
114
|
+
create_event payload: {fisheye_response: {body: response.body, headers: response.headers, status: response.status}}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::FisheyeAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::FisheyeAgent.new.default_options
|
7
|
+
@checker = Agents::FisheyeAgent.new(:name => "FisheyeAgent", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_fisheye_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Hammond
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: huginn_agent
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- justin@devthendo.io
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- lib/huginn_fisheye_agent.rb
|
78
|
+
- lib/huginn_fisheye_agent/fisheye_agent.rb
|
79
|
+
- spec/fisheye_agent_spec.rb
|
80
|
+
homepage: https://github.com/DevThenDo/huginn_fisheye_agent
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.5.2.3
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Trigger Fisheye to index a repository after changes are pushed
|
104
|
+
test_files:
|
105
|
+
- spec/fisheye_agent_spec.rb
|