capistrano-secrets-generate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41ee61b439747eddd49dd8c2f82936f9f0d000dc
4
+ data.tar.gz: db75248b4689fe90cee52546b3d3e0531249a6e3
5
+ SHA512:
6
+ metadata.gz: 7daeee58fb6602908511d48823770389132bc525167c26e167afbe84849fc008da77873d2c01e6c5732f58437efc8bad921797f1a8b18a18b96b13cda515e598
7
+ data.tar.gz: 8d2781ff694274c0cd5ff009adf31b7a79dcdd5863b8a69bc7495a8b067d43dcaade5bd90fcffce217f5058170ae2413c2675b8032015887e20c71e5fb96ad68
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in *.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2017 Mike Crockett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Capistrano::SecretsGenerate
2
+
3
+ Capistrano tasks for handling generating a `secret.token` when deploying Rails 4+ apps.
4
+
5
+ ### Install
6
+
7
+ Add this to `Gemfile`:
8
+
9
+ group :development do
10
+ gem 'capistrano', '~> 3.2.1'
11
+ gem 'capistrano-secrets-generate', '~> 1.0.0'
12
+ end
13
+
14
+ And then:
15
+
16
+ $ bundle install
17
+
18
+ ### Setup and usage
19
+
20
+ - make secret.yml load file `config/secret.token`:
21
+
22
+ production: &production
23
+ <% if ((false == Rails.env.test?) && (false == Rails.env.development?)) %>
24
+ secret_key_base: <%= File.read(File.join(Rails.application.config.root, "config", "secret.token")) %>
25
+ <% end %>
26
+
27
+ - add to `Capfile`:
28
+
29
+ require 'capistrano/secrets_generate'
30
+
31
+ You can now proceed with other deployment tasks.
32
+
33
+ ### How it works
34
+
35
+ On deployment:
36
+
37
+ - we look for `secret.token` file on the server shared dir<br/>
38
+ - if it exists, we add to linked files<br/>
39
+ - if not we look for file in current deployment, if it exists, we copy to shared and add to linked<br/>
40
+ - if nothing exists, then we use `rake secret` to create a new secret.<br/>
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "capistrano/secrets_generate/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-secrets-generate"
8
+ gem.version = Capistrano::SecretsGenerate::VERSION
9
+ gem.authors = ["Mike Crockett"]
10
+ gem.email = ["rubygems@mmcrockett.com"]
11
+ gem.description = <<-EOF.gsub(/^\s+/, "")
12
+ Capistrano tasks for automating generating or linking a secret in Rails 4+.
13
+
14
+ This plugin generates a secret if one doesn't exist on a remote server.
15
+
16
+ If a secret is already found on remote server, then it copies to shared
17
+ location and links.
18
+ EOF
19
+ gem.summary = "Capistrano tasks for automating generating/linking a secret."
20
+ gem.homepage = "https://github.com/mmcrockett/capistrano-secrets-generate"
21
+
22
+ gem.files = `git ls-files`.split($/)
23
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
+ gem.require_paths = ["lib"]
26
+ gem.licenses = ['MIT']
27
+
28
+ gem.add_dependency "capistrano", "~> 3.1"
29
+ gem.add_development_dependency "rake", "~> 0"
30
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ module Capistrano
2
+ module SecretsGenerate
3
+ module Helpers
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ require "pathname"
2
+
3
+ module Capistrano
4
+ module SecretsGenerate
5
+ module Paths
6
+ def secret_token_path
7
+ return Pathname.new(fetch(:secret_file))
8
+ end
9
+
10
+ def secret_token_linked_path
11
+ return shared_path.join(secret_token_path)
12
+ end
13
+
14
+ def secret_token_linked_dir
15
+ return secret_token_linked_path.join('..')
16
+ end
17
+
18
+ def secret_token_current_path
19
+ return current_path.join(secret_token_path)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module SecretsGenerate
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "capistrano/secrets_generate/paths"
2
+ require "capistrano/secrets_generate/helpers"
3
+ load File.expand_path("../tasks/secrets_generate.rake", __FILE__)
@@ -0,0 +1,48 @@
1
+ include Capistrano::SecretsGenerate::Paths
2
+ include Capistrano::SecretsGenerate::Helpers
3
+
4
+ namespace :load do task :defaults do
5
+ set(:secret_file, File.join("config", "secret.token"))
6
+ end
7
+ end
8
+
9
+ namespace :secrets_generate do
10
+ desc "Generate `secret.token` if none exists, otherwise copy and append to soft-link list."
11
+ task :check_secret do
12
+ on release_roles :all do
13
+ secret_token_linked_exists = test("[ -f #{secret_token_linked_path} ]")
14
+ secret_token_current_exists = test("[ -f #{secret_token_current_path} ]")
15
+
16
+ if ((false == secret_token_current_exists) && (false == secret_token_linked_exists))
17
+ after("deploy:published", "secrets_generate:generate_secret")
18
+ else
19
+ if (true == secret_token_current_exists)
20
+ if (false == test("[ -d #{secret_token_linked_dir} ]"))
21
+ execute(:mkdir, secret_token_linked_dir)
22
+ end
23
+
24
+ execute(:cp, secret_token_current_path, secret_token_linked_path)
25
+ end
26
+
27
+ append(:linked_files, secret_token_path)
28
+ end
29
+ end
30
+ end
31
+
32
+ desc "Use rake to generate new secret."
33
+ task :generate_secret do
34
+ on release_roles :all do
35
+ within release_path do
36
+ with rails_env: fetch(:rails_env) do
37
+ # Test that it works so we don't create bad file and it shows error.
38
+ execute(:rake, 'secret')
39
+
40
+ # Now run for real
41
+ execute(:rake, 'secret', '>', secret_token_path)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ before("deploy:check:linked_files", "secrets_generate:check_secret")
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-secrets-generate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Crockett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
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
+ description: |
42
+ Capistrano tasks for automating generating or linking a secret in Rails 4+.
43
+ This plugin generates a secret if one doesn't exist on a remote server.
44
+ If a secret is already found on remote server, then it copies to shared
45
+ location and links.
46
+ email:
47
+ - rubygems@mmcrockett.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - ".gitignore"
53
+ - Gemfile
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - capistrano-secrets-generate.gemspec
58
+ - lib/capistrano/capistrano-secrets-generate.rb
59
+ - lib/capistrano/secrets_generate.rb
60
+ - lib/capistrano/secrets_generate/helpers.rb
61
+ - lib/capistrano/secrets_generate/paths.rb
62
+ - lib/capistrano/secrets_generate/version.rb
63
+ - lib/capistrano/tasks/secrets_generate.rake
64
+ homepage: https://github.com/mmcrockett/capistrano-secrets-generate
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.6.7
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Capistrano tasks for automating generating/linking a secret.
88
+ test_files: []