Class: Rhoconnect::License

Inherits:
Object
  • Object
show all
Defined in:
lib/rhoconnect/license.rb

Constant Summary collapse

RHO_PUBLICKEY =

ships with rhoconnect

"99068e3a2708e6fe918252be8880eac539a1d2b2402651d75de5c7a2333a1cb2"
CLIENT_DOCKEY =
'rho_client_count'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLicense

Returns a new instance of License.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rhoconnect/license.rb', line 16

def initialize
  begin
    if ENV['RHOCONNECT_LICENSE']
      @license = ENV['RHOCONNECT_LICENSE']
    elsif ENV['RHOSYNC_LICENSE']
      @license = ENV['RHOSYNC_LICENSE']
    else
      app_config = Rhoconnect.get_config(Rhoconnect.base_directory)
      settings = Rhoconnect.get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
      licensefile = settings[:licensefile] 
      if licensefile
        path_to_license = (Pathname.new(licensefile).absolute?) ? licensefile : File.join(Rhoconnect.base_directory, licensefile)
      else
        path_to_license = File.join(File.dirname(__FILE__), '..', '..', 'generators', 'templates', 'application', 'settings', 'license.key')
      end
      @license = IO.read(path_to_license).strip
    end
    _decrypt
  rescue Exception => e
    log e.message
    log e.backtrace.join("\n")
    raise LicenseException.new("Error verifying license.")
  end
end

Instance Attribute Details

#issuedObject (readonly)

Returns the value of attribute issued.



9
10
11
# File 'lib/rhoconnect/license.rb', line 9

def issued
  @issued
end

#licenseObject

Returns the value of attribute license.



10
11
12
# File 'lib/rhoconnect/license.rb', line 10

def license
  @license
end

#licenseeObject (readonly)

Returns the value of attribute licensee.



9
10
11
# File 'lib/rhoconnect/license.rb', line 9

def licensee
  @licensee
end

#rhoconnect_versionObject (readonly)

Returns the value of attribute rhoconnect_version.



9
10
11
# File 'lib/rhoconnect/license.rb', line 9

def rhoconnect_version
  @rhoconnect_version
end

#seatsObject (readonly)

Returns the value of attribute seats.



9
10
11
# File 'lib/rhoconnect/license.rb', line 9

def seats
  @seats
end

Instance Method Details

#availableObject



67
68
69
70
71
72
# File 'lib/rhoconnect/license.rb', line 67

def available
  current = Store.get_value(CLIENT_DOCKEY)
  current = current ? current.to_i : 0
  available = self.seats - current
  available > 0 ? available : 0
end

#check_and_use_seatObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rhoconnect/license.rb', line 41

def check_and_use_seat
  incr = false
  Store.lock(CLIENT_DOCKEY) do
    current = Store.get_value(CLIENT_DOCKEY)
    current = current ? current.to_i : 0
    if current < self.seats
      Store.put_value CLIENT_DOCKEY, current + 1
      incr = true
    end
  end
  unless incr
    msg = "WARNING: Maximum # of devices exceeded for this license."
    log msg; raise LicenseSeatsExceededException.new(msg)
  end
end

#free_seatObject



57
58
59
60
61
62
63
64
65
# File 'lib/rhoconnect/license.rb', line 57

def free_seat
  Store.lock(CLIENT_DOCKEY) do
    current = Store.get_value(CLIENT_DOCKEY)
    current = current ? current.to_i : 0
    if current > 0
      Store.put_value CLIENT_DOCKEY, current - 1
    end
  end
end