Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
77ce88a7
Commit
77ce88a7
authored
Aug 24, 2011
by
H. Wade Minter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Fog credentials to be set from an external YAML file.
parent
d336c4a1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
lib/paperclip/storage/fog.rb
+20
-3
test/fixtures/fog.yml
+8
-0
test/fog_test.rb
+34
-0
No files found.
lib/paperclip/storage/fog.rb
View file @
77ce88a7
...
...
@@ -42,7 +42,7 @@ module Paperclip
base
.
instance_eval
do
@fog_directory
=
@options
[
:fog_directory
]
@fog_credentials
=
@options
[
:fog_credentials
]
@fog_credentials
=
parse_credentials
(
@options
[
:fog_credentials
])
@fog_host
=
@options
[
:fog_host
]
@fog_public
=
@options
.
key?
(
:fog_public
)
?
@options
[:
fog_public
]
:
true
@fog_file
=
@options
[
:fog_file
]
||
{}
...
...
@@ -120,8 +120,27 @@ module Paperclip
end
end
def
parse_credentials
creds
creds
=
find_credentials
(
creds
).
stringify_keys
env
=
Object
.
const_defined?
(
:Rails
)
?
Rails
.
env
:
nil
(
creds
[
env
]
||
creds
).
symbolize_keys
end
private
def
find_credentials
creds
case
creds
when
File
YAML
::
load
(
ERB
.
new
(
File
.
read
(
creds
.
path
)).
result
)
when
String
,
Pathname
YAML
::
load
(
ERB
.
new
(
File
.
read
(
creds
)).
result
)
when
Hash
creds
else
raise
ArgumentError
,
"Credentials are not a path, file, or hash."
end
end
def
connection
@connection
||=
::
Fog
::
Storage
.
new
(
@fog_credentials
)
end
...
...
@@ -129,8 +148,6 @@ module Paperclip
def
directory
@directory
||=
connection
.
directories
.
new
(
:key
=>
@fog_directory
)
end
end
end
end
test/fixtures/fog.yml
0 → 100644
View file @
77ce88a7
development
:
provider
:
AWS
aws_access_key_id
:
AWS_ID
aws_secret_access_key
:
AWS_SECRET
test
:
provider
:
AWS
aws_access_key_id
:
AWS_ID
aws_secret_access_key
:
AWS_SECRET
test/fog_test.rb
View file @
77ce88a7
...
...
@@ -5,6 +5,40 @@ Fog.mock!
class
FogTest
<
Test
::
Unit
::
TestCase
context
""
do
context
"with credentials provided in a path string"
do
setup
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
:storage
=>
:fog
,
:url
=>
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
:fog_credentials
=>
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'fog.yml'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
end
should
"have the proper information loading credentials from a file"
do
assert_equal
@dummy
.
avatar
.
instance_variable_get
(
"@fog_credentials"
)[
:provider
],
'AWS'
end
end
context
"with credentials provided in a File object"
do
setup
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
:storage
=>
:fog
,
:url
=>
'/:attachment/:filename'
,
:fog_directory
=>
"paperclip"
,
:fog_credentials
=>
File
.
open
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'fog.yml'
))
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
,
'5k.png'
),
'rb'
)
end
should
"have the proper information loading credentials from a file"
do
assert_equal
@dummy
.
avatar
.
instance_variable_get
(
"@fog_credentials"
)[
:provider
],
'AWS'
end
end
context
"with default values for path and url"
do
setup
do
rebuild_model
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment