Class: Remocon::Command::Validate

Inherits:
Object
  • Object
show all
Includes:
InterpreterHelper
Defined in:
lib/remocon/command/validate_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InterpreterHelper

#condition_array, #condition_names, #parameter_hash, #read_conditions, #read_parameters

Constructor Details

#initialize(opts) ⇒ Validate

Returns a new instance of Validate.



10
11
12
13
# File 'lib/remocon/command/validate_command.rb', line 10

def initialize(opts)
  @config = Remocon::Config.new(opts.merge(force: false))
  @cmd_opts = { validate_only: true }
end

Instance Attribute Details

#cmd_optsObject (readonly)

Returns the value of attribute cmd_opts.



8
9
10
# File 'lib/remocon/command/validate_command.rb', line 8

def cmd_opts
  @cmd_opts
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/remocon/command/validate_command.rb', line 8

def config
  @config
end

Instance Method Details

#require_conditions_file_pathObject



19
20
21
# File 'lib/remocon/command/validate_command.rb', line 19

def require_conditions_file_path
  config.conditions_file_path
end

#require_parameters_file_pathObject



15
16
17
# File 'lib/remocon/command/validate_command.rb', line 15

def require_parameters_file_path
  config.parameters_file_path
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/remocon/command/validate_command.rb', line 23

def run
  validate_options

  artifact = {
      conditions: condition_array,
      parameters: parameter_hash
  }.skip_nil_values.stringify_values

  response, body = Tempfile.open do |t|
    t.write(JSON.pretty_generate(artifact))
    t.flush

    Request.validate(config, t)
  end

  if response.kind_of?(Net::HTTPOK)
    if response.header["etag"] =~ /^.*-0$/
      if etag_errors.empty?
        STDOUT.puts "valid"
        true
      else
        # validation api cannot validate etag
        STDERR.puts "the latest etag was updated"
        false
      end
    else
      # https://firebase.google.com/docs/remote-config/use-config-rest#validate_before_publishing
      STDERR.puts "api server returned 200 but etag is not followed the valid format"
      false
    end
  else
    STDERR.puts body
    false
  end
end