Sha256: e6091a11797ff6d9228406c2772e9a61b77b8020f558c367cb07315086075353

Contents?: true

Size: 979 Bytes

Versions: 18

Compression:

Stored size: 979 Bytes

Contents

require 'open-uri'

module Lono
  class Bashify
    def initialize(options={})
      @options = options
      @path = options[:path]
    end

    def user_data_paths(data,path="")
      paths = []
      paths << path
      data.each do |key,value|
        if value.is_a?(Hash)
          paths += user_data_paths(value,"#{path}/#{key}")
        else
          paths += ["#{path}/#{key}"]
        end
      end
      paths.select {|p| p =~ /UserData/ && p =~ /Fn::Join/ }
    end

    def run
      raw = open(@path).read
      json = JSON.load(raw)
      paths = user_data_paths(json)
      if paths.empty?
        puts "No UserData script found"
        return
      end
      paths.each do |path|
        puts "UserData script for #{path}:"
        key = path.sub('/','').split("/").map {|x| "['#{x}']"}.join('')
        user_data = eval("json#{key}")
        delimiter = user_data[0]
        script = user_data[1]
        puts script.join(delimiter)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lono-1.1.3 lib/lono/bashify.rb
lono-1.1.2 lib/lono/bashify.rb
lono-1.1.1 lib/lono/bashify.rb
lono-1.1.0 lib/lono/bashify.rb
lono-1.0.2 lib/lono/bashify.rb
lono-1.0.1 lib/lono/bashify.rb
lono-1.0.0 lib/lono/bashify.rb
lono-0.5.2 lib/lono/bashify.rb
lono-0.5.1 lib/lono/bashify.rb
lono-0.5.0 lib/lono/bashify.rb
lono-0.4.4 lib/lono/bashify.rb
lono-0.4.3 lib/lono/bashify.rb
lono-0.4.2 lib/lono/bashify.rb
lono-0.4.1 lib/lono/bashify.rb
lono-0.4.0 lib/lono/bashify.rb
lono-0.3.4 lib/lono/bashify.rb
lono-0.3.3 lib/lono/bashify.rb
lono-0.3.2 lib/lono/bashify.rb