skylight 3.1.5 → 4.0.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -9
- data/bin/skylight +1 -1
- data/ext/extconf.rb +74 -76
- data/ext/libskylight.yml +7 -6
- data/lib/skylight.rb +15 -13
- data/lib/skylight/api.rb +40 -37
- data/lib/skylight/cli.rb +55 -60
- data/lib/skylight/cli/doctor.rb +13 -14
- data/lib/skylight/cli/helpers.rb +20 -22
- data/lib/skylight/cli/merger.rb +119 -116
- data/lib/skylight/config.rb +110 -96
- data/lib/skylight/errors.rb +8 -10
- data/lib/skylight/helpers.rb +35 -37
- data/lib/skylight/native.rb +13 -13
- data/lib/skylight/native_ext_fetcher.rb +30 -37
- data/lib/skylight/probes/sinatra_add_middleware.rb +2 -2
- data/lib/skylight/railtie.rb +32 -8
- data/lib/skylight/sinatra.rb +1 -1
- data/lib/skylight/trace.rb +4 -5
- data/lib/skylight/util/component.rb +76 -11
- data/lib/skylight/util/deploy.rb +10 -21
- data/lib/skylight/util/hostname.rb +4 -4
- data/lib/skylight/util/http.rb +134 -136
- data/lib/skylight/util/ssl.rb +6 -6
- data/lib/skylight/version.rb +1 -1
- metadata +51 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df25b1cb1ffff1e84bef0e911de92f5ed92ba455fe43b3319a332d3ca2670318
|
4
|
+
data.tar.gz: 758bab00fc5be7be085f507477a3ac4545d45205cc65a0863742d8698b7bc9a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f53ce448c301d94196132f0e392745aaff73bd7fa355cb7d5b469390c15f8694fd4c81639c0b5de5b9da4146134289b607d2ff7c830743456fbe7661edfd95aa
|
7
|
+
data.tar.gz: 1e6c1e179b7de9cb1752d690991c5216ac76e1aa4240f10c25de7475597375014a6bceabcef768576366baa8cb460298d1506da42e2dfed7843361e936e266f0
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
##
|
2
|
-
* [
|
3
|
-
|
4
|
-
|
5
|
-
* [
|
6
|
-
|
7
|
-
## 3.1.3
|
8
|
-
* [BUGFIX] skylightd should close cloned file descriptors on startup
|
9
|
-
* [BUGFIX] Convert numeric git shas to strings
|
1
|
+
## 4.0.0.alpha (December 3, 2018)
|
2
|
+
* [FEATURE] Skylight for Background Jobs
|
3
|
+
* [FEATURE] Probe for Delayed::Job (standalone)
|
4
|
+
* [IMPROVEMENT] Handle 403 config validation response
|
5
|
+
* [IMPROVEMENT] Config for `prune_large_traces` is now true by default
|
6
|
+
* [BREAKING] New method for assigning 'segment' to a trace endpoint name
|
10
7
|
|
11
8
|
## 3.1.2 (November 29, 2018)
|
12
9
|
* [BUGFIX] Fix derived endpoint names under Grape 1.2
|
data/bin/skylight
CHANGED
data/ext/extconf.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "rbconfig"
|
2
|
+
require "mkmf"
|
3
|
+
require "yaml"
|
4
|
+
require "logger"
|
5
|
+
require "fileutils"
|
6
6
|
|
7
|
-
|
7
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
8
8
|
|
9
|
-
require
|
9
|
+
require "skylight/version"
|
10
10
|
|
11
11
|
# Don't use the gem for dev
|
12
|
-
if File.
|
12
|
+
if File.exist?(File.expand_path("../Gemfile", __dir__))
|
13
13
|
# This approach won't work in production since skylight-core isn't in the skylight gem
|
14
|
-
|
14
|
+
$LOAD_PATH.unshift File.expand_path("../skylight-core/lib", __dir__)
|
15
15
|
else
|
16
16
|
# Is there a better way to get this into lib?
|
17
|
-
gem
|
17
|
+
gem "skylight-core", Skylight::VERSION.tr("-", ".")
|
18
18
|
end
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "skylight/native_ext_fetcher"
|
21
|
+
require "skylight/core/util/platform"
|
22
22
|
|
23
23
|
# Util allowing proxying writes to multiple location
|
24
24
|
class MultiIO
|
25
|
-
|
26
25
|
def initialize(*targets)
|
27
|
-
|
26
|
+
@targets = targets
|
28
27
|
end
|
29
28
|
|
30
29
|
def write(*args)
|
31
|
-
@targets.each {|t| t.write(*args)}
|
30
|
+
@targets.each { |t| t.write(*args) }
|
32
31
|
end
|
33
32
|
|
34
33
|
def close
|
@@ -38,28 +37,28 @@ end
|
|
38
37
|
|
39
38
|
include Skylight::Core::Util
|
40
39
|
|
41
|
-
SKYLIGHT_INSTALL_LOG = File.expand_path("
|
42
|
-
SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV[
|
43
|
-
SKYLIGHT_FETCH_LIB = !ENV.key?(
|
40
|
+
SKYLIGHT_INSTALL_LOG = File.expand_path("install.log", __dir__)
|
41
|
+
SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV["SKYLIGHT_REQUIRED"] !~ /^false$/i
|
42
|
+
SKYLIGHT_FETCH_LIB = !ENV.key?("SKYLIGHT_FETCH_LIB") || ENV["SKYLIGHT_FETCH_LIB"] !~ /^false$/i
|
44
43
|
|
45
44
|
# Directory where skylight.h exists
|
46
|
-
SKYLIGHT_HDR_PATH = ENV[
|
47
|
-
SKYLIGHT_LIB_PATH = ENV[
|
45
|
+
SKYLIGHT_HDR_PATH = ENV["SKYLIGHT_HDR_PATH"] || ENV["SKYLIGHT_LIB_PATH"] || "."
|
46
|
+
SKYLIGHT_LIB_PATH = ENV["SKYLIGHT_LIB_PATH"] || File.expand_path("../../lib/skylight/native/#{Platform.tuple}", __FILE__)
|
48
47
|
|
49
|
-
SKYLIGHT_SOURCE_URL = ENV[
|
50
|
-
SKYLIGHT_VERSION = ENV[
|
51
|
-
SKYLIGHT_CHECKSUM = ENV[
|
48
|
+
SKYLIGHT_SOURCE_URL = ENV["SKYLIGHT_SOURCE_URL"]
|
49
|
+
SKYLIGHT_VERSION = ENV["SKYLIGHT_VERSION"]
|
50
|
+
SKYLIGHT_CHECKSUM = ENV["SKYLIGHT_CHECKSUM"]
|
52
51
|
|
53
|
-
SKYLIGHT_EXT_STRICT = ENV.key?("SKYLIGHT_EXT_STRICT") && ENV[
|
52
|
+
SKYLIGHT_EXT_STRICT = ENV.key?("SKYLIGHT_EXT_STRICT") && ENV["SKYLIGHT_EXT_STRICT"] =~ /^true$/i
|
54
53
|
|
55
54
|
# Setup logger
|
56
|
-
LOG = Logger.new(MultiIO.new(STDOUT, File.open(SKYLIGHT_INSTALL_LOG,
|
55
|
+
LOG = Logger.new(MultiIO.new(STDOUT, File.open(SKYLIGHT_INSTALL_LOG, "a")))
|
57
56
|
|
58
57
|
# Handles terminating in the case of a failure. If we have a bug, we do not
|
59
58
|
# want to break our customer's deploy, but extconf.rb requires a Makefile to be
|
60
59
|
# present upon a successful exit. To satisfy this requirement, we create a
|
61
60
|
# dummy Makefile.
|
62
|
-
def fail(msg, type
|
61
|
+
def fail(msg, type = :error)
|
63
62
|
LOG.send type, msg
|
64
63
|
|
65
64
|
if SKYLIGHT_REQUIRED
|
@@ -77,38 +76,38 @@ end
|
|
77
76
|
# Check that Xcode license has been approved
|
78
77
|
# Based on Homebrew's implementation
|
79
78
|
# https://github.com/Homebrew/homebrew/blob/03708b016755847facc4f19a43ee9f7a44141ed7/Library/Homebrew/cmd/doctor.rb#L1183
|
80
|
-
if Platform::OS ==
|
79
|
+
if Platform::OS == "darwin"
|
81
80
|
# If the user installs Xcode-only, they have to approve the
|
82
81
|
# license or no "xc*" tool will work.
|
83
|
-
if `/usr/bin/xcrun clang 2>&1` =~ /license/ &&
|
84
|
-
fail <<-
|
82
|
+
if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?
|
83
|
+
fail <<-MESSAGE
|
85
84
|
You have not agreed to the Xcode license and so we are unable to build the native agent.
|
86
85
|
To resolve this, you can agree to the license by opening Xcode.app or running:
|
87
86
|
sudo xcodebuild -license
|
88
|
-
|
87
|
+
MESSAGE
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
92
91
|
#
|
93
92
|
# === Setup paths
|
94
93
|
#
|
95
|
-
root = File.expand_path(
|
94
|
+
root = File.expand_path(__dir__)
|
96
95
|
hdrpath = File.expand_path(SKYLIGHT_HDR_PATH)
|
97
96
|
libpath = File.expand_path(SKYLIGHT_LIB_PATH)
|
98
97
|
libskylight = File.expand_path("libskylight.#{Platform.libext}", libpath)
|
99
|
-
libskylight_yml = File.expand_path(
|
98
|
+
libskylight_yml = File.expand_path("libskylight.yml", root)
|
100
99
|
skylight_dlopen_h = File.expand_path("skylight_dlopen.h", hdrpath)
|
101
100
|
skylight_dlopen_c = File.expand_path("skylight_dlopen.c", hdrpath)
|
102
101
|
|
103
102
|
LOG.info "SKYLIGHT_HDR_PATH=#{hdrpath}; SKYLIGHT_LIB_PATH=#{libpath}"
|
104
103
|
|
105
|
-
LOG.info "file exists; path=#{libskylight}" if File.
|
106
|
-
LOG.info "file exists; path=#{skylight_dlopen_c}" if File.
|
107
|
-
LOG.info "file exists; path=#{skylight_dlopen_h}" if File.
|
104
|
+
LOG.info "file exists; path=#{libskylight}" if File.exist?(libskylight)
|
105
|
+
LOG.info "file exists; path=#{skylight_dlopen_c}" if File.exist?(skylight_dlopen_c)
|
106
|
+
LOG.info "file exists; path=#{skylight_dlopen_h}" if File.exist?(skylight_dlopen_h)
|
108
107
|
|
109
108
|
# If libskylight is not present, fetch it
|
110
109
|
if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(skylight_dlopen_h)
|
111
|
-
|
110
|
+
unless SKYLIGHT_FETCH_LIB
|
112
111
|
fail "libskylight.#{LIBEXT} not found -- remote download disabled; aborting install"
|
113
112
|
end
|
114
113
|
|
@@ -117,37 +116,35 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
|
|
117
116
|
fail "`#{libskylight_yml}` does not exist"
|
118
117
|
end
|
119
118
|
|
120
|
-
unless libskylight_info = YAML.load_file(libskylight_yml)
|
119
|
+
unless (libskylight_info = YAML.load_file(libskylight_yml))
|
121
120
|
fail "`#{libskylight_yml}` does not contain data"
|
122
121
|
end
|
123
122
|
|
124
|
-
if version = SKYLIGHT_VERSION
|
125
|
-
unless checksum = SKYLIGHT_CHECKSUM
|
123
|
+
if (version = SKYLIGHT_VERSION)
|
124
|
+
unless (checksum = SKYLIGHT_CHECKSUM)
|
126
125
|
fail "no checksum provided when using custom version"
|
127
126
|
end
|
127
|
+
elsif (platform_info = libskylight_info[Platform.tuple])
|
128
|
+
unless (version = platform_info["version"])
|
129
|
+
fail "libskylight version missing from `#{libskylight_yml}`; platform=#{Platform.tuple}"
|
130
|
+
end
|
131
|
+
|
132
|
+
unless (checksum = platform_info["checksum"])
|
133
|
+
fail "checksum missing from `#{libskylight_yml}`; platform=#{Platform.tuple}"
|
134
|
+
end
|
128
135
|
else
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
unless checksums = libskylight_info["checksums"]
|
143
|
-
fail "libskylight checksums missing from `#{libskylight_yml}`"
|
144
|
-
end
|
145
|
-
|
146
|
-
unless checksum = checksums[Platform.tuple]
|
147
|
-
fail "no checksum entry for requested architecture -- " \
|
148
|
-
"this probably means the requested architecture is not supported; " \
|
149
|
-
"platform=#{Platform.tuple}; available=#{checksums.keys}", :info
|
150
|
-
end
|
136
|
+
unless (version = libskylight_info["version"])
|
137
|
+
fail "libskylight version missing from `#{libskylight_yml}`"
|
138
|
+
end
|
139
|
+
|
140
|
+
unless (checksums = libskylight_info["checksums"])
|
141
|
+
fail "libskylight checksums missing from `#{libskylight_yml}`"
|
142
|
+
end
|
143
|
+
|
144
|
+
unless (checksum = checksums[Platform.tuple])
|
145
|
+
fail "no checksum entry for requested architecture -- " \
|
146
|
+
"this probably means the requested architecture is not supported; " \
|
147
|
+
"platform=#{Platform.tuple}; available=#{checksums.keys}", :info
|
151
148
|
end
|
152
149
|
end
|
153
150
|
|
@@ -160,7 +157,8 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
|
|
160
157
|
arch: Platform.tuple,
|
161
158
|
required: SKYLIGHT_REQUIRED,
|
162
159
|
platform: Platform.tuple,
|
163
|
-
logger: LOG
|
160
|
+
logger: LOG
|
161
|
+
)
|
164
162
|
|
165
163
|
unless res
|
166
164
|
fail "could not fetch archive -- aborting skylight native extension build"
|
@@ -174,11 +172,11 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
|
|
174
172
|
# Move
|
175
173
|
FileUtils.mv "#{hdrpath}/libskylight.#{Platform.libext}",
|
176
174
|
"#{libpath}/libskylight.#{Platform.libext}",
|
177
|
-
:
|
175
|
+
force: true
|
178
176
|
|
179
177
|
FileUtils.mv "#{hdrpath}/skylightd",
|
180
178
|
"#{libpath}/skylightd",
|
181
|
-
:
|
179
|
+
force: true
|
182
180
|
end
|
183
181
|
rescue => e
|
184
182
|
fail "unable to fetch native extension; msg=#{e.message}\n#{e.backtrace.join("\n")}"
|
@@ -192,35 +190,35 @@ end
|
|
192
190
|
#
|
193
191
|
|
194
192
|
def find_file(file, root = nil)
|
195
|
-
path = File.expand_path(file, root ||
|
193
|
+
path = File.expand_path(file, root || ".")
|
196
194
|
|
197
195
|
unless File.exist?(path)
|
198
196
|
fail "#{file} missing; path=#{root}"
|
199
197
|
end
|
200
198
|
end
|
201
199
|
|
202
|
-
$VPATH
|
200
|
+
$VPATH << libpath
|
203
201
|
|
204
202
|
# Where the ruby binding src is
|
205
|
-
SRC_PATH = File.expand_path(
|
203
|
+
SRC_PATH = File.expand_path(__dir__)
|
206
204
|
|
207
205
|
$srcs = Dir[File.expand_path("*.c", SRC_PATH)].map { |f| File.basename(f) }
|
208
206
|
|
209
207
|
# If the native agent support files were downloaded to a different directory,
|
210
208
|
# explicitly the file to the list of sources.
|
211
|
-
unless $srcs.include?(
|
209
|
+
unless $srcs.include?("skylight_dlopen.c")
|
212
210
|
$srcs << "skylight_dlopen.c" # From libskylight dist
|
213
211
|
end
|
214
212
|
|
215
213
|
# Make sure that the files are present
|
216
|
-
find_file
|
217
|
-
find_file
|
218
|
-
find_header
|
219
|
-
|
214
|
+
find_file "skylight_dlopen.h", hdrpath
|
215
|
+
find_file "skylight_dlopen.c", hdrpath
|
216
|
+
find_header "skylight_dlopen.h", hdrpath
|
217
|
+
fail "could not create Makefile; dlfcn.h missing" unless have_header "dlfcn.h"
|
220
218
|
|
221
219
|
# For escaping the GVL
|
222
|
-
unless have_func(
|
223
|
-
|
220
|
+
unless have_func("rb_thread_call_without_gvl", "ruby/thread.h") || have_func("rb_thread_blocking_region")
|
221
|
+
abort "Ruby is unexpectedly missing rb_thread_blocking_region. This should not happen."
|
224
222
|
end
|
225
223
|
|
226
224
|
# Previous comment stated:
|
@@ -234,7 +232,7 @@ if SKYLIGHT_EXT_STRICT
|
|
234
232
|
$CFLAGS << " -Werror"
|
235
233
|
end
|
236
234
|
|
237
|
-
checking_for
|
235
|
+
checking_for "fast thread local storage" do
|
238
236
|
if try_compile("__thread int foo;")
|
239
237
|
$defs << "-DHAVE_FAST_TLS"
|
240
238
|
true
|
@@ -250,4 +248,4 @@ if SKYLIGHT_EXT_STRICT
|
|
250
248
|
end
|
251
249
|
|
252
250
|
# TODO: Compute the relative path to the location
|
253
|
-
create_makefile
|
251
|
+
create_makefile "skylight_native", File.expand_path(__dir__) # or fail "could not create makefile"
|
data/ext/libskylight.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
version: "3.1.0-
|
1
|
+
version: "3.1.0-ef54598"
|
2
2
|
checksums:
|
3
|
-
x86-linux: "
|
4
|
-
x86_64-linux: "
|
5
|
-
x86_64-linux-musl: "
|
6
|
-
x86_64-darwin: "
|
7
|
-
x86_64-freebsd: "
|
3
|
+
x86-linux: "b2e0df4a907c75a7296b147145dcb756ee9c0c506e9ff34ccf5dbfd33f762707"
|
4
|
+
x86_64-linux: "ab6d9c22b4a9e1831370cd5a9dd100c70270aebe51be4ed99c2a636c972792fa"
|
5
|
+
x86_64-linux-musl: "0cc2e117097d0cbed11f6f8ce877d9bb48e9d7d8bb443eb19c00ccf1bc56c8c8"
|
6
|
+
x86_64-darwin: "183cafb3df420db56b4062a654708f0981f3ef3c3ba47c8a07810c93a7d689d4"
|
7
|
+
x86_64-freebsd: "bbdbd4c7faa4546278b557007f0131d554add50a4bc8aa2c24dd3d3288cf9337"
|
8
|
+
|
data/lib/skylight.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
require "skylight/version"
|
2
|
+
require "skylight/core"
|
3
|
+
require "skylight/trace"
|
4
|
+
require "skylight/instrumenter"
|
5
|
+
require "skylight/middleware"
|
6
|
+
require "skylight/api"
|
7
|
+
require "skylight/helpers"
|
8
|
+
require "skylight/config"
|
9
|
+
require "skylight/errors"
|
10
|
+
require "skylight/native"
|
11
|
+
|
12
|
+
# For prettier global names
|
13
|
+
require "English"
|
11
14
|
|
12
15
|
module Skylight
|
13
16
|
# Used from the CLI
|
14
|
-
autoload :CLI,
|
17
|
+
autoload :CLI, "skylight/cli"
|
15
18
|
|
16
19
|
# Specifically check for Railtie since we've had at least one case of a
|
17
20
|
# customer having Rails defined without having all of Rails loaded.
|
18
21
|
if defined?(Rails::Railtie)
|
19
|
-
require
|
22
|
+
require "skylight/railtie"
|
20
23
|
end
|
21
24
|
|
22
25
|
include Core::Instrumentable
|
@@ -30,5 +33,4 @@ module Skylight
|
|
30
33
|
end
|
31
34
|
|
32
35
|
Core::Probes.add_path(File.expand_path("skylight/probes", __dir__))
|
33
|
-
|
34
36
|
end
|
data/lib/skylight/api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "uri"
|
2
|
+
require "skylight/util/http"
|
3
3
|
|
4
4
|
module Skylight
|
5
5
|
# @api private
|
@@ -21,14 +21,14 @@ module Skylight
|
|
21
21
|
|
22
22
|
def errors
|
23
23
|
return unless res.respond_to?(:body) && res.body.is_a?(Hash)
|
24
|
-
res.body[
|
24
|
+
res.body["errors"]
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_s
|
28
28
|
if errors
|
29
29
|
errors.inspect
|
30
30
|
elsif res
|
31
|
-
"#{res.class
|
31
|
+
"#{res.class}: #{res}"
|
32
32
|
else
|
33
33
|
super
|
34
34
|
end
|
@@ -36,7 +36,6 @@ module Skylight
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class ConfigValidationResults
|
39
|
-
|
40
39
|
include Core::Util::Logging
|
41
40
|
|
42
41
|
attr_reader :raw_response
|
@@ -46,7 +45,7 @@ module Skylight
|
|
46
45
|
@raw_response = raw_response
|
47
46
|
end
|
48
47
|
|
49
|
-
def
|
48
|
+
def error_response?
|
50
49
|
raw_response.is_a?(Util::HTTP::ErrorResponse) || status > 499
|
51
50
|
end
|
52
51
|
|
@@ -55,7 +54,7 @@ module Skylight
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def body
|
58
|
-
return nil if
|
57
|
+
return nil if error_response?
|
59
58
|
|
60
59
|
unless raw_response.body.is_a?(Hash)
|
61
60
|
warn("Unable to parse server response: status=%s, body=%s", raw_response.status, raw_response.body)
|
@@ -67,11 +66,14 @@ module Skylight
|
|
67
66
|
|
68
67
|
def token_valid?
|
69
68
|
# Don't prevent boot if it's an error response, so assume token is valid
|
70
|
-
return true if
|
69
|
+
return true if error_response?
|
71
70
|
# A 2xx response means everything is good!
|
72
71
|
return true if raw_response.success?
|
73
|
-
|
74
|
-
|
72
|
+
return false if status == 401
|
73
|
+
|
74
|
+
# A 403/422 means an invalid config,
|
75
|
+
# but the token must be valid if we got this far
|
76
|
+
true
|
75
77
|
end
|
76
78
|
|
77
79
|
def config_valid?
|
@@ -79,23 +81,26 @@ module Skylight
|
|
79
81
|
raw_response.success?
|
80
82
|
end
|
81
83
|
|
84
|
+
def forbidden?
|
85
|
+
status == 403
|
86
|
+
end
|
87
|
+
|
82
88
|
def validation_errors
|
83
|
-
return if config_valid?
|
84
|
-
body
|
89
|
+
return {} if config_valid? || !body
|
90
|
+
body["errors"]
|
85
91
|
end
|
86
92
|
|
87
93
|
def corrected_config
|
88
|
-
return if config_valid?
|
89
|
-
body
|
94
|
+
return {} if config_valid? || !body
|
95
|
+
body["corrected"]
|
90
96
|
end
|
91
|
-
|
92
97
|
end
|
93
98
|
|
94
99
|
def initialize(config)
|
95
100
|
@config = config
|
96
101
|
end
|
97
102
|
|
98
|
-
def create_app(name, token=nil)
|
103
|
+
def create_app(name, token = nil)
|
99
104
|
params = { app: { name: name } }
|
100
105
|
params[:token] = token if token
|
101
106
|
|
@@ -106,17 +111,17 @@ module Skylight
|
|
106
111
|
end
|
107
112
|
|
108
113
|
def fetch_mergeable_apps(token)
|
109
|
-
headers = {
|
114
|
+
headers = { "x-skylight-merge-token" => token }
|
110
115
|
http_request(:merges, :get, headers).tap do |res|
|
111
|
-
raise error_for_status(res.status)
|
116
|
+
raise error_for_status(res.status), "HTTP #{res.status}: #{res.body}" unless res.success?
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
115
120
|
def merge_apps!(token, app_guid:, component_guid:, environment:)
|
116
|
-
headers = {
|
121
|
+
headers = { "x-skylight-merge-token" => token }
|
117
122
|
body = { environment: environment, app_guid: app_guid, component_guid: component_guid }
|
118
123
|
http_request(:merges, :post, body, headers).tap do |res|
|
119
|
-
raise error_for_status(res.status)
|
124
|
+
raise error_for_status(res.status), "HTTP #{res.status}: #{res.body}" unless res.success?
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
@@ -127,24 +132,22 @@ module Skylight
|
|
127
132
|
|
128
133
|
private
|
129
134
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
def error_for_status(code)
|
138
|
-
case code
|
139
|
-
when 401
|
140
|
-
Unauthorized
|
141
|
-
when 409
|
142
|
-
Conflict
|
143
|
-
else
|
144
|
-
Error
|
135
|
+
# TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
|
136
|
+
def http_request(service, method, *args)
|
137
|
+
http = Util::HTTP.new(config, service)
|
138
|
+
uri = URI.parse(config.get("#{service}_url"))
|
139
|
+
http.send(method, uri.path, *args)
|
145
140
|
end
|
146
|
-
end
|
147
141
|
|
142
|
+
def error_for_status(code)
|
143
|
+
case code
|
144
|
+
when 401
|
145
|
+
Unauthorized
|
146
|
+
when 409
|
147
|
+
Conflict
|
148
|
+
else
|
149
|
+
Error
|
150
|
+
end
|
151
|
+
end
|
148
152
|
end
|
149
|
-
|
150
153
|
end
|