rain_forest 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5276b08a7b706b69e684e0539ed058298181b7a3
4
- data.tar.gz: 52c8fde23cf2d9559e383c7ed3c612b2cb7071b7
3
+ metadata.gz: 7e50fce79a5348778b51639e48f147533ac6f791
4
+ data.tar.gz: abffab929a116c560e595b59e2df24858d9caa84
5
5
  SHA512:
6
- metadata.gz: ccd1c72dc8cb90034fd48e883a5c874bf67965b82e4e0f93c6a248a9fd9bea9a5fda95092412401745ace292030dbbb4b7a19e35c3b93f6ace33ab6c42044995
7
- data.tar.gz: d3d2dd20848cbeafec5c5e6a49a08f7908b25ccede58bb2aa0d9e346d11d5aa944392ed27d2cf1ff0c2304ba052fc48aa50ad4c224e3911c12894946096381d4
6
+ metadata.gz: 31d50ed893a2963c5677b4ceaec5cfbcfa45cf79a51b2080c334923997f2a7a0144eea8de67cd648d7eef312386a489c1023db84ddc3fdf41f583163681c0c78
7
+ data.tar.gz: c6ccf09750818fbfebfddaa3bc525fa40b0919967eab36be6b3173333b849d1159d9636db1a34da5316b865ddfac75aa792ec1218c80f8adc76f137b0552dd43
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ gem 'aws-sdk', '2.1.14', require: true
11
11
  # Include everything needed to run rake, tests, features, etc.
12
12
  group :development do
13
13
  gem "rspec", "2.14.0"
14
+ gem "byebug"
14
15
  gem 'coveralls', require: false
15
16
  gem "rdoc", "~> 3.12"
16
17
  gem "bundler", "~> 1.0"
data/Gemfile.lock CHANGED
@@ -9,6 +9,7 @@ GEM
9
9
  aws-sdk-resources (2.1.14)
10
10
  aws-sdk-core (= 2.1.14)
11
11
  builder (3.2.2)
12
+ byebug (9.0.4)
12
13
  coveralls (0.8.3)
13
14
  json (~> 1.8)
14
15
  rest-client (>= 1.6.8, < 2)
@@ -98,11 +99,15 @@ PLATFORMS
98
99
  DEPENDENCIES
99
100
  aws-sdk (= 2.1.14)
100
101
  bundler (~> 1.0)
102
+ byebug
101
103
  coveralls
102
104
  jeweler (~> 2.0.1)
103
105
  rdoc (~> 3.12)
104
106
  rspec (= 2.14.0)
105
107
  simplecov
106
108
 
109
+ RUBY VERSION
110
+ ruby 2.0.0p353
111
+
107
112
  BUNDLED WITH
