knife-dwim 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 +4 -0
- data/LICENSE +24 -0
- data/README.md +12 -0
- data/knife-dwim.gemspec +23 -0
- data/lib/chef/knife/dwim.rb +69 -0
- data/lib/knife-dwim/version.rb +3 -0
- metadata +63 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2010, Maciej Pasternacki <maciej@pasternacki.net>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the copyright holder nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL MACIEJ PASTERNACKI BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# knife-dwim
|
2
|
+
|
3
|
+
Knife plugin to save your mind from remembering whether it was "knife
|
4
|
+
cookbook upload", "knife data bag from file", or "knife role
|
5
|
+
whatever", and your fingers from typing all of this.
|
6
|
+
|
7
|
+
Just use `knife dwim path/to/file`, letting your shell autocomplete
|
8
|
+
the path for you, and have it uploaded to your Chef server correctly!
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
`knife dwim PATH [PATH [PATH [...]]]`
|
data/knife-dwim.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- mode: ruby; encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-dwim/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-dwim"
|
7
|
+
s.version = KnifeDwim::VERSION
|
8
|
+
s.authors = ["Maciej Pasternacki"]
|
9
|
+
s.email = ["maciej@pasternacki.net"]
|
10
|
+
s.homepage = "https://github.com/mpasternacki/knife-dwim"
|
11
|
+
s.summary = %q{Upload file to Chef server correctly}
|
12
|
+
s.description = %q{Run a correct knife command to upload file to Chef server}
|
13
|
+
s.licenses = ['BSD']
|
14
|
+
|
15
|
+
s.rubyforge_project = "knife-dwim"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency "chef"
|
23
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require 'chef/knife'
|
4
|
+
|
5
|
+
module KnifeDwim
|
6
|
+
class Dwim < Chef::Knife
|
7
|
+
banner "knife dwim [-n] FILE [FILE [FILE [...]]]"
|
8
|
+
|
9
|
+
def run_knife(cls, *args)
|
10
|
+
cls.load_deps
|
11
|
+
i = cls.new(args)
|
12
|
+
i.config = config
|
13
|
+
i.run
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
if name_args.empty?
|
18
|
+
ui.error('File name or names required')
|
19
|
+
else
|
20
|
+
name_args.each do |f|
|
21
|
+
path = Pathname.
|
22
|
+
new(f).
|
23
|
+
expand_path
|
24
|
+
|
25
|
+
unless path.exist?
|
26
|
+
ui.error "Path #{path} does not exist."
|
27
|
+
next
|
28
|
+
end
|
29
|
+
|
30
|
+
done = false
|
31
|
+
|
32
|
+
Chef::Config[:cookbook_path].each do |cbp|
|
33
|
+
rel_path = path.relative_path_from(Pathname.new(cbp).expand_path)
|
34
|
+
|
35
|
+
if not rel_path.to_s[0..2] == '../'
|
36
|
+
# path is within a cookbook dir
|
37
|
+
run_knife(Chef::Knife::CookbookUpload, rel_path.to_s.sub(/\/.*/,''))
|
38
|
+
done = true
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
next if done
|
44
|
+
|
45
|
+
path = path.relative_path_from(Pathname.pwd)
|
46
|
+
if path.to_s[0..2] == '../'
|
47
|
+
ui.error "Path #{path.expand_path} is outside the repo."
|
48
|
+
next
|
49
|
+
end
|
50
|
+
|
51
|
+
case path.to_s
|
52
|
+
when /^roles\//
|
53
|
+
run_knife(Chef::Knife::RoleFromFile, path.basename)
|
54
|
+
when /^nodes\//
|
55
|
+
run_knife(Chef::Knife::NodeFromFile, path.basename)
|
56
|
+
when /^environments\//
|
57
|
+
run_knife(Chef::Knife::EnvironmentFromFile, path.basename)
|
58
|
+
when /^data.bags\/(\w+)\/.*\.ya?ml$/
|
59
|
+
run_knife(Chef::Knife::DataBagFromYaml, $1, path.basename)
|
60
|
+
when /^data.bags\/(\w+)\//
|
61
|
+
run_knife(Chef::Knife::DataBagFromYaml, $1, path.basename)
|
62
|
+
else
|
63
|
+
ui.error "Don't know what to do with #{pn}."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-dwim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maciej Pasternacki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: &70145704872900 !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: *70145704872900
|
25
|
+
description: Run a correct knife command to upload file to Chef server
|
26
|
+
email:
|
27
|
+
- maciej@pasternacki.net
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- knife-dwim.gemspec
|
36
|
+
- lib/chef/knife/dwim.rb
|
37
|
+
- lib/knife-dwim/version.rb
|
38
|
+
homepage: https://github.com/mpasternacki/knife-dwim
|
39
|
+
licenses:
|
40
|
+
- BSD
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project: knife-dwim
|
59
|
+
rubygems_version: 1.8.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Upload file to Chef server correctly
|
63
|
+
test_files: []
|