test/lib/testhelper/auth.rb
# TODO: update this as API above so there's only one per keychain.
update this as API above so there's only one per keychain.
update this as API above so there ' s only one per keychain .
def connect_to_db(server: nil, user: nil)
      return if JSS::DB_CNX.connected?
      @db_server = server ? server : JSS::CONFIG.api_server_name
      @db_user = user
      raise 'No db_server_name defined in /etc/ruby-jss.conf. Please specify with --db-server' unless @db_server
      keychain_creds = rw_credentials_from_keychain(:db, @db_server, @db_user)
      if keychain_creds
        @db_user ||= keychain_creds[:user]
        begin
          JSS::DB_CNX.connect server: @db_server, user: @db_user, pw: keychain_creds[:password]
          return
        rescue Mysql::ServerError::AccessDeniedError
          say "Stored MySQL password for #{@db_user}@#{@db_server} is incorrect"
        end 
      else
        raise "No user stored for MySQL server '#{@db_server}'. Please specify with --db-user" unless @db_user
      end
      pw = db_pw
      save_rw_credentials KEYCHAIN_DB_LABEL, @db_user, @db_server, pw
    end
def connect_to_db ( server : nil , user : nil ) return if JSS :: DB_CNX . connected? @db_server = server ? server : JSS :: CONFIG . api_server_name @db_user = user raise 'No db_server_name defined in /etc/ruby-jss.conf. Please specify with --db-server' unless @db_server keychain_creds = rw_credentials_from_keychain ( :db , @db_server , @db_user ) if keychain_creds @db_user ||= keychain_creds [ :user ] begin JSS :: DB_CNX . connect server : @db_server , user : @db_user , pw : keychain_creds [ :password ] return rescue Mysql :: ServerError :: AccessDeniedError say "Stored MySQL password for #{@db_user}@#{@db_server} is incorrect" end else raise "No user stored for MySQL server '#{@db_server}'. Please specify with --db-user" unless @db_user end pw = db_pw save_rw_credentials KEYCHAIN_DB_LABEL , @db_user , @db_server , pw end
TODO: update this as API above so there's only one per keychain.
TODO : update this as API above so there ' s only one per keychain .
# look in the keychain # did we get a user/pw? Use it # re-prompt if bad pw in keychain # begin # Couldn't find a stored user for server, and no user given on CLI - error. # If we're here, we need to get the passwd for the user # store the pw
server
user