datapimp 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/datapimp/cli/create.rb +47 -0
- data/lib/datapimp/sync/dropbox_folder.rb +53 -29
- data/lib/datapimp/sync/s3_bucket.rb +19 -0
- data/lib/datapimp/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 79993874a9421dff20a6cd8ebcb5a2240fe0ff54
         | 
| 4 | 
            +
              data.tar.gz: 997c9057ec210a512440b8b744b7f1817c5cc80b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d01cbe4441e8b98ba4163dc13d930d8edca6a40156f62ae1c340d17fea74540c2f89a4973c0bc85247ff4facaf252d2bca8a926a5dedbd4322ce01c79b7a6888
         | 
| 7 | 
            +
              data.tar.gz: e9b507cc01eb04d3c76d216dcc5d1c7c112655f7de80b6922b3da34af01530628fb5b170d5b1b2098f9ec4423ef8d7c5f30e0ec089684c038c0ae32e4a2837d8
         | 
    
        data/lib/datapimp/cli/create.rb
    CHANGED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            command 'create s3 bucket' do |c|
         | 
| 2 | 
            +
              c.syntax = 'datapimp create s3 bucket BUCKETNAME'
         | 
| 3 | 
            +
              c.description = 'create an s3 bucket to use for website hosting'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              Datapimp::Cli.accepts_keys_for(c, :amazon)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              c.action do |args, options|
         | 
| 8 | 
            +
                raise 'Must specify bucket name' unless args.first
         | 
| 9 | 
            +
                Datapimp::Sync::S3Bucket.new(remote: args.first).run_create_action()
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            command 'create cloudfront distribution' do |c|
         | 
| 14 | 
            +
              c.syntax = "datapimp create cloudfront distribution"
         | 
| 15 | 
            +
              c.description = "create a cloudfront distribution to link to a specific bucket"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              Datapimp::Cli.accepts_keys_for(c, :amazon)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              c.option '--bucket NAME', String, 'The name of the bucket that will provide the content'
         | 
| 20 | 
            +
              c.option '--domains DOMAINS', Array, 'What domains will be pointing to this bucket?'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              c.action do |args, options|
         | 
| 23 | 
            +
                bucket = Datapimp::Sync::S3Bucket.new(remote: options.bucket)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                cdn_options = {
         | 
| 26 | 
            +
                  enabled: true,
         | 
| 27 | 
            +
                  custom_origin: {
         | 
| 28 | 
            +
                    'DNSName'=> bucket.website_hostname,
         | 
| 29 | 
            +
                    'OriginProtocolPolicy'=>'http-only'
         | 
| 30 | 
            +
                  },
         | 
| 31 | 
            +
                  comment: options.bucket,
         | 
| 32 | 
            +
                  caller_reference: Time.now.to_i.to_s,
         | 
| 33 | 
            +
                  cname: Array(options.domains).join(","),
         | 
| 34 | 
            +
                  default_root_object: 'index.html'
         | 
| 35 | 
            +
                }
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                distributions = Datapimp::Sync.amazon.cdn.distributions
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                distribution = distributions.find {|d| d.comment == options.bucket }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                if !distribution
         | 
| 42 | 
            +
                  distribution = Datapimp::Sync.amazon.cdn.distributions.create(cdn_options)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                log "Cloudfront distribution created: #{ distribution.domain } status: #{ distribution.status }"
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| @@ -2,6 +2,51 @@ module Datapimp | |
| 2 2 | 
             
              class Sync::DropboxFolder < Hashie::Mash
         | 
| 3 3 | 
             
                include Datapimp::Logging
         | 
| 4 4 |  | 
| 5 | 
            +
                def run(action, options={})
         | 
| 6 | 
            +
                  action = action.to_sym
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  log "DropboxFolder run:#{action}"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  if action == :push
         | 
| 11 | 
            +
                    run_push_action
         | 
| 12 | 
            +
                  elsif action == :pull
         | 
| 13 | 
            +
                    run_pull_action
         | 
| 14 | 
            +
                  elsif action == :create
         | 
| 15 | 
            +
                    run_create_action
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def run_create_action
         | 
| 20 | 
            +
                  dropbox.mkdir(remote)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def run_pull_action
         | 
| 24 | 
            +
                  remote_path_entries.each do |entry|
         | 
| 25 | 
            +
                    remote_dropbox_path = entry.path
         | 
| 26 | 
            +
                    remote_content = dropbox.download(remote_dropbox_path)
         | 
| 27 | 
            +
                    relative_local_path = remote_dropbox_path.gsub("#{remote}/",'')
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    log "Saving #{ remote_content.length } bytes to #{ relative_local_path }"
         | 
| 30 | 
            +
                    local_path.join(relative_local_path).open("w+") {|fh| fh.write(remote_content) }
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def run_push_action
         | 
| 35 | 
            +
                  if remote_path_missing?
         | 
