capistrano-secret 1.0.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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +110 -0
- data/Rakefile +2 -0
- data/capistrano-secret.gemspec +25 -0
- data/lib/capistrano/secret/tasks/secret.cap +40 -0
- data/lib/capistrano/secret/version.rb +5 -0
- data/lib/capistrano/secret.rb +9 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 8a4c1fd2482f46d94f7a8c46258af5ebbaffb0f0
|
|
4
|
+
data.tar.gz: 889fb344037a19edb3c807af048398af5cf1d447
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8099c64da791cd6c5680734be431d329375ee973df56cc2dd9aef657d2e10d9f9ede5f92cc5f4261809e14aaaa190ded5ff21deea45d65a7945d608b9f2c8a18
|
|
7
|
+
data.tar.gz: 689386968bad3c37e489caf228427f291ce7674384edda1c02862844271e47e038d9eb58d51942ca2910c58a8d515cee72e277e83ceb0b9247a566dd08029eb6
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Xavier Priour
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# capistrano-secret
|
|
2
|
+
|
|
3
|
+
A [Capistrano](http://capistranorb.com/) gem to isolate secret information.
|
|
4
|
+
|
|
5
|
+
When developing, it is imperative to keep secret information (server names, login, passwords,...) out of source control.
|
|
6
|
+
This usually leads to cumbersome and risky setups, especially when combined with a deployment tool (like Capistrano).
|
|
7
|
+
|
|
8
|
+
This tiny gem provides methods to **easily** do the **right thing**: conveniently tuck all secrets in a JSON file in a dedicated folder, and easily the information from the rest of the Capistrano tasks.
|
|
9
|
+
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
Get the library:
|
|
13
|
+
```ruby
|
|
14
|
+
gem install capistrano-secret
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Load it into your `Capfile`:
|
|
18
|
+
```ruby
|
|
19
|
+
require 'capistrano/secret'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Create secret directory and add it to `.gitignore`:
|
|
23
|
+
```
|
|
24
|
+
config/secret
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then in Capistrano access any secret with:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
secret('path.to.example.key');
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
Here are capistrano-secret's advantages over alternatives (like keeping whole config files out of repository)
|
|
36
|
+
|
|
37
|
+
* All secret information in one unique place: no duplication, easy to keep out of repository.
|
|
38
|
+
* Files contain only secret: no mixing with other, non-sensitive information (like configuration directives).
|
|
39
|
+
* Standard JSON syntax.
|
|
40
|
+
* Each stages has its own set of secrets.
|
|
41
|
+
* Method name makes it explicit to developer this is sensitive information (it's called `secret()`!).
|
|
42
|
+
|
|
43
|
+
Full power shows when used in conjunction with a templating library like [capistrano-template](https://github.com/xavierpriour/capistrano-template), to generate configuration files at deployment.
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
* [Capistrano 3](http://capistranorb.com/)
|
|
48
|
+
|
|
49
|
+
All dependencies are listed in the .gemspec file so if using `bundler` you just need to `bundle install` in your project directory.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
Get the gem, either manually:
|
|
54
|
+
```ruby
|
|
55
|
+
gem install capistrano-secret
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or using `bundler`, add the library to your `Gemfile`:
|
|
59
|
+
```ruby
|
|
60
|
+
gem 'capistrano-secret', require: false
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Include gem in your `Capfile`:
|
|
64
|
+
```ruby
|
|
65
|
+
require 'capistrano/secret'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Create directory where secret information will be stored.
|
|
69
|
+
Default is `config/secret`, to change it update `deploy.rb`:
|
|
70
|
+
```ruby
|
|
71
|
+
set :secret_dir, '.secrets'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Ensure the directory stays out of repository.
|
|
75
|
+
For example, with git, add it to `.gitignore`:
|
|
76
|
+
```
|
|
77
|
+
config/secret
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Then in the directory, create one JSON file per stage (same name as the stage):
|
|
81
|
+
```
|
|
82
|
+
config/secret/production.json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
In the files, define keys as needed, using JSON syntax. For example:
|
|
86
|
+
```JSON
|
|
87
|
+
{
|
|
88
|
+
"db" : {
|
|
89
|
+
"user" : "user_db",
|
|
90
|
+
"password" : "srwhntseithenrsnrsnire",
|
|
91
|
+
"host" : "sql.yourdomain.com",
|
|
92
|
+
"name" : "yourDB"
|
|
93
|
+
},
|
|
94
|
+
"mail" : {
|
|
95
|
+
"mode" : "smtp",
|
|
96
|
+
"user" : "myapp@yourdomain.com",
|
|
97
|
+
"password" : "rastenhrtrethernhtr",
|
|
98
|
+
"host" : "ssl://smtp.yourdomain.com",
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Then in your Capistrano tasks you can access any value using `secret('path.to.key')`.
|
|
104
|
+
The call is safe and will just return `nil` if all or part of the path leads nowhere.
|
|
105
|
+
So you can test the return value of any part of the path to see if an option is present - for example:
|
|
106
|
+
```ruby
|
|
107
|
+
if secret('mail') then
|
|
108
|
+
# do something with mail info, like send a msg after deploy
|
|
109
|
+
end
|
|
110
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'capistrano/secret/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "capistrano-secret"
|
|
8
|
+
spec.version = Capistrano::Secret::VERSION
|
|
9
|
+
spec.authors = ["Xavier Priour"]
|
|
10
|
+
spec.email = ["xavier.priour@bubblyware.com"]
|
|
11
|
+
spec.summary = %q{Capistrano extension to isolate secret information}
|
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
|
13
|
+
spec.homepage = "https://github.com/xavierpriour/capistrano-secret"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
|
|
24
|
+
spec.add_dependency "capistrano", "~> 3"
|
|
25
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
# - key: (string), can be a dot notation
|
|
4
|
+
def secret(key)
|
|
5
|
+
parts = key.split('.');
|
|
6
|
+
result = fetch(:secret, {});
|
|
7
|
+
parts.each {|k|
|
|
8
|
+
if result.has_key?(k);
|
|
9
|
+
result = result[k];
|
|
10
|
+
else
|
|
11
|
+
result = nil;
|
|
12
|
+
break;
|
|
13
|
+
end
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
namespace :secret do
|
|
19
|
+
desc <<-DESC
|
|
20
|
+
Load secrets from :secret_dir (defaults to config/secret).
|
|
21
|
+
|
|
22
|
+
They are then available by calling secret('path.in.dot.notation').
|
|
23
|
+
DESC
|
|
24
|
+
task :load do
|
|
25
|
+
my_stage = fetch(:stage)
|
|
26
|
+
secret = {}
|
|
27
|
+
my_dir = fetch(:secret_dir) || "config/secret"
|
|
28
|
+
secret_file = "#{my_dir}/#{my_stage}.json"
|
|
29
|
+
if (File.exists? secret_file)
|
|
30
|
+
File.open( secret_file, "r" ) do |f|
|
|
31
|
+
secret = JSON.load( f )
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
secret = {}
|
|
35
|
+
end
|
|
36
|
+
set :secret, secret
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
before 'deploy:starting', 'secret:load'
|
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: capistrano-secret
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Xavier Priour
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: capistrano
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
57
|
+
- xavier.priour@bubblyware.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- capistrano-secret.gemspec
|
|
68
|
+
- lib/capistrano/secret.rb
|
|
69
|
+
- lib/capistrano/secret/tasks/secret.cap
|
|
70
|
+
- lib/capistrano/secret/version.rb
|
|
71
|
+
homepage: https://github.com/xavierpriour/capistrano-secret
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata: {}
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubyforge_project:
|
|
91
|
+
rubygems_version: 2.2.2
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: Capistrano extension to isolate secret information
|
|
95
|
+
test_files: []
|