Skip to content

Commit 936d4dd

Browse files
committed
Rename allowed_sources to mtls_allowed_sources for clarity
Rename the route options field from allowed_sources to mtls_allowed_sources for better clarity about its purpose in mTLS app-to-app routing. Updates RouteOptionsMessage to use the new field name in: - Allowed keys registration - Feature flag gating - Validation methods - All related tests
1 parent f560db5 commit 936d4dd

2 files changed

Lines changed: 93 additions & 93 deletions

File tree

app/messages/route_options_message.rb

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
module VCAP::CloudController
44
class RouteOptionsMessage < BaseMessage
55
# Register all possible keys upfront so attr_accessors are created
6-
register_allowed_keys %i[loadbalancing hash_header hash_balance allowed_sources]
6+
register_allowed_keys %i[loadbalancing hash_header hash_balance mtls_allowed_sources]
77

88
def self.valid_route_options
99
options = %i[loadbalancing]
1010
options += %i[hash_header hash_balance] if VCAP::CloudController::FeatureFlag.enabled?(:hash_based_routing)
11-
options += %i[allowed_sources] if VCAP::CloudController::FeatureFlag.enabled?(:app_to_app_mtls_routing)
11+
options += %i[mtls_allowed_sources] if VCAP::CloudController::FeatureFlag.enabled?(:app_to_app_mtls_routing)
1212
options.freeze
1313
end
1414

@@ -22,7 +22,7 @@ def self.valid_loadbalancing_algorithms
2222
validate :loadbalancing_algorithm_is_valid
2323
validate :route_options_are_valid
2424
validate :hash_options_are_valid
25-
validate :allowed_sources_options_are_valid
25+
validate :mtls_allowed_sources_options_are_valid
2626

2727
def loadbalancing_algorithm_is_valid
2828
return if loadbalancing.blank?
@@ -85,99 +85,99 @@ def validate_hash_options_with_loadbalancing
8585
errors.add(:base, 'Hash balance can only be set when loadbalancing is hash') if hash_balance.present? && loadbalancing.present? && loadbalancing != 'hash'
8686
end
8787

88-
def allowed_sources_options_are_valid
89-
# Only validate allowed_sources when the feature flag is enabled
88+
def mtls_allowed_sources_options_are_valid
89+
# Only validate mtls_allowed_sources when the feature flag is enabled
9090
# If disabled, route_options_are_valid will already report it as unknown field
9191
return unless VCAP::CloudController::FeatureFlag.enabled?(:app_to_app_mtls_routing)
92-
return if allowed_sources.blank?
92+
return if mtls_allowed_sources.blank?
9393

94-
validate_allowed_sources_structure
95-
validate_allowed_sources_any_exclusivity
96-
validate_allowed_sources_guids_exist
94+
validate_mtls_allowed_sources_structure
95+
validate_mtls_allowed_sources_any_exclusivity
96+
validate_mtls_allowed_sources_guids_exist
9797
end
9898

9999
private
100100

101-
# Normalize allowed_sources to use string keys (Rails may parse JSON with symbol keys)
102-
def normalized_allowed_sources
103-
@normalized_allowed_sources ||= allowed_sources.is_a?(Hash) ? allowed_sources.transform_keys(&:to_s) : allowed_sources
101+
# Normalize mtls_allowed_sources to use string keys (Rails may parse JSON with symbol keys)
102+
def normalized_mtls_allowed_sources
103+
@normalized_mtls_allowed_sources ||= mtls_allowed_sources.is_a?(Hash) ? mtls_allowed_sources.transform_keys(&:to_s) : mtls_allowed_sources
104104
end
105105

106-
def validate_allowed_sources_structure
107-
unless allowed_sources.is_a?(Hash)
108-
errors.add(:allowed_sources, 'must be an object')
106+
def validate_mtls_allowed_sources_structure
107+
unless mtls_allowed_sources.is_a?(Hash)
108+
errors.add(:mtls_allowed_sources, 'must be an object')
109109
return
110110
end
111111

112112
valid_keys = %w[apps spaces orgs any]
113-
invalid_keys = normalized_allowed_sources.keys - valid_keys
114-
errors.add(:allowed_sources, "contains invalid keys: #{invalid_keys.join(', ')}") if invalid_keys.any?
113+
invalid_keys = normalized_mtls_allowed_sources.keys - valid_keys
114+
errors.add(:mtls_allowed_sources, "contains invalid keys: #{invalid_keys.join(', ')}") if invalid_keys.any?
115115

