Skip to content

Commit e1bb0cc

Browse files
committed
Move config file class out of stack
1 parent 4d8694c commit e1bb0cc

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

app/models/helpers/config_file.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
module VCAP::CloudController
3+
class ConfigFile
4+
def initialize(file_path)
5+
@hash = YAMLConfig.safe_load_file(file_path).tap do |h|
6+
Schema.validate(h)
7+
end
8+
end
9+
10+
def stacks
11+
@hash['stacks']
12+
end
13+
14+
def deprecated_stacks
15+
@hash['deprecated_stacks']
16+
end
17+
18+
def default
19+
@hash['default']
20+
end
21+
22+
Schema = Membrane::SchemaParser.parse do
23+
{
24+
'default' => String,
25+
'stacks' => [{
26+
'name' => String,
27+
'description' => String,
28+
optional('build_rootfs_image') => String,
29+
optional('run_rootfs_image') => String
30+
}],
31+
optional('deprecated_stacks') => [
32+
String
33+
]
34+
}
35+
end
36+
end
37+
end

app/models/runtime/stack.rb

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'models/helpers/process_types'
2+
require 'models/helpers/config_file'
23

34
module VCAP::CloudController
45
class Stack < Sequel::Model
@@ -97,40 +98,5 @@ def self.populate_from_hash(hash)
9798
create(hash.slice('name', 'description', 'build_rootfs_image', 'run_rootfs_image'))
9899
end
99100
end
100-
101-
class ConfigFile
102-
def initialize(file_path)
103-
@hash = YAMLConfig.safe_load_file(file_path).tap do |h|
104-
Schema.validate(h)
105-
end
106-
end
107-
108-
def stacks
109-
@hash['stacks']
110-
end
111-
112-
def deprecated_stacks
113-
@hash['deprecated_stacks']
114-
end
115-
116-
def default
117-
@hash['default']
118-
end
119-
120-
Schema = Membrane::SchemaParser.parse do
121-
{
122-
'default' => String,
123-
'stacks' => [{
124-
'name' => String,
125-
'description' => String,
126-
optional('build_rootfs_image') => String,
127-
optional('run_rootfs_image') => String
128-
}],
129-
optional('deprecated_stacks') => [
130-
String
131-
]
132-
}
133-
end
134-
end
135101
end
136-
end
102+
end

lib/cloud_controller/check_stacks.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CheckStacks
44

55
def initialize(config, db)
66
@config = config
7-
@stack_config = VCAP::CloudController::Stack::ConfigFile.new(config.get(:stacks_file))
7+
@stack_config = VCAP::CloudController::ConfigFile.new(config.get(:stacks_file))
88
@db = db
99
end
1010

@@ -30,4 +30,4 @@ def validate_stack(deprecated_stack)
3030
raise "rake task 'stack_check' failed, stack '#{deprecated_stack}' not supported" if deprecated_stack_in_db
3131
end
3232
end
33-
end
33+
end

lib/tasks/stack_check.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ namespace :stacks do
77
next unless db.table_exists?(:buildpack_lifecycle_data)
88

99
RakeConfig.config.load_db_encryption_key
10+
require 'models/helpers/config_file'
1011
require 'cloud_controller/check_stacks'
1112
VCAP::CloudController::CheckStacks.new(RakeConfig.config, db).validate_stacks
1213
end
13-
end
14+
end

0 commit comments

Comments
 (0)