| 36 | 
            +
                    run_create_action()
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  Dir[local_path.join("**/*")].each do |f|
         | 
| 40 | 
            +
                    f = Pathname(f)
         | 
| 41 | 
            +
                    base = f.relative_path_from(local_path).to_s
         | 
| 42 | 
            +
                    target_path = File.join(remote, base)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    log "Uploading #{ f } to #{target_path}"
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    dropbox.upload(target_path, f.read, :overwrite => false)
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 5 50 | 
             
                # Provides easy access to the Dropbox client
         | 
| 6 51 | 
             
                def dropbox
         | 
| 7 52 | 
             
                  @dropbox ||= Datapimp::Sync.dropbox
         | 
| @@ -47,37 +92,16 @@ module Datapimp | |
| 47 92 | 
             
                  remote_path.nil?
         | 
| 48 93 | 
             
                end
         | 
| 49 94 |  | 
| 50 | 
            -
                def  | 
| 51 | 
            -
                   | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
                     | 
| 57 | 
            -
                   | 
| 58 | 
            -
                    run_pull_action
         | 
| 59 | 
            -
                  end
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                def run_pull_action
         | 
| 63 | 
            -
                  binding.pry
         | 
| 95 | 
            +
                def remote_path_entries
         | 
| 96 | 
            +
                  remote_path.map do |entry|
         | 
| 97 | 
            +
                    if entry.is_dir
         | 
| 98 | 
            +
                      dropbox.ls(entry.path)
         | 
| 99 | 
            +
                    else
         | 
| 100 | 
            +
                      entry
         | 
| 101 | 
            +
                    end
         | 
| 102 | 
            +
                  end.flatten
         | 
| 64 103 | 
             
                end
         | 
| 65 104 |  | 
| 66 | 
            -
                def run_push_action
         | 
| 67 | 
            -
                  if remote_path_missing?
         | 
| 68 | 
            -
                    dropbox.mkdir(remote)
         | 
| 69 | 
            -
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  Dir[local_path.join("**/*")].each do |f|
         | 
| 72 | 
            -
                    f = Pathname(f)
         | 
| 73 | 
            -
                    base = f.relative_path_from(local_path).to_s
         | 
| 74 | 
            -
                    target_path = File.join(remote, base)
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                    log "Uploading #{ f } to #{target_path}"
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                    dropbox.upload(target_path, f.read, :overwrite => false)
         | 
| 79 | 
            -
                  end
         | 
| 80 | 
            -
                end
         | 
| 81 105 | 
             
              end
         | 
| 82 106 | 
             
            end
         | 
| 83 107 |  | 
| @@ -8,6 +8,14 @@ module Datapimp | |
| 8 8 | 
             
                    @s3 ||= Datapimp::Sync.amazon.storage.directories.get(remote)
         | 
| 9 9 | 
             
                  end
         | 
| 10 10 |  | 
| 11 | 
            +
                  def website_hostname
         | 
| 12 | 
            +
                    "#{s3.key}.s3-website-#{ s3.location }.amazonaws.com"
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def website_url(proto="http")
         | 
| 16 | 
            +
                    "#{proto}://#{ website_hostname }"
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 11 19 | 
             
                  def local_path
         | 
| 12 20 | 
             
                    Pathname(local)
         | 
| 13 21 | 
             
                  end
         | 
| @@ -101,7 +109,16 @@ module Datapimp | |
| 101 109 | 
             
                  end
         | 
| 102 110 |  | 
| 103 111 | 
             
                  def run_pull_action(options={})
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  def run_create_action(options={})
         | 
| 115 | 
            +
                    directories = Datapimp::Sync.amazon.storage.directories
         | 
| 104 116 |  | 
| 117 | 
            +
                    if existing = directories.get(remote)
         | 
| 118 | 
            +
                      return existing
         | 
| 119 | 
            +
                    else
         | 
| 120 | 
            +
                      directories.create(key:remote)
         | 
| 121 | 
            +
                    end
         | 
| 105 122 | 
             
                  end
         | 
| 106 123 |  | 
| 107 124 | 
             
                  def run(action, options={})
         | 
| @@ -109,6 +126,8 @@ module Datapimp | |
| 109 126 |  | 
| 110 127 | 
             
                    if action == :push
         | 
| 111 128 | 
             
                      run_push_action(options)
         | 
| 129 | 
            +
                    elsif action == :create
         | 
| 130 | 
            +
                      run_create_action(options)
         | 
| 112 131 | 
             
                    elsif action == :update_acl
         | 
| 113 132 | 
             
                      run_update_acl_action(options={})
         | 
| 114 133 | 
             
                    elsif action == :pull
         | 
    
        data/lib/datapimp/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: datapimp
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.9
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jonathan Soeder
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-04- | 
| 11 | 
            +
            date: 2015-04-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: pry
         |