116116
# Validate types
117117
%w[apps spaces orgs].each do |key|
118-
next unless normalized_allowed_sources[key].present?
118+
next unless normalized_mtls_allowed_sources[key].present?
119119

120-
unless normalized_allowed_sources[key].is_a?(Array) && normalized_allowed_sources[key].all? { |v| v.is_a?(String) }
121-
errors.add(:allowed_sources, "#{key} must be an array of strings")
120+
unless normalized_mtls_allowed_sources[key].is_a?(Array) && normalized_mtls_allowed_sources[key].all? { |v| v.is_a?(String) }
121+
errors.add(:mtls_allowed_sources, "#{key} must be an array of strings")
122122
end
123123
end
124124

125-
return unless normalized_allowed_sources['any'].present? && ![true, false].include?(normalized_allowed_sources['any'])
125+
return unless normalized_mtls_allowed_sources['any'].present? && ![true, false].include?(normalized_mtls_allowed_sources['any'])
126126

127-
errors.add(:allowed_sources, 'any must be a boolean')
127+
errors.add(:mtls_allowed_sources, 'any must be a boolean')
128128
end
129129

130-
def validate_allowed_sources_any_exclusivity
131-
return unless allowed_sources.is_a?(Hash)
130+
def validate_mtls_allowed_sources_any_exclusivity
131+
return unless mtls_allowed_sources.is_a?(Hash)
132132

133-
has_any = normalized_allowed_sources['any'] == true
134-
has_lists = %w[apps spaces orgs].any? { |key| normalized_allowed_sources[key].present? && normalized_allowed_sources[key].any? }
133+
has_any = normalized_mtls_allowed_sources['any'] == true
134+
has_lists = %w[apps spaces orgs].any? { |key| normalized_mtls_allowed_sources[key].present? && normalized_mtls_allowed_sources[key].any? }
135135

136136
return unless has_any && has_lists
137137

138-
errors.add(:allowed_sources, 'any is mutually exclusive with apps, spaces, and orgs')
138+
errors.add(:mtls_allowed_sources, 'any is mutually exclusive with apps, spaces, and orgs')
139139
end
140140

141-
def validate_allowed_sources_guids_exist
142-
return unless allowed_sources.is_a?(Hash)
143-
return if errors[:allowed_sources].any? # Skip if already invalid
141+
def validate_mtls_allowed_sources_guids_exist
142+
return unless mtls_allowed_sources.is_a?(Hash)
143+
return if errors[:mtls_allowed_sources].any? # Skip if already invalid
144144

145145
validate_app_guids_exist
146146
validate_space_guids_exist
147147
validate_org_guids_exist
148148
end
149149

150150
def validate_app_guids_exist
151-
app_guids = normalized_allowed_sources['apps']
151+
app_guids = normalized_mtls_allowed_sources['apps']
152152
return if app_guids.blank?
153153

154154
existing_guids = AppModel.where(guid: app_guids).select_map(:guid)
155155
missing_guids = app_guids - existing_guids
156156
return if missing_guids.empty?
157157

158-
errors.add(:allowed_sources, "apps contains non-existent app GUIDs: #{missing_guids.join(', ')}")
158+
errors.add(:mtls_allowed_sources, "apps contains non-existent app GUIDs: #{missing_guids.join(', ')}")
159159
end
160160

161161
def validate_space_guids_exist
162-
space_guids = normalized_allowed_sources['spaces']
162+
space_guids = normalized_mtls_allowed_sources['spaces']
163163
return if space_guids.blank?
164164

165165
existing_guids = Space.where(guid: space_guids).select_map(:guid)
166166
missing_guids = space_guids - existing_guids
167167
return if missing_guids.empty?
168168

169-
errors.add(:allowed_sources, "spaces contains non-existent space GUIDs: #{missing_guids.join(', ')}")
169+
errors.add(:mtls_allowed_sources, "spaces contains non-existent space GUIDs: #{missing_guids.join(', ')}")
170170
end
171171

172172
def validate_org_guids_exist
173-
org_guids = normalized_allowed_sources['orgs']
173+
org_guids = normalized_mtls_allowed_sources['orgs']
174174
return if org_guids.blank?
175175

176176
existing_guids = Organization.where(guid: org_guids).select_map(:guid)
177177
missing_guids = org_guids - existing_guids
178178
return if missing_guids.empty?
179179

180-
errors.add(:allowed_sources, "orgs contains non-existent organization GUIDs: #{missing_guids.join(', ')}")
180+
errors.add(:mtls_allowed_sources, "orgs contains non-existent organization GUIDs: #{missing_guids.join(', ')}")
181181
end
182182
end
183183
end

0 commit comments

Comments
 (0)