Sha256: f13903c6c2e127eb0ae4a5dde353b4ec2f7e8d249593cbd2d475aa008bb3d9a2

Contents?: true

Size: 1.7 KB

Versions: 49

Compression:

Stored size: 1.7 KB

Contents

# -*- encoding : utf-8 -*-
module Reactor
  module Cm
    class Bridge
      # credit goes to Anton
      def self.login_for(sessionId)
        old_username = Reactor::Configuration.xml_access[:username]
        Reactor::Configuration.xml_access[:username] = 'root'
        begin
          response = Reactor::Cm::XmlRequest.prepare do |xml|
            xml.tag!('licenseManager-logins')
          end.execute!
          login = nil
          result = response.xpath('//licenseManager-logins/listitem')
          result = [result] unless result.kind_of?(Array)
          result.each do |login_data_element|
            properties = deserialize_login_data(login_data_element.text)
            if properties[:sessionId] == sessionId && properties[:interface] == "X"
              login = properties[:login]
              break
            end
          end
          login
        rescue => e
          Rails.logger.error "Login to CM failed! #{e.class}: #{e.message}"
          nil
        ensure
          Reactor::Configuration.xml_access[:username] = old_username
        end
      end

      private
      def self.deserialize_login_data(serialized_property_list)
        entry_delimiter = /;\r?\n/
        no_braces = serialized_property_list[1..(serialized_property_list.rindex(entry_delimiter) - 1)]
        property_list_lines = no_braces.split(entry_delimiter)
        property_list_lines.inject(properties = {}) do |map, line|
          key, value = line.strip.scan(/^([^=]*) = (.*)$/).first
          if value[0..0] == '"'
            value = value[1..(value.length - 2)]
            value.gsub!(/\\(.)/, '\1')
          end
          map[key.to_sym] = value
          map
        end
        properties
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
infopark_reactor-1.26.1 lib/reactor/cm/bridge.rb
infopark_reactor-1.26.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.25.2 lib/reactor/cm/bridge.rb
infopark_reactor-1.25.1 lib/reactor/cm/bridge.rb
infopark_reactor-1.25.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.24.1 lib/reactor/cm/bridge.rb
infopark_reactor-1.24.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.23.1 lib/reactor/cm/bridge.rb
infopark_reactor-1.23.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.23.0.beta2 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.6 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.5 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.4 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.3 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.2 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.1 lib/reactor/cm/bridge.rb
infopark_reactor-1.22.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.21.0 lib/reactor/cm/bridge.rb
infopark_reactor-1.20.4 lib/reactor/cm/bridge.rb
infopark_reactor-1.20.3 lib/reactor/cm/bridge.rb