<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright 2014-2016, Chef Software Inc.
# 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.
#

require "mixlib/cli" unless defined?(Mixlib::CLI)
require_relative "../config"
require_relative "../encrypted_data_bag_item/check_encrypted"

class Chef
  class Knife
    module DataBagSecretOptions
      include Mixlib::CLI
      include Chef::EncryptedDataBagItem::CheckEncrypted

      # The config object is populated by knife#merge_configs with knife.rb `knife[:*]` config values, but they do
      # not overwrite the command line properties.  It does mean, however, that `knife[:secret]` and `--secret-file`
      # passed at the same time populate both `config[:secret]` and `config[:secret_file]`.  We cannot differentiate
      # the valid case (`knife[:secret]` in config file and `--secret-file` on CL) and the invalid case (`--secret`
      # and `--secret-file` on the CL) - thats why I'm storing the CL options in a different config key if they
      # are provided.

      def self.included(base)
        base.option :secret,
          short: "-s SECRET",
          long: "--secret ",
          description: "The secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret'.",
          # Need to store value from command line in separate variable - knife#merge_configs populates same keys
          # on config object from
          proc: Proc.new { |s| set_cl_secret(s) }

        base.option :secret_file,
          long: "--secret-file SECRET_FILE",
          description: "A file containing the secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret_file'.",
          proc: Proc.new { |sf| set_cl_secret_file(sf) }

        base.option :encrypt,
          long: "--encrypt",
          description: "If 'secret' or 'secret_file' is present in your config, then encrypt data bags using it.",
          boolean: true,
          default: false
      end

      def encryption_secret_provided?
        base_encryption_secret_provided?
      end<commit_msg>Remove data bag secret (-s) short option<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright 2014-2016, Chef Software Inc.
# 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.
#

require "mixlib/cli" unless defined?(Mixlib::CLI)
require_relative "../config"
require_relative "../encrypted_data_bag_item/check_encrypted"

class Chef
  class Knife
    module DataBagSecretOptions
      include Mixlib::CLI
      include Chef::EncryptedDataBagItem::CheckEncrypted

      # The config object is populated by knife#merge_configs with knife.rb `knife[:*]` config values, but they do
      # not overwrite the command line properties.  It does mean, however, that `knife[:secret]` and `--secret-file`
      # passed at the same time populate both `config[:secret]` and `config[:secret_file]`.  We cannot differentiate
      # the valid case (`knife[:secret]` in config file and `--secret-file` on CL) and the invalid case (`--secret`
      # and `--secret-file` on the CL) - thats why I'm storing the CL options in a different config key if they
      # are provided.

      def self.included(base)
        base.option :secret,
          long: "--secret SECRET",
          description: "The secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret'.",
          # Need to store value from command line in separate variable - knife#merge_configs populates same keys
          # on config object from
          proc: Proc.new { |s| set_cl_secret(s) }

        base.option :secret_file,
          long: "--secret-file SECRET_FILE",
          description: "A file containing the secret key to use to encrypt data bag item values. Can also be defaulted in your config with the key 'secret_file'.",
          proc: Proc.new { |sf| set_cl_secret_file(sf) }

        base.option :encrypt,
          long: "--encrypt",
          description: "If 'secret' or 'secret_file' is present in your config, then encrypt data bags using it.",
          boolean: true,
          default: false
      end

      def encryption_secret_provided?
        base_encryption_secret_provided?
      end
{'fraction_non_alphanumeric': 0.08959700093720713, 'fraction_numerical': 0.005248359887535145, 'mean_word_length': 3.123647604327666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2354204', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1415, 'n_words': 621}