Class: InputValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/input_validator.rb

Instance Method Summary collapse

Constructor Details

#initializeInputValidator

Returns a new instance of InputValidator.



3
4
5
# File 'lib/input_validator.rb', line 3

def initialize
  @simple_validator = SimpleValidator.new
end

Instance Method Details

#test_modeObject



7
8
9
# File 'lib/input_validator.rb', line 7

def test_mode
  @test_mode = true
end

#validate_manifest(m) {|@simple_validator.method_exists manifest, 'version_source'| ... } ⇒ Object

Yields:

  • (@simple_validator.method_exists manifest, 'version_source')


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/input_validator.rb', line 20

def validate_manifest m

  manifest = Hashit.new m
  puts 'Validating upgrade manifest...'

  if manifest.nil? || manifest.class.to_s != 'Hashit'
    yield 'Config map must be a non-nil class of type Hashit'
  end

  @node_name = 'manifest'
  yield @simple_validator.method_exists manifest, 'version_source'
  yield @simple_validator.method_value_not_nil manifest, 'version_source'
  yield @simple_validator.method_exists manifest.version_source, 'repo_url'
  yield @simple_validator.method_value_not_nil_or_empty manifest.version_source, 'repo_url'
  yield @simple_validator.method_exists manifest.version_source, 'branch'
  yield @simple_validator.method_value_not_nil_or_empty manifest.version_source, 'branch'
  yield @simple_validator.method_exists manifest, 'projects'
  yield @simple_validator.method_value_not_nil manifest, 'projects'
end

#validate_project_node(project) {|@simple_validator.method_exists project, 'next'| ... } ⇒ Object

Yields:

  • (@simple_validator.method_exists project, 'next')


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/input_validator.rb', line 40

def validate_project_node project

  @node_name = 'project'

  # ensure is_root value's boolean only if the key exists
  msg = @simple_validator.method_exists project, 'is_root'
  if msg.nil?
    msg = @simple_validator.method_value_not_nil_or_empty project, 'is_root'
    project.is_root = project.is_root.downcase == 'y' if msg.nil?
  else
    yield msg
  end

  # previous and next keys are required, their values are not
  yield @simple_validator.method_exists project, 'next'
  yield @simple_validator.method_exists project, 'previous'

  @node_name = 'project.metadata'
  yield @simple_validator.method_exists project., 'repo_url'
  yield @simple_validator.method_value_not_nil_or_empty project., 'repo_url'

  yield @simple_validator.method_exists project., 'branch'
  yield @simple_validator.method_value_not_nil_or_empty project., 'branch'

  yield @simple_validator.method_exists project., 'should_upgrade'
  msg = @simple_validator.method_value_not_nil_or_empty project., 'should_upgrade'
  project..should_upgrade = project..should_upgrade.downcase == 'y' if msg.nil?
  yield msg

  yield @simple_validator.method_exists project., 'should_publish_nuget'
  msg = @simple_validator.method_value_not_nil_or_empty project., 'should_publish_nuget'
  project..should_publish_nuget = project..should_publish_nuget.downcase == 'y' if msg.nil?
  yield msg

  yield @simple_validator.method_exists project., 'env_vars'
  yield @simple_validator.method_value_not_nil project., 'env_vars'

  yield @simple_validator.method_exists project., 'status'
  yield @simple_validator.method_value_not_nil_or_empty project., 'status'

  yield @simple_validator.method_exists project., 'build_configuration_id'
  yield @simple_validator.method_exists project., 'build_wait_time_in_secs'

  @node_name = 'project.metadata.env_vars'
  yield @simple_validator.method_exists project..env_vars, 'env'
  yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'env'

  yield @simple_validator.method_exists project..env_vars, 'service_name'
  yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'service_name'

  if !@test_mode
    yield @simple_validator.method_exists project..env_vars, 'AI_InstrumentationKey'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'AI_InstrumentationKey'

    yield @simple_validator.method_exists project..env_vars, 'AppClientId'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'AppClientId'

    yield @simple_validator.method_exists project..env_vars, 'RuntimePath'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'RuntimePath'

    yield @simple_validator.method_exists project..env_vars, 'SettingsAccount'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'SettingsAccount'

    yield @simple_validator.method_exists project..env_vars, 'SettingsAccountKey'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'SettingsAccountKey'

    yield @simple_validator.method_exists project..env_vars, 'unitestconnectionString'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'unitestconnectionString'

    yield @simple_validator.method_exists project..env_vars, 'should_update_settings_connstr'
    yield @simple_validator.method_value_not_nil_or_empty project..env_vars, 'should_update_settings_connstr'
  end

  @node_name = 'project.metadata.semver'
  yield @simple_validator.method_exists project., 'semver'
  yield @simple_validator.method_value_not_nil project., 'semver'
  yield @simple_validator.method_exists project..semver, 'file'
  yield @simple_validator.method_value_not_nil_or_empty project..semver, 'file'

  yield @simple_validator.method_exists project..semver, 'dimension'
  yield @simple_validator.method_value_not_nil_or_empty project..semver, 'dimension'

  # location key required not value
  yield @simple_validator.method_exists project..semver, 'location'

end

#validate_version_map(version_map) ⇒ Object

We should do more specific test of which environment variables are we expecting or which metatdata are we expecting if project publishes nuget we need to check if major /minor/patch incrmeented but not all 3



14
15
16
17
18
# File 'lib/input_validator.rb', line 14

def validate_version_map version_map
  if version_map.nil? || !version_map.is_a?(GlobalConstants::HASH)
    yield 'Version map must be a non-empty ' + GlobalConstants::HASH
  end
end