Class: Factorix::ServiceCredential

Inherits:
Data
  • Object
show all
Defined in:
lib/factorix/service_credential.rb,
lib/factorix/service_credential.rb

Overview

Service credentials for Factorio MOD downloads

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tokenString (readonly)

Returns Factorio service token.

Returns:

  • (String)

    Factorio service token



12
13
14
# File 'lib/factorix/service_credential.rb', line 12

def token
  @token
end

#usernameString (readonly)

Returns Factorio service username.

Returns:

  • (String)

    Factorio service username



12
13
14
# File 'lib/factorix/service_credential.rb', line 12

def username
  @username
end

Class Method Details

.loadServiceCredential

Load service credentials with automatic source detection

Tries environment variables first, falls back to player-data.json. Raises an error if only one environment variable is set (partial configuration).

Returns:

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/factorix/service_credential.rb', line 33

def self.load
  username_env = ENV.fetch(ENV_USERNAME, nil)
  token_env = ENV.fetch(ENV_TOKEN, nil)

  if username_env && token_env
    from_env
  elsif username_env || token_env
    raise CredentialError, "Both #{ENV_USERNAME} and #{ENV_TOKEN} must be set (or neither)"
  else
    runtime = Container[:runtime]
    from_player_data(runtime:)
  end
end

Instance Method Details

#inspectString Also known as: to_s

Returns string representation with masked credentials.

Returns:

  • (String)

    string representation with masked credentials



119
# File 'lib/factorix/service_credential.rb', line 119

def inspect = %[#<#{self.class} username="*****" token="*****">]

#pretty_print(pp) ⇒ void

This method returns an undefined value.

Parameters:

  • pp (PP)

    pretty printer



125
# File 'lib/factorix/service_credential.rb', line 125

def pretty_print(pp) = pp.text(inspect)