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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rhoconnect/license.rb', line 15

def initialize
  begin
    if ENV['RHOCONNECT_LICENSE']
      @license = ENV['RHOCONNECT_LICENSE']
    elsif ENV['RHOSYNC_LICENSE']
      @license = ENV['RHOSYNC_LICENSE']
    else
      settings = Rhoconnect.get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
      @license = IO.read(File.join(Rhoconnect.base_directory,settings[:licensefile])).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.



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

def issued
  @issued
end

#licenseeObject (readonly)

Returns the value of attribute licensee.



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

def licensee
  @licensee
end

#rhoconnect_versionObject (readonly)

Returns the value of attribute rhoconnect_version.



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

def rhoconnect_version
  @rhoconnect_version
end

#seatsObject (readonly)

Returns the value of attribute seats.



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

def seats
  @seats
end

Instance Method Details

#availableObject



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

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rhoconnect/license.rb', line 33

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



49
50
51
52
53
54
55
56
57
# File 'lib/rhoconnect/license.rb', line 49

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