cknife 1.3.0 → 1.4.1
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 +5 -5
- data/Gemfile +2 -1
- data/Gemfile.lock +7 -6
- data/README.md +17 -68
- data/VERSION +1 -1
- data/bin/cknifewcdir +1 -1
- data/cknife.gemspec +19 -16
- data/lib/cknife/cknife_mysql.rb +33 -1
- data/lib/cknife/cknife_pg.rb +2 -1
- data/lib/cknife/command_line.rb +72 -18
- metadata +41 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e37b17c77acd0b4e3061acda6e7006191c5b273ebd4ece0a4c1684a200372238
|
|
4
|
+
data.tar.gz: 298ff9070254761d827c2c76e9bfa61f28b86415e8a313f6cb70793bc7688185
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e39607eff2db2b6648819c57af80575a64b7f3c912b2b6ceb86edb001d26c33dd5b0c07da2c585695ca8942b3c78fa49600442686162aaf052d8b72e51c4dec7
|
|
7
|
+
data.tar.gz: 0b2dd211a8216da414727601b60ac91c2570c7b8164791707d6f469b5882479fa38362d8d19ff74337ebbbdc4dfbd73626195fdc6ecb1811083a1affc6f300ce
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
source "http://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gem "rest-client", '>= 1.8.0', '~> 1'
|
|
4
|
-
gem "nokogiri",
|
|
4
|
+
gem "nokogiri", ">= 1.10.4", '~> 1'
|
|
5
5
|
gem "i18n", '>= 0.6.6'
|
|
6
6
|
gem "activesupport", '>= 4.2.9'
|
|
7
7
|
gem "actionpack", '>= 4.2.9'
|
|
@@ -11,6 +11,7 @@ gem "builder", '~> 3.0'
|
|
|
11
11
|
gem "fog-aws", '< 3.0'
|
|
12
12
|
gem "unf", '>= 0.1', '~> 0'
|
|
13
13
|
gem "daemons"
|
|
14
|
+
gem 'loofah', '~> 2.2.3'
|
|
14
15
|
|
|
15
16
|
# Add dependencies to develop your gem here.
|
|
16
17
|
# Include everything needed to run rake, tests, features, etc.
|
data/Gemfile.lock
CHANGED
|
@@ -75,21 +75,21 @@ GEM
|
|
|
75
75
|
rdoc
|
|
76
76
|
semver2
|
|
77
77
|
jwt (1.5.6)
|
|
78
|
-
loofah (2.2.
|
|
78
|
+
loofah (2.2.3)
|
|
79
79
|
crass (~> 1.0.2)
|
|
80
80
|
nokogiri (>= 1.5.9)
|
|
81
81
|
mail (2.5.5)
|
|
82
82
|
mime-types (~> 1.16)
|
|
83
83
|
treetop (~> 1.4.8)
|
|
84
84
|
mime-types (1.25.1)
|
|
85
|
-
mini_portile2 (2.
|
|
85
|
+
mini_portile2 (2.4.0)
|
|
86
86
|
minitest (5.11.3)
|
|
87
87
|
multi_json (1.13.1)
|
|
88
88
|
multi_xml (0.6.0)
|
|
89
89
|
multipart-post (2.0.0)
|
|
90
90
|
netrc (0.11.0)
|
|
91
|
-
nokogiri (1.
|
|
92
|
-
mini_portile2 (~> 2.
|
|
91
|
+
nokogiri (1.10.4)
|
|
92
|
+
mini_portile2 (~> 2.4.0)
|
|
93
93
|
oauth2 (1.4.0)
|
|
94
94
|
faraday (>= 0.8, < 0.13)
|
|
95
95
|
jwt (~> 1.0)
|
|
@@ -139,11 +139,12 @@ DEPENDENCIES
|
|
|
139
139
|
fog-aws (< 3.0)
|
|
140
140
|
i18n (>= 0.6.6)
|
|
141
141
|
jeweler (~> 2.1)
|
|
142
|
+
loofah (~> 2.2.3)
|
|
142
143
|
mail (~> 2.5.5)
|
|
143
|
-
nokogiri (~> 1, >= 1.
|
|
144
|
+
nokogiri (~> 1, >= 1.10.4)
|
|
144
145
|
rest-client (~> 1, >= 1.8.0)
|
|
145
146
|
thor (~> 0, >= 0.14)
|
|
146
147
|
unf (~> 0, >= 0.1)
|
|
147
148
|
|
|
148
149
|
BUNDLED WITH
|
|
149
|
-
1.16.
|
|
150
|
+
1.16.6
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
[](https://badge.fury.io/rb/cknife)
|
|
3
|
+
|
|
2
4
|
# Quickstart
|
|
3
5
|
|
|
4
6
|
cknife is a set of command line tools. They...do different things.
|
|
@@ -21,66 +23,13 @@ named `your-bucket-name`.
|
|
|
21
23
|
|
|
22
24
|
> cknifeaws afew my-bucket --count=50
|
|
23
25
|
|
|
24
|
-
That will show you 50 of them.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
[
|
|
30
|
-
|
|
31
|
-
yet you still find it silly to be going to the same [old documentation
|
|
32
|
-
websites](https://www.postgresql.org/docs/9.5/static/backup-dump.html)
|
|
33
|
-
for things you are certain you once knew how to do?
|
|
34
|
-
|
|
35
|
-
Well, you can write a script in something other than
|
|
36
|
-
bash to automate the precise command line invocation
|
|
37
|
-
that you used to accomplish a task. But when you
|
|
38
|
-
move to a different project, how can you take your
|
|
39
|
-
scripts with you? Why not design your scripts
|
|
40
|
-
to be robust enough so that they are conventional?
|
|
41
|
-
|
|
42
|
-
Why can't a [Stackoverflow](https://stackoverflow.com) question's
|
|
43
|
-
answer be captured in a form that can be configured and called by you
|
|
44
|
-
(or someone who was in your position before), so that you don't have
|
|
45
|
-
to enter the same question into
|
|
46
|
-
[google.com](https://www.google.com/?q=LOL%20HALP%20ME%20CODE) again
|
|
47
|
-
later down the road?
|
|
48
|
-
|
|
49
|
-
Why make a browser bookmark if you can skip the browser entirely?
|
|
50
|
-
It's not like the browser bookmark can compile the answer into machine
|
|
51
|
-
code for you, anyway.
|
|
52
|
-
|
|
53
|
-
If someone turns the answer into a programmed tool, what if your IDE
|
|
54
|
-
is no better than the command line when it comes to invoking it?
|
|
55
|
-
|
|
56
|
-
I created cknife to have a set of scripts to fall back on when
|
|
57
|
-
confronted with the above encounter I've been having for years. cknife
|
|
58
|
-
is a toolset that encapsulates common command line expressions that
|
|
59
|
-
developers use when at work.
|
|
60
|
-
|
|
61
|
-
I've never used [chef](https://www.chef.io), but were I to grow
|
|
62
|
-
cknife, I wouldn't be surprised to see it overlap with it.
|
|
63
|
-
|
|
64
|
-
cknife currently has some wrappers around Amazon's EC2 and S3
|
|
65
|
-
services. It has others around MySQL and PostgreSQL. It has a trivial
|
|
66
|
-
one around [du](http://man7.org/linux/man-pages/man1/du.1.html). The
|
|
67
|
-
`cknifemon` tool, meanwhile, is a daemon that can launch PUT HTTP
|
|
68
|
-
requests to an endpoint you configure, on a schedule.
|
|
69
|
-
|
|
70
|
-
It can be used for system administration, but it can be also be used
|
|
71
|
-
to aid developers as they acclimate themselves to a piece of
|
|
72
|
-
technology with which they may not be familiar, and for which
|
|
73
|
-
documentation may be a little scattered. It can be used
|
|
74
|
-
to bang on a piece of technology for the sake of your own
|
|
75
|
-
learning, too.
|
|
76
|
-
|
|
77
|
-
To be precise, cknife consists of command line executables. These
|
|
78
|
-
tools often require more information from the user, which can be put
|
|
79
|
-
into a configuration file, `cknife.yml`, in YAML format, and found by
|
|
80
|
-
cknife in the current working directory ($CWD) when it is invoked.
|
|
81
|
-
|
|
82
|
-
See the [Wiki](https://github.com/mikedll/cknife/wiki) for
|
|
83
|
-
details on the tools cknife has.
|
|
26
|
+
That will show you 50 of them. You can see the help for this command, too.
|
|
27
|
+
|
|
28
|
+
> cknifeaws help
|
|
29
|
+
|
|
30
|
+
See the
|
|
31
|
+
[Wiki](https://github.com/mikedll/cknife/wiki) for details on the
|
|
32
|
+
tools cknife has. A complete list of the tools is below under 'usage'.
|
|
84
33
|
|
|
85
34
|
# Requirements
|
|
86
35
|
|
|
@@ -118,14 +67,14 @@ these two places, in order:
|
|
|
118
67
|
|
|
119
68
|
Here are the command line executables:
|
|
120
69
|
|
|
121
|
-
- cknifeaws
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
70
|
+
- cknifeaws - AWS wrappers.
|
|
71
|
+
- cknifemail - SMTP email sender.
|
|
72
|
+
- cknifemon - Daemon that sends heartbeat signals to a place of your choosing.
|
|
73
|
+
- cknifemysql - MySQL utilities.
|
|
74
|
+
- cknifepg - PostgreSQL utilities.
|
|
75
|
+
- cknifewcdir - Lines-of-code calculator.
|
|
76
|
+
- cknifedub - Spot directories that are particularly space-consuming.
|
|
77
|
+
- cknifenowtimestamp - Get a now() timestamp string.
|
|
129
78
|
|
|
130
79
|
You can invoke any of them like this:
|
|
131
80
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.4.1
|
data/bin/cknifewcdir
CHANGED
|
@@ -31,7 +31,7 @@ class CKnifeWcdir < Thor
|
|
|
31
31
|
def count(*patterns)
|
|
32
32
|
start_point = options[:start].empty? ? "." : options[:start].chomp('/')
|
|
33
33
|
|
|
34
|
-
pattern_s = "\\( " + patterns.map { |p| "-name #{p}" }.join(' -
|
|
34
|
+
pattern_s = "\\( " + patterns.map { |p| "-name '#{p}'" }.join(' -or ') + " \\) "
|
|
35
35
|
skip_s = options[:skip].empty? ? "" : "-type d \\( " + options[:skip].map { |dir| "-path #{start_point}/#{dir.chomp('/')}" }.join(' -o ') + " \\) -prune -o "
|
|
36
36
|
|
|
37
37
|
# note patterns must go after the skips (after the -prune -o)
|
data/cknife.gemspec
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: cknife 1.
|
|
5
|
+
# stub: cknife 1.4.1 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "cknife".freeze
|
|
9
|
-
s.version = "1.
|
|
9
|
+
s.version = "1.4.1"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib".freeze]
|
|
13
13
|
s.authors = ["Michael Rivera".freeze]
|
|
14
|
-
s.date = "
|
|
14
|
+
s.date = "2019-08-31"
|
|
15
15
|
s.description = "A collection of command line tools, especially for popular API services.".freeze
|
|
16
16
|
s.email = "soymrmike@gmail.com".freeze
|
|
17
17
|
s.executables = ["cknifeaws".freeze, "cknifedub".freeze, "cknifemail".freeze, "cknifemon".freeze, "cknifemysql".freeze, "cknifenowtimestamp".freeze, "cknifepg".freeze, "cknifewcdir".freeze]
|
|
@@ -51,53 +51,56 @@ Gem::Specification.new do |s|
|
|
|
51
51
|
]
|
|
52
52
|
s.homepage = "http://github.com/mikedll/cknife".freeze
|
|
53
53
|
s.licenses = ["".freeze]
|
|
54
|
-
s.rubygems_version = "2.
|
|
54
|
+
s.rubygems_version = "2.7.9".freeze
|
|
55
55
|
s.summary = "CKnife".freeze
|
|
56
56
|
|
|
57
57
|
if s.respond_to? :specification_version then
|
|
58
58
|
s.specification_version = 4
|
|
59
59
|
|
|
60
60
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
61
|
-
s.add_runtime_dependency(%q<rest-client>.freeze, ["
|
|
62
|
-
s.add_runtime_dependency(%q<nokogiri>.freeze, ["
|
|
61
|
+
s.add_runtime_dependency(%q<rest-client>.freeze, ["~> 1", ">= 1.8.0"])
|
|
62
|
+
s.add_runtime_dependency(%q<nokogiri>.freeze, ["~> 1", ">= 1.10.4"])
|
|
63
63
|
s.add_runtime_dependency(%q<i18n>.freeze, [">= 0.6.6"])
|
|
64
64
|
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.2.9"])
|
|
65
65
|
s.add_runtime_dependency(%q<actionpack>.freeze, [">= 4.2.9"])
|
|
66
66
|
s.add_runtime_dependency(%q<mail>.freeze, ["~> 2.5.5"])
|
|
67
|
-
s.add_runtime_dependency(%q<thor>.freeze, ["
|
|
67
|
+
s.add_runtime_dependency(%q<thor>.freeze, ["~> 0", ">= 0.14"])
|
|
68
68
|
s.add_runtime_dependency(%q<builder>.freeze, ["~> 3.0"])
|
|
69
69
|
s.add_runtime_dependency(%q<fog-aws>.freeze, ["< 3.0"])
|
|
70
|
-
s.add_runtime_dependency(%q<unf>.freeze, ["
|
|
70
|
+
s.add_runtime_dependency(%q<unf>.freeze, ["~> 0", ">= 0.1"])
|
|
71
71
|
s.add_runtime_dependency(%q<daemons>.freeze, [">= 0"])
|
|
72
|
+
s.add_runtime_dependency(%q<loofah>.freeze, ["~> 2.2.3"])
|
|
72
73
|
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
|
73
74
|
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.1"])
|
|
74
75
|
else
|
|
75
|
-
s.add_dependency(%q<rest-client>.freeze, ["
|
|
76
|
-
s.add_dependency(%q<nokogiri>.freeze, ["
|
|
76
|
+
s.add_dependency(%q<rest-client>.freeze, ["~> 1", ">= 1.8.0"])
|
|
77
|
+
s.add_dependency(%q<nokogiri>.freeze, ["~> 1", ">= 1.10.4"])
|
|
77
78
|
s.add_dependency(%q<i18n>.freeze, [">= 0.6.6"])
|
|
78
79
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.2.9"])
|
|
79
80
|
s.add_dependency(%q<actionpack>.freeze, [">= 4.2.9"])
|
|
80
81
|
s.add_dependency(%q<mail>.freeze, ["~> 2.5.5"])
|
|
81
|
-
s.add_dependency(%q<thor>.freeze, ["
|
|
82
|
+
s.add_dependency(%q<thor>.freeze, ["~> 0", ">= 0.14"])
|
|
82
83
|
s.add_dependency(%q<builder>.freeze, ["~> 3.0"])
|
|
83
84
|
s.add_dependency(%q<fog-aws>.freeze, ["< 3.0"])
|
|
84
|
-
s.add_dependency(%q<unf>.freeze, ["
|
|
85
|
+
s.add_dependency(%q<unf>.freeze, ["~> 0", ">= 0.1"])
|
|
85
86
|
s.add_dependency(%q<daemons>.freeze, [">= 0"])
|
|
87
|
+
s.add_dependency(%q<loofah>.freeze, ["~> 2.2.3"])
|
|
86
88
|
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
|
87
89
|
s.add_dependency(%q<jeweler>.freeze, ["~> 2.1"])
|
|
88
90
|
end
|
|
89
91
|
else
|
|
90
|
-
s.add_dependency(%q<rest-client>.freeze, ["
|
|
91
|
-
s.add_dependency(%q<nokogiri>.freeze, ["
|
|
92
|
+
s.add_dependency(%q<rest-client>.freeze, ["~> 1", ">= 1.8.0"])
|
|
93
|
+
s.add_dependency(%q<nokogiri>.freeze, ["~> 1", ">= 1.10.4"])
|
|
92
94
|
s.add_dependency(%q<i18n>.freeze, [">= 0.6.6"])
|
|
93
95
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.2.9"])
|
|
94
96
|
s.add_dependency(%q<actionpack>.freeze, [">= 4.2.9"])
|
|
95
97
|
s.add_dependency(%q<mail>.freeze, ["~> 2.5.5"])
|
|
96
|
-
s.add_dependency(%q<thor>.freeze, ["
|
|
98
|
+
s.add_dependency(%q<thor>.freeze, ["~> 0", ">= 0.14"])
|
|
97
99
|
s.add_dependency(%q<builder>.freeze, ["~> 3.0"])
|
|
98
100
|
s.add_dependency(%q<fog-aws>.freeze, ["< 3.0"])
|
|
99
|
-
s.add_dependency(%q<unf>.freeze, ["
|
|
101
|
+
s.add_dependency(%q<unf>.freeze, ["~> 0", ">= 0.1"])
|
|
100
102
|
s.add_dependency(%q<daemons>.freeze, [">= 0"])
|
|
103
|
+
s.add_dependency(%q<loofah>.freeze, ["~> 2.2.3"])
|
|
101
104
|
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
|
102
105
|
s.add_dependency(%q<jeweler>.freeze, ["~> 2.1"])
|
|
103
106
|
end
|
data/lib/cknife/cknife_mysql.rb
CHANGED
|
@@ -6,6 +6,8 @@ require 'cknife/command_line'
|
|
|
6
6
|
module CKnife
|
|
7
7
|
class CKnifeMysql < Thor
|
|
8
8
|
|
|
9
|
+
class_option :verbose, :default => false, :type => :boolean, :desc => "Show which commands are invoked, any input given to them, and any output they give back."
|
|
10
|
+
|
|
9
11
|
no_tasks do
|
|
10
12
|
def config
|
|
11
13
|
@config ||= Config
|
|
@@ -30,8 +32,38 @@ module CKnife
|
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def command_line
|
|
33
|
-
@command_line ||= CommandLine.new(option_file, "[client]\npassword=\"#{conf[:password]}\"", self)
|
|
35
|
+
@command_line ||= CommandLine.new(option_file, "[client]\npassword=\"#{conf[:password]}\"", self, options)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def mysql_easy
|
|
39
|
+
"mysql #{connection_options} #{conf[:database]}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
desc "console", "Launch mysql console."
|
|
44
|
+
method_option :myfile, :type => :boolean, :default => false, :desc => "Write my.cnf file if it doesn't exist."
|
|
45
|
+
def console
|
|
46
|
+
if !File.exists?(option_file)
|
|
47
|
+
if !options[:myfile]
|
|
48
|
+
say("You must prepare a #{option_file} file for this command, or use --myfile to have this tool create it for you. Alternatively, you can create a #{option_file} file with the myfile command and delete it later with the dmyfile command.")
|
|
49
|
+
return
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
command_line.write_option_file
|
|
34
53
|
end
|
|
54
|
+
|
|
55
|
+
dc(mysql_easy) if options[:verbose]
|
|
56
|
+
exec(mysql_easy)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
desc "myfile", "Write a my.cnf file in $CWD. Useful for starting a mysql session on your own."
|
|
60
|
+
def myfile
|
|
61
|
+
command_line.create_opt_file("Connect command: #{mysql_easy}")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc "dmyfile", "Delete the my.cnf file in $CWD, assuming it exactly matches what would be generated by this tool."
|
|
65
|
+
def dmyfile
|
|
66
|
+
command_line.delete_opt_file
|
|
35
67
|
end
|
|
36
68
|
|
|
37
69
|
desc "capture", "Capture a dump of the database to db(current timestamp).sql."
|
data/lib/cknife/cknife_pg.rb
CHANGED
|
@@ -36,6 +36,7 @@ class CKnifePg < Thor
|
|
|
36
36
|
@pg_pass_file = ".pgpass"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# dump command?
|
|
39
40
|
def dc(cmd)
|
|
40
41
|
puts "PGPASSFILE=#{pg_pass_file} #{cmd}"
|
|
41
42
|
end
|
|
@@ -304,7 +305,7 @@ AND
|
|
|
304
305
|
return
|
|
305
306
|
end
|
|
306
307
|
|
|
307
|
-
|
|
308
|
+
write_pg_pass_file
|
|
308
309
|
say("Wrote #{pg_pass_file} to $CWD.")
|
|
309
310
|
say(connect_msg)
|
|
310
311
|
say("Remember to delete the .pgpass file when you are finished.")
|
data/lib/cknife/command_line.rb
CHANGED
|
@@ -1,31 +1,76 @@
|
|
|
1
1
|
module CKnife
|
|
2
2
|
class CommandLine
|
|
3
3
|
|
|
4
|
-
attr_accessor :option_file, :option_file_contents, :thor_output
|
|
4
|
+
attr_accessor :option_file, :option_file_contents, :thor_output, :options
|
|
5
5
|
|
|
6
|
-
def initialize(f, s, o)
|
|
6
|
+
def initialize(f, s, o, opts)
|
|
7
7
|
self.option_file = f
|
|
8
8
|
self.option_file_contents = s
|
|
9
9
|
self.thor_output = o
|
|
10
|
+
self.options = opts
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# dump command?
|
|
14
|
+
def dc(cmd)
|
|
15
|
+
puts "PGPASSFILE=#{pg_pass_file} #{cmd}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def write_option_file
|
|
19
|
+
File.open(option_file, "w", 0600) { |f| f.write option_file_contents }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete_opt_file
|
|
23
|
+
if !File.exists?(option_file)
|
|
24
|
+
thor_output.say("No #{option_file} file to delete.")
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
s = File.read(option_file)
|
|
29
|
+
if s == option_file_contents
|
|
30
|
+
File.unlink(option_file)
|
|
31
|
+
thor_output.say("Deleted #{option_file} file.")
|
|
32
|
+
else
|
|
33
|
+
thor_output.say("The #{option_file} file's contents do not match what this tool would have generated. Assuming you are trying to delete a #{option_file} file that this tool did not generate, please inspect the file to ensure it contains what you expect, and then delete it yourself.", :red)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def create_opt_file(connect_msg)
|
|
38
|
+
if File.exists?(option_file)
|
|
39
|
+
thor_output.say("A #{option_file} file is already present.")
|
|
40
|
+
thor_output.say(connect_msg)
|
|
41
|
+
return
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
write_option_file
|
|
45
|
+
thor_output.say("Wrote #{option_file} to $CWD.")
|
|
46
|
+
thor_output.say(connect_msg)
|
|
47
|
+
thor_output.say("Remember to delete the #{option_file} file when you are finished.")
|
|
10
48
|
end
|
|
11
49
|
|
|
12
50
|
def execute(cmd, input = nil)
|
|
13
51
|
return if !@session_ok
|
|
14
|
-
|
|
52
|
+
dc(cmd) if options[:verbose]
|
|
15
53
|
stdin, stdout, stderr, wait_thread = Open3.popen3(cmd)
|
|
16
54
|
if input
|
|
17
|
-
puts input
|
|
55
|
+
puts input if options[:verbose]
|
|
18
56
|
stdin.write input
|
|
19
57
|
stdin.close
|
|
20
58
|
end
|
|
21
59
|
output = stdout.read
|
|
22
60
|
output += stderr.read
|
|
23
|
-
$stdout.write output
|
|
61
|
+
$stdout.write output if options[:verbose]
|
|
24
62
|
stdout.close
|
|
25
63
|
stderr.close
|
|
26
64
|
result = wait_thread.value.to_i
|
|
27
|
-
|
|
28
|
-
|
|
65
|
+
|
|
66
|
+
if result != 0
|
|
67
|
+
@session_ok = false
|
|
68
|
+
msg = "An error occurred."
|
|
69
|
+
msg += " If the --verbose flag is available for this command, you may try turning it on." if !options[:verbose]
|
|
70
|
+
thor_output.say(msg, :red)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
yield if block_given?
|
|
29
74
|
output
|
|
30
75
|
end
|
|
31
76
|
|
|
@@ -37,24 +82,33 @@ module CKnife
|
|
|
37
82
|
@session_live = true
|
|
38
83
|
@session_ok = true
|
|
39
84
|
|
|
85
|
+
existing_option_file = false
|
|
40
86
|
if File.exists?(option_file)
|
|
41
|
-
|
|
42
|
-
|
|
87
|
+
existing_option_file = true
|
|
88
|
+
s = File.read(option_file)
|
|
89
|
+
if s != option_file_contents
|
|
90
|
+
thor_output.say("A #{option_file} file is present, but it does not match your database configuration. The contents of the #{option_file} file must exactly match what this tool would generate. Please reconcile the #{option_file} file with your configuration, and then try again. You can also delete the #{option_file} file since this tool generates one in order to do its job (and removes it after finishing).", :red)
|
|
91
|
+
return
|
|
92
|
+
end
|
|
43
93
|
end
|
|
44
94
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
result = yield self
|
|
95
|
+
write_option_file
|
|
48
96
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
97
|
+
result = nil
|
|
98
|
+
begin
|
|
99
|
+
result = yield self # don't know what we're planning to do with the result here...
|
|
100
|
+
ensure
|
|
101
|
+
if !existing_option_file
|
|
102
|
+
FileUtils.rm(option_file)
|
|
103
|
+
if File.exists?(option_file)
|
|
104
|
+
thor_output.say("Failed to remove #{option_file} file. Please remove it for your infrastructure's security.")
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
thor_output.say("Left existing #{option_file} file on disk.", :yellow)
|
|
108
|
+
end
|
|
52
109
|
end
|
|
53
110
|
|
|
54
|
-
thor_output.say
|
|
55
|
-
thor_output.say("Command failed.", :red) if !@session_ok
|
|
56
111
|
@session_live = false
|
|
57
|
-
|
|
58
112
|
result
|
|
59
113
|
end
|
|
60
114
|
end
|
metadata
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cknife
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Rivera
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-08-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.8.0
|
|
20
17
|
- - "~>"
|
|
21
18
|
- !ruby/object:Gem::Version
|
|
22
19
|
version: '1'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.8.0
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
|
-
- - ">="
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: 1.8.0
|
|
30
27
|
- - "~>"
|
|
31
28
|
- !ruby/object:Gem::Version
|
|
32
29
|
version: '1'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.8.0
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: nokogiri
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: 1.8.2
|
|
40
37
|
- - "~>"
|
|
41
38
|
- !ruby/object:Gem::Version
|
|
42
39
|
version: '1'
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 1.10.4
|
|
43
43
|
type: :runtime
|
|
44
44
|
prerelease: false
|
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
|
-
- - ">="
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: 1.8.2
|
|
50
47
|
- - "~>"
|
|
51
48
|
- !ruby/object:Gem::Version
|
|
52
49
|
version: '1'
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 1.10.4
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
|
54
54
|
name: i18n
|
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -110,22 +110,22 @@ dependencies:
|
|
|
110
110
|
name: thor
|
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
|
112
112
|
requirements:
|
|
113
|
-
- - ">="
|
|
114
|
-
- !ruby/object:Gem::Version
|
|
115
|
-
version: '0.14'
|
|
116
113
|
- - "~>"
|
|
117
114
|
- !ruby/object:Gem::Version
|
|
118
115
|
version: '0'
|
|
116
|
+
- - ">="
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0.14'
|
|
119
119
|
type: :runtime
|
|
120
120
|
prerelease: false
|
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
122
|
requirements:
|
|
123
|
-
- - ">="
|
|
124
|
-
- !ruby/object:Gem::Version
|
|
125
|
-
version: '0.14'
|
|
126
123
|
- - "~>"
|
|
127
124
|
- !ruby/object:Gem::Version
|
|
128
125
|
version: '0'
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: '0.14'
|
|
129
129
|
- !ruby/object:Gem::Dependency
|
|
130
130
|
name: builder
|
|
131
131
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -158,22 +158,22 @@ dependencies:
|
|
|
158
158
|
name: unf
|
|
159
159
|
requirement: !ruby/object:Gem::Requirement
|
|
160
160
|
requirements:
|
|
161
|
-
- - ">="
|
|
162
|
-
- !ruby/object:Gem::Version
|
|
163
|
-
version: '0.1'
|
|
164
161
|
- - "~>"
|
|
165
162
|
- !ruby/object:Gem::Version
|
|
166
163
|
version: '0'
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0.1'
|
|
167
167
|
type: :runtime
|
|
168
168
|
prerelease: false
|
|
169
169
|
version_requirements: !ruby/object:Gem::Requirement
|
|
170
170
|
requirements:
|
|
171
|
-
- - ">="
|
|
172
|
-
- !ruby/object:Gem::Version
|
|
173
|
-
version: '0.1'
|
|
174
171
|
- - "~>"
|
|
175
172
|
- !ruby/object:Gem::Version
|
|
176
173
|
version: '0'
|
|
174
|
+
- - ">="
|
|
175
|
+
- !ruby/object:Gem::Version
|
|
176
|
+
version: '0.1'
|
|
177
177
|
- !ruby/object:Gem::Dependency
|
|
178
178
|
name: daemons
|
|
179
179
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -188,6 +188,20 @@ dependencies:
|
|
|
188
188
|
- - ">="
|
|
189
189
|
- !ruby/object:Gem::Version
|
|
190
190
|
version: '0'
|
|
191
|
+
- !ruby/object:Gem::Dependency
|
|
192
|
+
name: loofah
|
|
193
|
+
requirement: !ruby/object:Gem::Requirement
|
|
194
|
+
requirements:
|
|
195
|
+
- - "~>"
|
|
196
|
+
- !ruby/object:Gem::Version
|
|
197
|
+
version: 2.2.3
|
|
198
|
+
type: :runtime
|
|
199
|
+
prerelease: false
|
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
201
|
+
requirements:
|
|
202
|
+
- - "~>"
|
|
203
|
+
- !ruby/object:Gem::Version
|
|
204
|
+
version: 2.2.3
|
|
191
205
|
- !ruby/object:Gem::Dependency
|
|
192
206
|
name: bundler
|
|
193
207
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -280,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
280
294
|
version: '0'
|
|
281
295
|
requirements: []
|
|
282
296
|
rubyforge_project:
|
|
283
|
-
rubygems_version: 2.
|
|
297
|
+
rubygems_version: 2.7.9
|
|
284
298
|
signing_key:
|
|
285
299
|
specification_version: 4
|
|
286
300
|
summary: CKnife
|