Sha256: c631aa379ec033c055e798ebe7bb63e1af799df72a5e269e58e5d887204782ff

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

require 'aws/with-stacco-patches'
require 'yaml'

require 'stacco/base'

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

  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

  def stack_bucket_prefix
    @config['organization'].gsub(/[^\w]/, '')
  end

  def stacks
    @services[:s3].buckets.find_all{ |b| b.name =~ /^stacco-#{self.stack_bucket_prefix}-stack-/ }.map{ |b| Stacco::Stack.new(b) }
  end

  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
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stacco-0.1.30 ./lib/stacco/orchestrator.rb
stacco-0.1.29 ./lib/stacco/orchestrator.rb
stacco-0.1.28 ./lib/stacco/orchestrator.rb
stacco-0.1.27 ./lib/stacco/orchestrator.rb
stacco-0.1.26 ./lib/stacco/orchestrator.rb
stacco-0.1.24 ./lib/stacco/orchestrator.rb
stacco-0.1.23 ./lib/stacco/orchestrator.rb
stacco-0.1.22 ./lib/stacco/orchestrator.rb
stacco-0.1.21 ./lib/stacco/orchestrator.rb
stacco-0.1.20 ./lib/stacco/orchestrator.rb
stacco-0.1.18 ./lib/stacco/orchestrator.rb