remocon 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/remocon.rb +1 -0
- data/lib/remocon/command/lib/interpreter_helper.rb +0 -8
- data/lib/remocon/command/lib/request.rb +25 -0
- data/lib/remocon/command/validate_command.rb +28 -13
- data/lib/remocon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f0c28fa84a9323c0c1d867d81d7b8a13b676774
|
4
|
+
data.tar.gz: 2637bbbec4410f90cfc2d086b55fc6340890c6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac73ff7a2316cad4ce51836741d753b7c023bd8413c36e4c8c7bbb707a4fa7f63e8facccf2386bab7216686e824e977e61f67eaf75d329540f033fddf1319ba
|
7
|
+
data.tar.gz: be5f1b03a2967c35ef96be01d23dd84eb8ad5392b99bbdaa95268f39eb687dc0e84a9d140e11b0b0960473714eec132b832706802c81906b5f382d7b55b41fbd
|
data/Gemfile.lock
CHANGED
data/lib/remocon.rb
CHANGED
@@ -28,10 +28,6 @@ module Remocon
|
|
28
28
|
@parameter_hash ||= sort_parameters(read_parameters.first)
|
29
29
|
end
|
30
30
|
|
31
|
-
def parameter_errors
|
32
|
-
@parameter_errors ||= read_parameters.second
|
33
|
-
end
|
34
|
-
|
35
31
|
def read_conditions
|
36
32
|
@read_conditions ||= begin
|
37
33
|
condition_interpreter = Remocon::ConditionFileInterpreter.new(require_conditions_file_path)
|
@@ -43,10 +39,6 @@ module Remocon
|
|
43
39
|
@condition_array ||= sort_conditions(read_conditions.first)
|
44
40
|
end
|
45
41
|
|
46
|
-
def condition_errors
|
47
|
-
@condition_errors ||= read_conditions.second
|
48
|
-
end
|
49
|
-
|
50
42
|
def condition_names
|
51
43
|
@condition_names ||= condition_array.map { |e| e[:name] }
|
52
44
|
end
|
@@ -27,6 +27,31 @@ module Remocon
|
|
27
27
|
return response, response_body
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.validate(config, config_temp_file)
|
31
|
+
raise "etag should be specified. If you want to ignore this error, then please add --force option" unless config.etag
|
32
|
+
|
33
|
+
client, uri = Request.build_client(config)
|
34
|
+
|
35
|
+
headers = {
|
36
|
+
"Authorization" => "Bearer #{config.token}",
|
37
|
+
"Content-Type" => "application/json; UTF8",
|
38
|
+
"If-Match" => config.etag,
|
39
|
+
}
|
40
|
+
|
41
|
+
request = Net::HTTP::Put.new("#{uri.request_uri}?validate_only=true", headers)
|
42
|
+
request.body = +""
|
43
|
+
request.body << config_temp_file.read.delete("\r\n")
|
44
|
+
|
45
|
+
response = client.request(request)
|
46
|
+
|
47
|
+
response_body = begin
|
48
|
+
json_str = response.try(:read_body)
|
49
|
+
(json_str ? JSON.parse(json_str) : {}).with_indifferent_access
|
50
|
+
end
|
51
|
+
|
52
|
+
return response, response_body
|
53
|
+
end
|
54
|
+
|
30
55
|
def self.pull(config)
|
31
56
|
raw_json, etag = open(config.endpoint, "Authorization" => "Bearer #{config.token}") do |io|
|
32
57
|
[io.read, io.meta["etag"]]
|
@@ -23,21 +23,36 @@ module Remocon
|
|
23
23
|
def run
|
24
24
|
validate_options
|
25
25
|
|
26
|
-
|
26
|
+
artifact = {
|
27
|
+
conditions: condition_array,
|
28
|
+
parameters: parameter_hash
|
29
|
+
}.skip_nil_values.stringify_values
|
27
30
|
|
28
|
-
|
31
|
+
response, body = Tempfile.open do |t|
|
32
|
+
t.write(JSON.pretty_generate(artifact))
|
33
|
+
t.flush
|
29
34
|
|
30
|
-
|
31
|
-
|
35
|
+
Request.validate(config, t)
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
if response.kind_of?(Net::HTTPOK)
|
39
|
+
if response.header["etag"] =~ /^.*-0$/
|
40
|
+
if etag_errors.empty?
|
41
|
+
STDOUT.puts "valid"
|
42
|
+
true
|
43
|
+
else
|
44
|
+
# validation api cannot validate etag
|
45
|
+
STDERR.puts "the latest etag was updated"
|
46
|
+
false
|
47
|
+
end
|
48
|
+
else
|
49
|
+
# https://firebase.google.com/docs/remote-config/use-config-rest#validate_before_publishing
|
50
|
+
STDERR.puts "api server returned 200 but etag is not followed the valid format"
|
51
|
+
false
|
40
52
|
end
|
53
|
+
else
|
54
|
+
STDERR.puts body
|
55
|
+
false
|
41
56
|
end
|
42
57
|
end
|
43
58
|
|
@@ -46,7 +61,7 @@ module Remocon
|
|
46
61
|
def validate_options
|
47
62
|
raise ValidationError, "A condition file must exist" unless File.exist?(config.conditions_file_path)
|
48
63
|
raise ValidationError, "A parameter file must exist" unless File.exist?(config.parameters_file_path)
|
49
|
-
raise ValidationError, "An etag
|
64
|
+
raise ValidationError, "An etag must be specified" unless config.etag
|
50
65
|
end
|
51
66
|
|
52
67
|
def remote_etag
|
@@ -54,7 +69,7 @@ module Remocon
|
|
54
69
|
end
|
55
70
|
|
56
71
|
def etag_errors
|
57
|
-
if config.etag != remote_etag
|
72
|
+
if config.etag != "*" && config.etag != remote_etag
|
58
73
|
[ValidationError.new("#{config.etag} is found but the latest etag is #{remote_etag || 'none'}")]
|
59
74
|
else
|
60
75
|
[]
|
data/lib/remocon/version.rb
CHANGED