knife-org-utils 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.
- checksums.yaml +7 -0
- data/README.md +42 -0
- data/lib/chef/knife/info.rb +71 -0
- data/lib/chef/knife/switch.rb +26 -0
- data/lib/chef/knife/switch_add.rb +103 -0
- data/lib/chef/knife/switch_list.rb +14 -0
- data/lib/knife-org-utils/version.rb +3 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af93ea12eb77961bc616479637517b54ba380e8b
|
4
|
+
data.tar.gz: d46ed3be6bf9dd7834a38879cc0bf02acb6fa44b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf180b95ce94d019dcc9978d18c24141a3d2e6676da0c1a8dc702816fa6e24edb8980bf9595b3c17a0e0fbd6106521f6be93255a68838d05c5c0b52a5d45f549
|
7
|
+
data.tar.gz: 78d9e0139ebae2f513254101bdac08f133b5da596f52fb0c15405c1f2cbea90c7975f7355f34dc40dc1981fd18cd37e0aaa8f76d2d09e46ae9e5a233cd229a77
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# knife org utils
|
2
|
+
[](http://badge.fury.io/rb/knife-org-utils) [](https://travis-ci.org/secret-sauce/knife-org-utils) [](https://gemnasium.com/secret-sauce/knife-org-utils)
|
3
|
+
|
4
|
+
|
5
|
+
### Description:
|
6
|
+
This is an EXPERIMENTAL knife plugin that allows you :
|
7
|
+
|
8
|
+
- to switch your .chef config files and keys to point to one of your orgs based on command line options
|
9
|
+
- to display information from the `knife.rb` config file in knife's configuration file search path.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
This knife plugin is packaged as a gem. To install it, clone this
|
14
|
+
git repository and run the following command from inside the cloned repo:
|
15
|
+
|
16
|
+
rake install
|
17
|
+
|
18
|
+
|
19
|
+
## Requirements
|
20
|
+
* create a `~/.chef` directory on your workstation and make it a git repo
|
21
|
+
* create branches, each branch containing the appropriate config file and pem files pointing to a specific org
|
22
|
+
|
23
|
+
|
24
|
+
## Subcommands
|
25
|
+
|
26
|
+
### `knife switch add $CHEF_RERO_DIR`
|
27
|
+
Imports `.chef` files from `$CHEF_RERO_DIR/.chef` into a new git branch in `~/.chef` folder. The name of the branch will be based on the `chef_server_url` in the `knife.rb` file. Starter Kit is a valid chef-repo directory.
|
28
|
+
|
29
|
+
### `knife switch BRANCH`
|
30
|
+
checkout to this git branch containing your chef credentials, provided it exists.
|
31
|
+
|
32
|
+
### `knife switch list`
|
33
|
+
list of available branches in `~/.chef` folder.
|
34
|
+
|
35
|
+
### `knife info [options]`
|
36
|
+
prints the current chef server referenced by your `~/.chef/knife.rb`.
|
37
|
+
|
38
|
+
*Options*
|
39
|
+
|
40
|
+
* `--tiny`: Show concise information in oneline
|
41
|
+
* `--medium`: Show important information in oneline
|
42
|
+
* `--long`: Show all information in multi-lines
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeOrgUtils
|
4
|
+
class Info < Chef::Knife
|
5
|
+
|
6
|
+
category 'CHEF KNIFE INFO'
|
7
|
+
banner 'knife info'
|
8
|
+
|
9
|
+
option :tiny,
|
10
|
+
:long => '--tiny',
|
11
|
+
:description => 'Print concise information in oneline',
|
12
|
+
:boolean => true | false
|
13
|
+
|
14
|
+
option :medium,
|
15
|
+
:long => '--medium',
|
16
|
+
:description => 'Print important information in oneline',
|
17
|
+
:boolean => true | false
|
18
|
+
|
19
|
+
option :long,
|
20
|
+
:long => '--long',
|
21
|
+
:description => 'Print all information in multiple lines',
|
22
|
+
:boolean => true | false,
|
23
|
+
:default => true
|
24
|
+
|
25
|
+
def run
|
26
|
+
read_config_data
|
27
|
+
|
28
|
+
unless @config_file.nil?
|
29
|
+
case
|
30
|
+
when config[:tiny] then ui.msg(tiny_print)
|
31
|
+
when config[:medium] then ui.msg(medium_print)
|
32
|
+
else ui.msg(long_print)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_config_data
|
38
|
+
@config_file = Chef::Knife.locate_config_file
|
39
|
+
|
40
|
+
uri = URI(server_url)
|
41
|
+
@host = uri.host
|
42
|
+
|
43
|
+
%r(.*/organizations/(?<org>.*)$) =~ uri.path
|
44
|
+
@organization = org || ''
|
45
|
+
end
|
46
|
+
|
47
|
+
def user_string
|
48
|
+
(username != ENV['USER']) ? "#{username}@" : ''
|
49
|
+
end
|
50
|
+
|
51
|
+
def tiny_print
|
52
|
+
%r(^(?<host>[a-zA-Z0-9-]+)\..*$) =~ @host
|
53
|
+
"#{user_string}#{host}/#{@organization}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def medium_print
|
57
|
+
"#{user_string}#{@host}/#{organization}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def long_print
|
61
|
+
<<-VERBOSE.gsub(/^\s+/, '')
|
62
|
+
Host: #{@host}
|
63
|
+
Username: #{username}
|
64
|
+
Organization: #{@organization}
|
65
|
+
Config File: #{@config_file}
|
66
|
+
VERBOSE
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :host, :organization, :user, :config_file_location
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'git'
|
3
|
+
|
4
|
+
module KnifeOrgUtils
|
5
|
+
class Switch < Chef::Knife
|
6
|
+
|
7
|
+
banner 'knife switch BRANCH'
|
8
|
+
|
9
|
+
def run
|
10
|
+
unless @name_args.length == 1
|
11
|
+
ui.fatal 'You must specify an BRANCH name'
|
12
|
+
show_usage
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
@git = ::Git.open( '~/.chef' )
|
17
|
+
|
18
|
+
begin
|
19
|
+
@git.checkout( "#{@name_args[0]}" )
|
20
|
+
ui.msg "Switched to branch #{@name_args[0]}"
|
21
|
+
rescue Git::GitExecuteError => e
|
22
|
+
ui.error e.message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'git'
|
3
|
+
|
4
|
+
module KnifeOrgUtils
|
5
|
+
class SwitchAdd < Chef::Knife
|
6
|
+
|
7
|
+
banner 'knife switch add CHEF_RERO_DIR'
|
8
|
+
|
9
|
+
def kit_path
|
10
|
+
@kit_path ||= ::File.join( ::File.expand_path( @name_args[0] ), '.chef' )
|
11
|
+
end
|
12
|
+
|
13
|
+
def dot_chef_path
|
14
|
+
@dot_chef_path ||= File.expand_path( '~/.chef' )
|
15
|
+
end
|
16
|
+
|
17
|
+
def git
|
18
|
+
git = ::Git.open( dot_chef_path )
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
unless @name_args.length == 1
|
23
|
+
ui.fatal 'You must specify the path to started kit CHEF-RERO-DIR'
|
24
|
+
show_usage
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
kit_files = get_kit_files
|
29
|
+
branch_name = get_branch_name
|
30
|
+
|
31
|
+
unless branch_exists? branch_name
|
32
|
+
checkout( branch_name )
|
33
|
+
clean_files
|
34
|
+
copy_files( kit_files )
|
35
|
+
commit( branch_name )
|
36
|
+
else
|
37
|
+
ui.info "Branch for #{branch_name} already exists"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_kit_files
|
42
|
+
unless ::File.exists?( kit_path ) && ::File.directory?( kit_path )
|
43
|
+
ui.fatal "Valid starter kit is not found at #{@name_args[0]}"
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
::Dir.glob( "#{@kit_path}/**" ).select{ | f | ::File.file? f }
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_branch_name
|
50
|
+
knife_path = ::File.join( kit_path, 'knife.rb' )
|
51
|
+
knife_data = ::File.read( knife_path )
|
52
|
+
|
53
|
+
%r(^chef_server_url\s+"https{0,1}://(?<host>[a-zA-Z0-9-]+).*/organizations/(?<org>[a-zA-Z0-9_]+)"$) =~ knife_data
|
54
|
+
|
55
|
+
if host.nil? || org.nil?
|
56
|
+
ui.fatal "Invalid knife.rb at #{knife_path}"
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
"#{host}/#{org}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def branch_exists?( branch_name )
|
64
|
+
git.branches.local.find do | branch |
|
65
|
+
branch.name == branch_name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def checkout( branch_name )
|
70
|
+
begin
|
71
|
+
git.branch( branch_name ).checkout
|
72
|
+
rescue Git::GitExecuteError => e
|
73
|
+
ui.fatal e.message
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def copy_files( files )
|
79
|
+
files.each do | file |
|
80
|
+
filename = ::File.basename file
|
81
|
+
dest = ::File.join( dot_chef_path, filename )
|
82
|
+
::FileUtils.copy( file, dest )
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def clean_files
|
87
|
+
files = ::Dir.glob( "#{dot_chef_path}/**" ).select{ | f | ::File.file? f }
|
88
|
+
files.each do |file|
|
89
|
+
::File.unlink( file )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def commit( branch_name )
|
94
|
+
begin
|
95
|
+
git.add( :all=>true )
|
96
|
+
git.commit( "Adding #{branch_name} from #{kit_path}" )
|
97
|
+
rescue Git::GitExecuteError => e
|
98
|
+
ui.fatal e.message
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-org-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Venkat Venkataraju
|
8
|
+
- Shruthi Venkateswaran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: git
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: json
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: Manages your .chef org, and provides info about your chef config
|
99
|
+
email:
|
100
|
+
- ven@yahoo-inc.com
|
101
|
+
- shruthiv@yahoo-inc.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- README.md
|
107
|
+
- lib/chef/knife/info.rb
|
108
|
+
- lib/chef/knife/switch.rb
|
109
|
+
- lib/chef/knife/switch_add.rb
|
110
|
+
- lib/chef/knife/switch_list.rb
|
111
|
+
- lib/knife-org-utils/version.rb
|
112
|
+
homepage: https://github.com/secret-sauce/knife-org-utils.git
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.2.2
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: knife org
|
136
|
+
test_files: []
|