gnm-cap_permission 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "capistrano"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ capistrano (2.11.2)
5
+ highline
6
+ net-scp (>= 1.0.0)
7
+ net-sftp (>= 2.0.0)
8
+ net-ssh (>= 2.0.14)
9
+ net-ssh-gateway (>= 1.1.0)
10
+ git (1.2.5)
11
+ highline (1.6.11)
12
+ jeweler (1.6.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ net-scp (1.0.4)
17
+ net-ssh (>= 1.99.1)
18
+ net-sftp (2.0.5)
19
+ net-ssh (>= 2.0.9)
20
+ net-ssh (2.3.0)
21
+ net-ssh-gateway (1.1.0)
22
+ net-ssh (>= 1.99.1)
23
+ rake (0.9.2.2)
24
+ rcov (1.0.0)
25
+ shoulda (3.0.1)
26
+ shoulda-context (~> 1.0.0)
27
+ shoulda-matchers (~> 1.0.0)
28
+ shoulda-context (1.0.0)
29
+ shoulda-matchers (1.0.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.0.0)
36
+ capistrano
37
+ jeweler (~> 1.6.4)
38
+ rcov
39
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Gorilla Nation Media
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = gnm-cap_permission
2
+
3
+ Adds group based permissions to Capistrano tasks.
4
+
5
+ == Installation
6
+
7
+ $ gem install gnm-cap_permission
8
+
9
+ Include in your Capfile
10
+ require 'rubygems'
11
+ require 'gnm-cap_permission'
12
+
13
+ == Usage
14
+
15
+ Permission by group:
16
+ set :group_name, "releasemgmt" # allows users in 'releasemgmt' group to run cap tasks
17
+ Note: Users in "root", "sysadmins", and "confmgmt" groups are granted rights by default
18
+
19
+ Permission by users:
20
+ set :deployment_users, ["leeroy", "jenkins"] # allows user 'leeroy' and user 'jenkins' to run cap tasks
21
+
22
+ == Contributing to cap_permission
23
+
24
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
25
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
26
+ * Fork the project
27
+ * Start a feature/bugfix branch
28
+ * Commit and push until you are happy with your contribution
29
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
30
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2012 Gorilla Nation Media. See LICENSE.txt for
35
+ further details.
36
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "gnm-cap_permission"
18
+ gem.homepage = "https://github.com/GorillaNation/gnm-cap_permission"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{adds group based permissions to Capistrano tasks}
21
+ gem.description = %Q{adds group based permissions to Capistrano tasks}
22
+ gem.email = "configurationmanagement@gorillanation.com"
23
+ gem.authors = ["Dru Ibarra"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "gnm-cap_permission #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.3
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gnm-cap_permission}
8
+ s.version = "1.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Dru Ibarra}]
12
+ s.date = %q{2012-03-20}
13
+ s.description = %q{adds group based permissions to Capistrano tasks}
14
+ s.email = %q{configurationmanagement@gorillanation.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "gnm-cap_permission.gemspec",
28
+ "lib/gnm-cap_permission.rb",
29
+ "test/helper.rb",
30
+ "test/test_cap_permission.rb"
31
+ ]
32
+ s.homepage = %q{https://github.com/GorillaNation/gnm-cap_permission}
33
+ s.licenses = [%q{MIT}]
34
+ s.require_paths = [%q{lib}]
35
+ s.rubygems_version = %q{1.8.6}
36
+ s.summary = %q{adds group based permissions to Capistrano tasks}
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
43
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ s.add_development_dependency(%q<rcov>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<capistrano>, [">= 0"])
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<capistrano>, [">= 0"])
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,48 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ set :admin_groups, ["root", "sysadmins", "confmgmt"]
3
+
4
+ def user_in_group?(group)
5
+ return false if group.nil?
6
+ user = ENV["SUDO_USER"]
7
+ if user.nil?
8
+ puts "\e[0;33m WARNING: 'cap_permission' gem requires you to run cap with sudo\e[0m"
9
+ return false
10
+ end
11
+ groups = capture("groups #{user}").split
12
+ groups.include?(group)
13
+ end
14
+
15
+ def admin_user?()
16
+ admin_groups.each do |admin_group|
17
+ return true if user_in_group?(admin_group)
18
+ end
19
+ return false
20
+ rescue NameError => e
21
+ puts "\e[0;33m WARNING: #{e}\e[0m"
22
+ false
23
+ end
24
+
25
+ def deployment_user?()
26
+ user = ENV["SUDO_USER"]
27
+ deployment_users.to_a.include?(user)
28
+ rescue NameError => e
29
+ puts "\e[0;33m WARNING: #{e}\e[0m"
30
+ false
31
+ end
32
+
33
+ namespace :permission do
34
+ desc "check user's group membership"
35
+ task :check do
36
+ if (not admin_user? and not user_in_group?(group_name) and not deployment_user?)
37
+ abort "\n\n\n\e[0;31m You do not have proper group membership to run this deployment! \e[0m\n\n\n"
38
+ end
39
+ end
40
+ end
41
+
42
+ if Gem.available?('capistrano-ext')
43
+ after "multistage:ensure", "permission:check"
44
+ else
45
+ on :start, "permission:check"
46
+ end
47
+
48
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'gnm-cap_permission'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCapPermission < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gnm-cap_permission
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 3
10
+ version: 1.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Dru Ibarra
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ version_requirements: *id001
32
+ name: capistrano
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ version_requirements: *id002
46
+ name: shoulda
47
+ prerelease: false
48
+ - !ruby/object:Gem::Dependency
49
+ type: :development
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ hash: 23
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ version_requirements: *id003
62
+ name: bundler
63
+ prerelease: false
64
+ - !ruby/object:Gem::Dependency
65
+ type: :development
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 1
74
+ - 6
75
+ - 4
76
+ version: 1.6.4
77
+ version_requirements: *id004
78
+ name: jeweler
79
+ prerelease: false
80
+ - !ruby/object:Gem::Dependency
81
+ type: :development
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ version_requirements: *id005
92
+ name: rcov
93
+ prerelease: false
94
+ description: adds group based permissions to Capistrano tasks
95
+ email: configurationmanagement@gorillanation.com
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files:
101
+ - LICENSE.txt
102
+ - README.rdoc
103
+ files:
104
+ - .document
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ - Rakefile
110
+ - VERSION
111
+ - gnm-cap_permission.gemspec
112
+ - lib/gnm-cap_permission.rb
113
+ - test/helper.rb
114
+ - test/test_cap_permission.rb
115
+ homepage: https://github.com/GorillaNation/gnm-cap_permission
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.6
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: adds group based permissions to Capistrano tasks
148
+ test_files: []
149
+