remocon 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93390c5bcbfb187a136b9574a25a698792f6d983
4
- data.tar.gz: 9535d94e292b39592b59648a5d99dcd7f3cd7d58
3
+ metadata.gz: 4f0c28fa84a9323c0c1d867d81d7b8a13b676774
4
+ data.tar.gz: 2637bbbec4410f90cfc2d086b55fc6340890c6ed
5
5
  SHA512:
6
- metadata.gz: cea8d85ee2d7f346823d5836b3d9022083b4d6d159948ca5d6bbc37514d690ace6d5c33e8849c06d47925ccdb93cc2094ef90cce9eaf598c5839cef426b5bc15
7
- data.tar.gz: b11688605b37af9448bbf43c40d081c204b303b4d5cbdc9102ffa607f6e13e449af0595a7f7ce000fd2772068c7149d7d32f2d56889025b27166c1b3ac9882aa
6
+ metadata.gz: 3ac73ff7a2316cad4ce51836741d753b7c023bd8413c36e4c8c7bbb707a4fa7f63e8facccf2386bab7216686e824e977e61f67eaf75d329540f033fddf1319ba
7
+ data.tar.gz: be5f1b03a2967c35ef96be01d23dd84eb8ad5392b99bbdaa95268f39eb687dc0e84a9d140e11b0b0960473714eec132b832706802c81906b5f382d7b55b41fbd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remocon (0.4.0)
4
+ remocon (0.4.1)
5
5
  activesupport
6
6
  googleauth
7
7
  thor
data/lib/remocon.rb CHANGED
@@ -10,6 +10,7 @@ require "open-uri"
10
10
  require "fileutils"
11
11
  require "net/http"
12
12
  require "googleauth"
13
+ require "tempfile"
13
14
 
14
15
  require "remocon/util/array"
15
16
  require "remocon/util/hash"
@@ -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
- errors = parameter_errors + condition_errors + etag_errors
26
+ artifact = {
27
+ conditions: condition_array,
28
+ parameters: parameter_hash
29
+ }.skip_nil_values.stringify_values
27
30
 
28
- print_errors(errors)
31
+ response, body = Tempfile.open do |t|
32
+ t.write(JSON.pretty_generate(artifact))
33
+ t.flush
29
34
 
30
- errors.empty?
31
- end
35
+ Request.validate(config, t)
36
+ end
32
37
 
33
- def print_errors(errors)
34
- if errors.empty?
35
- STDOUT.puts "No error was found."
36
- else
37
- errors.each do |e|
38
- STDERR.puts "#{e.class} #{e.message}"
39
- STDERR.puts e.backtrace&.join("\n")
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 file must exist" unless File.exist?(config.etag_file_path)
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
  []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Remocon
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remocon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jumpei Matsuda