lib/omniauth/strategies/chef.rb in omniauth-chef-0.2.0 vs lib/omniauth/strategies/chef.rb in omniauth-chef-0.4.1

- old
+ new

@@ -13,25 +13,28 @@ # 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 'chef' +require 'chef/config' require 'omniauth' module OmniAuth module Strategies class Chef include OmniAuth::Strategy option :endpoint, 'https://api.opscode.piab' + option :ssl_verify_mode, :verify_peer option :fields, [:name, :password] option :headers, { } option :organization, nil option :resource, 'authenticate_user' option :source, 'web' option :superuser, 'pivotal' option :key_path, '../../../../config/webui_priv.pem' + option :key_data, nil option :uid, :name def callback_phase @user = authenticated_user @@ -78,11 +81,12 @@ def authenticated? @user ? true : false end def chef - ::Chef::REST.new endpoint, options.superuser, nil, parameters + ::Chef::Config.ssl_verify_mode options.ssl_verify_mode.to_sym + ::Chef::ServerAPI.new endpoint, parameters end def endpoint organization ? "#{options.endpoint}/#{organization}" : options.endpoint end @@ -90,18 +94,21 @@ def headers options.headers.merge({ 'x-ops-request-source' => options.source }) end def key - IO.read(File.expand_path(options.key_path, __FILE__)).strip + options.key_data || IO.read(File.expand_path(options.key_path, __FILE__)).strip end def organization options.organization end def parameters - { headers: headers, raw_key: key } + { headers: headers, + client_name: options.superuser, + client_key: nil, + raw_key: key } end def password options.password ? options.password : request[:password] end