Class: Stacco::Orchestrator

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Orchestrator

Returns a new instance of Orchestrator.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/stacco.rb', line 151

def initialize(config)
  @config = config

  storage_bucket_name = @config['storage_bucket']

  s3 = AWS::S3.new(
    access_key_id: @config['aws']['access_key_id'],
    secret_access_key: @config['aws']['secret_access_key'],
    region: @config['aws']['region']
  )

  @bucket = s3.buckets[storage_bucket_name]
  s3.buckets.create(storage_bucket_name) unless @bucket.exists?
end

Class Method Details

.from_config(config_body) ⇒ Object



146
147
148
149
# File 'lib/stacco.rb', line 146

def self.from_config(config_body)
  config_body = config_body.read if config_body.respond_to?(:read)
  self.new YAML.load(config_body)
end

Instance Method Details

#define_stack(config_body) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/stacco.rb', line 170

def define_stack(config_body)
  config_body = config_body.read if config_body.respond_to?(:read)

  config = YAML.load(config_body)

  stack_name = config['name']

  stack_object = @bucket.objects["stack/#{stack_name}"]
  stack_object.write(config.to_yaml)

  Stacco::Stack.new(stack_object)
end

#stacksObject



166
167
168
# File 'lib/stacco.rb', line 166

def stacks
  @bucket.objects.with_prefix('stack/').to_a[1..-1].map{ |obj| Stacco::Stack.new(obj) }
end