Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roll back knife[:secret] and knife[:secret_file] stuff - this does no…
…t match behavior in mainline, and it'd be nice to create files (in the future) without encryption/decryption being the default behavior. Also, add in "knife file create." Initial whack at getting an interactive file creation thing going.
- Loading branch information
Showing
5 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# | ||
# Author:: Christian Paredes <cp@redbluemagenta.com> | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
class Chef | ||
class Knife | ||
class FileCreate < Knife | ||
|
||
deps do | ||
require 'chef/encrypted_data_bag_item' | ||
require 'chef/data_bag' | ||
end | ||
|
||
banner "knife file create ITEM [options]" | ||
|
||
option :secret, | ||
:short => "-s SECRET", | ||
:long => "--secret ", | ||
:description => "The secret key to use to encrypt data bag item values" | ||
|
||
option :secret_file, | ||
:long => "--secret-file SECRET_FILE", | ||
:description => "A file containing the secret key to use to encrypt data bag item values" | ||
|
||
def read_secret | ||
if config[:secret] | ||
config[:secret] | ||
else | ||
Chef::EncryptedDataBagItem.load_secret(config[:secret_file]) | ||
end | ||
end | ||
|
||
def use_encryption | ||
if config[:secret] && config[:secret_file] | ||
stdout.puts "please specify only one of --secret, --secret-file" | ||
exit(1) | ||
end | ||
config[:secret] || config[:secret_file] | ||
end | ||
|
||
def run | ||
@item_name = @name_args | ||
if @item_name.nil? | ||
stdout.puts opt_parser | ||
exit(1) | ||
end | ||
|
||
create_object({ "id" => @item_name }, "encrypted_file[#{@item_name}.json]") do |output_user| | ||
item = Chef::DataBagItem.from_hash( | ||
if use_encryption | ||
Chef::EncryptedDataBagItem.encrypt_data_bag_item(output_user, secret) | ||
else | ||
output_user | ||
end) | ||
item.data_bag(@item_name) | ||
output(format_for_display(item.to_hash)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module Knife | ||
module File | ||
VERSION = "0.1.5" | ||
VERSION = "0.1.6" | ||
MAJOR, MINOR, TINY = VERSION.split('.') | ||
end | ||
end |