108
- 1.10.6
113
+ 1.12.4
data/README.markdown CHANGED
@@ -4,7 +4,10 @@
4
4
  [![Build Status](https://travis-ci.org/LukasBeaton/rain_forest.svg?branch=master)](https://travis-ci.org/LukasBeaton/rain_forest)
5
5
  [![Coverage Status](https://coveralls.io/repos/LukasBeaton/rain_forest/badge.svg?branch=master&service=github)](https://coveralls.io/github/LukasBeaton/rain_forest?branch=master)
6
6
 
7
- Rain Forest is a collection of simplified adaptors for Amazon Web Services and relies on the [aws-sdk Gem](https://rubygems.org/gems/aws-sdk). The intention is for Rain Forest to one day support many of Amazon's web services. However, at the moment there is only support for S3.
7
+ Rain Forest is a collection of simplified adaptors for Amazon Web Services and relies on the [aws-sdk Gem](https://rubygems.org/gems/aws-sdk). The intention is for Rain Forest to one day support many of Amazon's web services. However, at the moment there is some basic support for:
8
+
9
+ * S3
10
+ * CloudFront
8
11
 
9
12
  ## Installation
10
13
 
@@ -56,6 +59,7 @@ config/initializers/rain_forest.rb
56
59
  RainForest::S3.move(source_key, dest_key)
57
60
  RainForest::S3.content_length(storage_key)
58
61
  RainForest::S3.delete_objects(prefix)
62
+ RainForest::CloudFront.update_origin(distribution_id, new_origin)
59
63
 
60
64
 
61
65
  ## Contributing to Rain Forest
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -0,0 +1,42 @@
1
+ require 'aws-sdk'
2
+
3
+ module RainForest
4
+ class CloudFront
5
+ attr_accessor :client
6
+
7
+ def initialize
8
+ akid = ENV['RAIN_FOREST_AWS_AKID']
9
+ secret = ENV['RAIN_FOREST_AWS_SECRET']
10
+ @client = ::Aws::CloudFront::Client.new(access_key_id: akid, secret_access_key: secret, region: 'cloudfront.amazonaws.com')
11
+ end
12
+
13
+ def self.update_origin(distribution_id, new_origin_key)
14
+ self.new.update_origin(distribution_id, new_origin_key)
15
+ end
16
+
17
+ def update_origin(distribution_id, new_origin_key)
18
+ begin
19
+ dist = @client.get_distribution(id: distribution_id)
20
+
21
+ dist_config = dist[:distribution][:distribution_config]
22
+ dist_config[:comment] = dist_config[:comment].to_s #ensure not nil or will get an error
23
+ dist_config[:logging][:bucket] = dist_config[:logging][:bucket].to_s #ensure not nil or will get an error
24
+ dist_config[:logging][:prefix] = dist_config[:logging][:prefix].to_s #ensure not nil or will get an error
25
+
26
+ dist_config[:origins][:items][0][:origin_path] = new_origin_key # IMPORTANT: set new origin!
27
+
28
+ options = {
29
+ id: distribution_id,
30
+ if_match: dist[:etag],
31
+ distribution_config: dist_config
32
+ }
33
+
34
+ @client.update_distribution(options)
35
+ rescue Exception => e
36
+ return false, e.message
37
+ end
38
+
39
+ return true, nil
40
+ end
41
+ end
42
+ end
data/lib/rain_forest.rb CHANGED
@@ -1 +1,2 @@
1
1
  require File.join(File.dirname(__FILE__), "rain_forest", "s3")
2
+ require File.join(File.dirname(__FILE__), "rain_forest", "cloud_front")
data/rain_forest.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rain_forest"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lukas Beaton"]
12
- s.date = "2016-06-13"
12
+ s.date = "2016-07-07"
13
13
  s.description = "A simplified adaptor for Amazon Web Services. Only S3 is supported at the moment."
14
14
  s.email = "lukas.beaton@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -26,8 +26,10 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/rain_forest.rb",
29
+ "lib/rain_forest/cloud_front.rb",
29
30
  "lib/rain_forest/s3.rb",
30
31
  "rain_forest.gemspec",
32
+ "spec/rain_forest/cloud_front_spec.rb",
31
33
  "spec/rain_forest/s3_spec.rb",
32
34
  "spec/spec_helper.rb"
33
35
  ]
@@ -43,6 +45,7 @@ Gem::Specification.new do |s|
43
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
46
  s.add_runtime_dependency(%q<aws-sdk>, ["= 2.1.14"])
45
47
  s.add_development_dependency(%q<rspec>, ["= 2.14.0"])
48
+ s.add_development_dependency(%q<byebug>, [">= 0"])
46
49
  s.add_development_dependency(%q<coveralls>, [">= 0"])
47
50
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
51
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
@@ -51,6 +54,7 @@ Gem::Specification.new do |s|
51
54
  else
52
55
  s.add_dependency(%q<aws-sdk>, ["= 2.1.14"])
53
56
  s.add_dependency(%q<rspec>, ["= 2.14.0"])
57
+ s.add_dependency(%q<byebug>, [">= 0"])
54
58
  s.add_dependency(%q<coveralls>, [">= 0"])
55
59
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
60
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -60,6 +64,7 @@ Gem::Specification.new do |s|
60
64
  else
61
65
  s.add_dependency(%q<aws-sdk>, ["= 2.1.14"])
62
66
  s.add_dependency(%q<rspec>, ["= 2.14.0"])
67
+ s.add_dependency(%q<byebug>, [">= 0"])
63
68
  s.add_dependency(%q<coveralls>, [">= 0"])
64
69
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
70
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe RainForest::CloudFront do
4
+ let(:credentials){ double("AWS Crendetials") }
5
+ let(:client){ double("AWS Client") }
6
+
7
+ let(:cloudfront_distribution){
8
+ {
9
+ etag: 'ETAG',
10
+ distribution: {
11
+ distribution_config: {
12
+ comment: nil,
13
+ logging: {
14
+ bucket: nil,
15
+ prefix: nil
16
+ },
17
+ origins: {
18
+ items: [
19
+ {origin_path: 'OLD_ORIGIN' }
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ before do
28
+ expect(::Aws::CloudFront::Client).to receive(:new).with(access_key_id: ENV["RAIN_FOREST_AWS_AKID"], secret_access_key: ENV["RAIN_FOREST_AWS_SECRET"], region: 'cloudfront.amazonaws.com').and_return(client).at_least(:once)
29
+ end
30
+
31
+ describe "#update_origin" do
32
+ it "works with default public-read permissions" do
33
+ expected_config = {
34
+ comment: '',
35
+ logging: {
36
+ bucket: '',
37
+ prefix: ''
38
+ },
39
+ origins: {
40
+ items: [
41
+ {origin_path: '/NEW_ORIGIN' }
42
+ ]
43
+ }
44
+ }
45
+
46
+ expect(client).to receive(:get_distribution).with(id: 'DISTRIBUTION_ID').and_return(cloudfront_distribution)
47
+ expect(client).to receive(:update_distribution).with(id: 'DISTRIBUTION_ID', if_match: 'ETAG', distribution_config: expected_config)
48
+
49
+ success, message = RainForest::CloudFront.update_origin('DISTRIBUTION_ID', "/NEW_ORIGIN")
50
+
51
+ expect(message).to eq(nil)
52
+ expect(success).to eq(true)
53
+ end
54
+
55
+ it "handles errors" do
56
+ expect(client).to receive(:get_distribution).with(id: 'DISTRIBUTION_ID').and_return(cloudfront_distribution)
57
+ expect(client).to receive(:update_distribution).and_raise(Exception.new("KABOOM!"))
58
+
59
+ success, message = RainForest::CloudFront.update_origin('DISTRIBUTION_ID', "/NEW_ORIGIN")
60
+
61
+ expect(message).to eq("KABOOM!")
62
+ expect(success).to eq(false)
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rain_forest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Beaton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: coveralls
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,8 +140,10 @@ files:
126
140
  - Rakefile
127
141
  - VERSION
128
142
  - lib/rain_forest.rb
143
+ - lib/rain_forest/cloud_front.rb
129
144
  - lib/rain_forest/s3.rb
130
145
  - rain_forest.gemspec
146
+ - spec/rain_forest/cloud_front_spec.rb
131
147
  - spec/rain_forest/s3_spec.rb
132
148
  - spec/spec_helper.rb
133
149
  homepage: http://github.com/LukasBeaton/rain_forest