class Stacco::Orchestrator

Public Class Methods

from_config(config_body) click to toggle source
# File lib/stacco/orchestrator.rb, line 7
def self.from_config(config_body)
  config_body = config_body.read if config_body.respond_to?(:read)
  self.new YAML.load(config_body)
end
new(config) click to toggle source
# File lib/stacco/orchestrator.rb, line 12
def initialize(config)
  @config = config

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

Public Instance Methods

define_stack(config_body) click to toggle source
# File lib/stacco/orchestrator.rb, line 31
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']
  bucket_name = "stacco-#{self.stack_bucket_prefix}-stack-#{stack_name}"

  bucket = @services[:s3].buckets[bucket_name]
  unless bucket.exists?
    @services[:s3].buckets.create(bucket_name)
  end

  bucket.objects['stack.yml'].write(config.to_yaml)

  Stacco::Stack.new(bucket)
end
stack_bucket_prefix() click to toggle source
# File lib/stacco/orchestrator.rb, line 23
def stack_bucket_prefix
  @config['organization'].gsub(/[^\w]/, '')
end
stacks() click to toggle source
# File lib/stacco/orchestrator.rb, line 27
def stacks
  @services[:s3].buckets.find_all{ |b| b.name =~ /^stacco-#{self.stack_bucket_prefix}-stack-/ }.map{ |b| Stacco::Stack.new(b) rescue nil }.compact
end