Class: RosettAi::Licensing::LicenseStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/licensing/license_store.rb

Overview

Persists the license key at ~/.config/rosett-ai/license.key with strict file permissions (0600, owned by current uid).

Constant Summary collapse

SAFE_FILE_MODE =

Returns File permission mode for secure files.

Returns:

  • (Object)

    File permission mode for secure files.

0o600
SAFE_DIR_MODE =

Returns Directory permission mode for secure directories.

Returns:

  • (Object)

    Directory permission mode for secure directories.

0o700

Instance Method Summary collapse

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rosett_ai/licensing/license_store.rb', line 42

def exists?
  license_path.exist?
end

#loadLicenseKey?

Load the license key from persistent storage.

Returns:



28
29
30
31
32
33
# File 'lib/rosett_ai/licensing/license_store.rb', line 28

def load
  return nil unless exists?

  validate_permissions!
  File.read(license_path.to_s).chomp
end

#remove!void

This method returns an undefined value.

Remove the stored license key file.



38
39
40
# File 'lib/rosett_ai/licensing/license_store.rb', line 38

def remove!
  File.delete(license_path.to_s) if exists?
end

#save(raw_key) ⇒ void

This method returns an undefined value.

Save the license key to persistent storage.

Parameters:

  • raw_key (Object)

    the raw key



20
21
22
23
24
# File 'lib/rosett_ai/licensing/license_store.rb', line 20

def save(raw_key)
  ensure_parent_directory!
  File.write(license_path.to_s, raw_key, mode: 'w', perm: SAFE_FILE_MODE)
  validate_permissions!
end