middleman-s3_redirect 3.0.3 → 3.0.4

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: 6fba30466432df1f1fc4b02c84b31f3f87c0d860
4
- data.tar.gz: aa584c64af0b5f15b9b4ef1c22eae65290e6d779
3
+ metadata.gz: 6645a78129ff9d9ee32b93a06ec00c4c4cfc38c1
4
+ data.tar.gz: da0172f182c49de0d591e28a95fbdeadf993a325
5
5
  SHA512:
6
- metadata.gz: 18dacefd83dbf3b4eae1ebb6199c8581691ea4b84ff3971cfcefd94d47cfb939f400b3de6be73bc65f5eda7775ad107e270224e0c03974d525abee501bd306f4
7
- data.tar.gz: 1753ef083ae0f4538e22f0351e6c405d431243c8cd835327cad47372cae73a53d739a05f85a479e4dd9ba03503da3cd093b6606c2afa64070e3d5cfcbb756feb
6
+ metadata.gz: 1414a3cbdbd1f90854d85ce3aa1122e3c7d1bc40ea4915117bdd5fea790847d3d1f468163b6f65e791e9e24013245e366282a2313d6df741e8a02cde8bd49370
7
+ data.tar.gz: dc40049a708320f698cb412d0232cb35e4abb8bf8cb1017a363b8a03615a1f8d73d212800a7992c60fbca495ed0730b8687b7d16a2e664008f50e8287918ebdb
data/.s3_sync.sample ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ aws_access_key_id: <AWS Access Key>
3
+ aws_secret_access_key: <AWS Secret Access Key>
data/README.md CHANGED
@@ -37,7 +37,40 @@ The ```redirect``` method register a redirect:
37
37
  redirect '/old/path', '/new/path'
38
38
  ```
39
39
 
40
- You can then configure S3 to redirect these path by running ```middleman s3_redirect```.
40
+ You can then configure S3 to redirect these path by running ```middleman s3_redirect```.
41
+
42
+ ### Providing AWS Credentials
43
+
44
+ There are a few ways to provide the AWS credentials for s3_redirect:
45
+
46
+ #### Through ```config.rb```
47
+
48
+ You can set the aws_access_key_id and aws_secret_access_key in the block
49
+ that is passed to the activate method.
50
+
51
+ #### Through ```.s3_sync``` File
52
+
53
+ You can create a ```.s3_sync``` at the root of your middleman project.
54
+ The credentials are passed in the YAML format. The keys match the
55
+ options keys.
56
+
57
+ The .s3_sync file takes precedence to the configuration passed in the
58
+ activate method.
59
+
60
+ A sample ```.s3_sync``` file is included at the root of this repo.
61
+
62
+ #### Through Environment
63
+
64
+ You can also pass the credentials through environment variables. They
65
+ map to the following values:
66
+
67
+ | Setting | Environment Variable |
68
+ | --------------------- | ---------------------------------- |
69
+ | aws_access_key_id | ```ENV['AWS_ACCESS_KEY_ID``` |
70
+ | aws_secret_access_key | ```ENV['AWS_SECRET_ACCESS_KEY']``` |
71
+
72
+ The environment is used when the credentials are not set in the activate
73
+ method or passed through the ```.s3_sync``` configuration file.
41
74
 
42
75
  ## A Debt of Gratitude
43
76
 
@@ -47,7 +80,7 @@ extend it to add my synchronization code. My gratitude goes to @karlfreeman
47
80
  and is work on Middleman sync.
48
81
 
49
82
  Many thanks to [Junya Ogura](https://github.com/juno) for multiple pull
50
- requests improving this gem.
83
+ requests improving this gem.
51
84
 
52
85
  ## Contributing
53
86
 
@@ -2,16 +2,20 @@ require 'middleman-core'
2
2
 
3
3
  module Middleman
4
4
  module S3Redirect
5
- class Options < Struct.new(
6
- :prefix,
7
- :public_path,
8
- :bucket,
9
- :region,
10
- :path_style,
11
- :aws_access_key_id,
12
- :aws_secret_access_key,
13
- :after_build
14
- )
5
+ class Options
6
+ attr_accessor \
7
+ :prefix,
8
+ :public_path,
9
+ :bucket,
10
+ :region,
11
+ :path_style,
12
+ :aws_access_key_id,
13
+ :aws_secret_access_key,
14
+ :after_build
15
+
16
+ def initialize
17
+ self.read_config
18
+ end
15
19
 
16
20
  def redirect(from, to)
17
21
  redirects << RedirectEntry.new(from, to)
@@ -22,6 +26,24 @@ module Middleman
22
26
  end
23
27
 
24
28
  protected
29
+
30
+ def read_config(io = nil)
31
+ unless io
32
+ root_path = ::Middleman::Application.root
33
+ config_file_path = File.join(root_path, ".s3_sync")
34
+
35
+ # skip if config file does not exist
36
+ return unless File.exists?(config_file_path)
37
+
38
+ io = File.open(config_file_path, "r")
39
+ end
40
+
41
+ config = YAML.load(io)
42
+
43
+ self.aws_access_key_id = config["aws_access_key_id"] if config["aws_access_key_id"]
44
+ self.aws_secret_access_key = config["aws_secret_access_key"] if config["aws_secret_access_key"]
45
+ end
46
+
25
47
  class RedirectEntry
26
48
  attr_reader :from, :to
27
49
  def initialize(from, to)
@@ -48,7 +70,7 @@ module Middleman
48
70
  end
49
71
 
50
72
  def registered(app, options_hash = {}, &block)
51
- options = Options.new(options.hash)
73
+ options = Options.new
52
74
  yield options if block_given?
53
75
 
54
76
  @@options = options
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module S3Redirect
3
- VERSION = "3.0.3"
3
+ VERSION = "3.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-s3_redirect
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Jean
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-15 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - .gitignore
78
+ - .s3_sync.sample
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md