|
| 1 | +# |
| 2 | +# Author:: Adam Jacob (<adam@opscode.com>) |
| 3 | +# Copyright:: Copyright (c) 2009 Opscode, Inc. |
| 4 | +# License:: Apache License, Version 2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +require 'chef/knife' |
| 20 | + |
| 21 | +class Chef |
| 22 | + class Knife |
| 23 | + class ConfigureClient < Knife |
| 24 | + banner "Sub-Command: configure client DIRECTORY" |
| 25 | + |
| 26 | + def run |
| 27 | + raise ArgumentError, "You must provide the directory to put the files in" unless @name_args[0] |
| 28 | + Chef::Log.info("Creating client configuration") |
| 29 | + system("mkdir -p #{@name_args[0]}") |
| 30 | + Chef::Log.info("Writing client.rb") |
| 31 | + File.open(File.join(@name_args[0], "client.rb"), "w") do |file| |
| 32 | + file.puts('log_level :info') |
| 33 | + file.puts('log_location STDOUT') |
| 34 | + file.puts("chef_server_url '#{Chef::Config[:chef_server_url]}'") |
| 35 | + file.puts("validation_client_name '#{Chef::Config[:validation_client_name]}'") |
| 36 | + end |
| 37 | + Chef::Log.info("Writing validation.pem") |
| 38 | + system("cp #{Chef::Config[:validation_key]} #{File.join(@name_args[0], 'validation.pem')}") |
| 39 | + end |
| 40 | + |
| 41 | + end |
| 42 | + end |
| 43 | +end |
| 44 | + |
| 45 | + |
0 commit comments