chefenv 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Garson
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,57 @@
1
+ # Chefenv
2
+
3
+ Manages multiple chef server/organization environments
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'chefenv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install chefenv
18
+
19
+ ## Usage
20
+
21
+ Execute:
22
+
23
+ $ chefenv init
24
+
25
+ This will ensure that you have a ~/chef directory.
26
+
27
+ Create a directory under ~/chef for each of your environments.
28
+ Put your knife.rb, .pem and any other files you need for that organization
29
+ under that folder. For example, for my hosted chef organization, I create
30
+ ~/chef/hosted and put my knife.rb and .pem files in there. Additionally, this is
31
+ a reasonable place to put secret key files.
32
+
33
+ Once you have at least one folder created under ~/chef, you can
34
+
35
+ $ chefenv list
36
+
37
+ or
38
+
39
+ $ chefenv use ENVNAME
40
+
41
+ ## Future Work
42
+
43
+ 1. Allow using a different directory than ~/chef
44
+ 1. Read the ~/.chef symlink to get the current env instead of using ~/chef/current file
45
+ 1. Add tasks for creating/destroying organizations
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
55
+ ## Author
56
+
57
+ Author:: Andrew Garson (<andrew.garson@gmail.com>)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/chefenv ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("../../lib", __FILE__)
4
+ require 'chefenv'
5
+
6
+ ChefEnv::Tasks.start
data/chefenv.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chefenv/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "chefenv"
8
+ gem.version = Chefenv::VERSION
9
+ gem.authors = ["Andrew Garson"]
10
+ gem.email = ["andrew.garson@gmail.com"]
11
+ gem.description = %q{Manage your current Chef server endpoint}
12
+ gem.summary = gem.description
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "thor"
21
+ end
@@ -0,0 +1,3 @@
1
+ module Chefenv
2
+ VERSION = "0.1.0"
3
+ end
data/lib/chefenv.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'thor'
2
+ require 'fileutils'
3
+ require "chefenv/version"
4
+ require 'pathname'
5
+
6
+ module ChefEnv
7
+ # Your code goes here...
8
+ class Tasks < Thor
9
+
10
+ desc "list", "list the available chef environments"
11
+ def list
12
+ current = current_environment
13
+ available_environments.each do |env|
14
+ puts "#{(env == current_environment) ? '*' : ' '} #{env}"
15
+ end
16
+ if available_environments.size == 0
17
+ puts "No Environments Available"
18
+ end
19
+ end
20
+
21
+ desc "use ENV", "use a particular environment"
22
+ def use(env="")
23
+ unless env == current_environment
24
+ if available_environments.include?(env)
25
+ select_environment(env)
26
+ else
27
+ puts "#{env} is not a known environment"
28
+ list
29
+ end
30
+ end
31
+ end
32
+
33
+ desc "current", "display the name of the current environment"
34
+ def current()
35
+ puts current_environment
36
+ end
37
+
38
+ desc "init", "initialize the environment"
39
+ def init()
40
+ FileUtils.mkdir_p(File.expand_path("~/chef")) unless File.exists?("~/chef")
41
+ current = current_environment
42
+
43
+ if current.nil?
44
+ puts 'No environment selected. Picking the first one that I find. You can change it with `chefenv use ENV`'
45
+ available = available_environments
46
+ if available.empty?
47
+ puts "No environments are available"
48
+ else
49
+ puts "Trying to use '#{available.first}'"
50
+ use(available.first)
51
+ end
52
+ current = current_environment
53
+ list
54
+ return
55
+ end
56
+
57
+ unless available_environments.include?(current)
58
+ puts "'#{current}' is selected as the current environment, but it is not valid. Please select a different environment"
59
+ `rm -f ~/.chef`
60
+ `rm -f ~/chef/current`
61
+ list
62
+ return
63
+ end
64
+
65
+ end
66
+
67
+ no_tasks do
68
+ def available_environments
69
+ Pathname.new(File.expand_path("~/chef")).children.select { |c| c.directory? }.map { |d| d.basename.to_s }
70
+ end
71
+
72
+ def select_environment(env)
73
+ File.write(File.expand_path("~/chef/current"), env)
74
+ `rm -f ~/.chef`
75
+ `ln -s ~/chef/#{env} ~/.chef`
76
+ end
77
+
78
+ def current_environment
79
+ begin
80
+ File.read(File.expand_path("~/chef/current")).chomp
81
+ rescue Errno::ENOENT
82
+ nil
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chefenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Garson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Manage your current Chef server endpoint
31
+ email:
32
+ - andrew.garson@gmail.com
33
+ executables:
34
+ - chefenv
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/chefenv
44
+ - chefenv.gemspec
45
+ - lib/chefenv.rb
46
+ - lib/chefenv/version.rb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Manage your current Chef server endpoint
71
+ test_files: []
72
+ has_rdoc: