Class: Daytona::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/daytona/config.rb

Constant Summary collapse

API_URL =
'https://app.daytona.io/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, jwt_token: nil, api_url: nil, organization_id: nil, target: nil, otel_enabled: nil, use_deprecated_polling: nil, _experimental: nil) ⇒ Config

Initializes a new Daytona::Config object.

Parameters:

  • api_key (String, nil) (defaults to: nil)

    Daytona API key. Defaults to ENV.

  • jwt_token (String, nil) (defaults to: nil)

    Daytona JWT token. Defaults to ENV.

  • api_url (String, nil) (defaults to: nil)

    Daytona API URL. Defaults to ENV or Daytona::Config::API_URL.

  • organization_id (String, nil) (defaults to: nil)

    Daytona organization ID. Defaults to ENV.

  • target (String, nil) (defaults to: nil)

    Daytona target. Defaults to ENV.

  • otel_enabled (Boolean, nil) (defaults to: nil)

    Enable OpenTelemetry tracing for SDK operations.

  • use_deprecated_polling (Boolean, nil) (defaults to: nil)

    Observe sandbox state by legacy polling instead of WebSocket event streaming. Defaults to false (event streaming). Can also be enabled via the DAYTONA_USE_DEPRECATED_POLLING environment variable.

  • _experimental (Hash, nil) (defaults to: nil)

    Experimental configuration options.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/daytona/config.rb', line 108

def initialize( # rubocop:disable Metrics/ParameterLists
  api_key: nil,
  jwt_token: nil,
  api_url: nil,
  organization_id: nil,
  target: nil,
  otel_enabled: nil,
  use_deprecated_polling: nil,
  _experimental: nil
)
  @env_reader = daytona_env_reader

  @api_key = api_key || @env_reader.call('DAYTONA_API_KEY')
  @jwt_token = jwt_token || @env_reader.call('DAYTONA_JWT_TOKEN')
  # Resolved from the process environment only, never from .env / .env.local:
  # the endpoint decides where the credential above is sent.
  @api_url = resolve_api_url(api_url)
  @target = target || @env_reader.call('DAYTONA_TARGET')
  @organization_id = organization_id || @env_reader.call('DAYTONA_ORGANIZATION_ID')
  @otel_enabled = otel_enabled
  @_experimental = _experimental
  @use_deprecated_polling = resolve_use_deprecated_polling(use_deprecated_polling)
end

Instance Attribute Details

#_experimentalHash?

Experimental configuration options

Returns:

  • (Hash, nil)

    Experimental configuration hash



94
95
96
# File 'lib/daytona/config.rb', line 94

def _experimental
  @_experimental
end

#api_keyString?

API key for authentication with the Daytona API

Returns:

  • (String, nil)

    Daytona API key



54
55
56
# File 'lib/daytona/config.rb', line 54

def api_key
  @api_key
end

#api_urlString?

URL of the Daytona API

Returns:

  • (String, nil)

    Daytona API URL



64
65
66
# File 'lib/daytona/config.rb', line 64

def api_url
  @api_url
end

#jwt_tokenString?

JWT token for authentication with the Daytona API

Returns:

  • (String, nil)

    Daytona JWT token



59
60
61
# File 'lib/daytona/config.rb', line 59

def jwt_token
  @jwt_token
end

#organization_idString?

Organization ID for authentication with the Daytona API

Returns:

  • (String, nil)

    Daytona API URL



69
70
71
# File 'lib/daytona/config.rb', line 69

def organization_id
  @organization_id
end

#otel_enabledBoolean?

Enable OpenTelemetry tracing for SDK operations.

Returns:

  • (Boolean, nil)


79
80
81
# File 'lib/daytona/config.rb', line 79

def otel_enabled
  @otel_enabled
end

#targetString?

Target environment for sandboxes

Returns:

  • (String, nil)

    Daytona target



74
75
76
# File 'lib/daytona/config.rb', line 74

def target
  @target
end

#use_deprecated_pollingBoolean

Deprecated.

Polling-only mode will be removed in a future release; event streaming is the default and falls back to polling automatically when WebSockets are unavailable.

Observe sandbox state by legacy polling instead of WebSocket event streaming. Defaults to false (event streaming). Can also be enabled via the DAYTONA_USE_DEPRECATED_POLLING environment variable.

Returns:

  • (Boolean)


89
90
91
# File 'lib/daytona/config.rb', line 89

def use_deprecated_polling
  @use_deprecated_polling
end

Instance Method Details

#read_env(name) ⇒ String?

Reads a DAYTONA_-prefixed environment variable using the same precedence as the Config initializer: runtime ENV first, then .env.local, then .env. Only names starting with DAYTONA_ are accepted.

Parameters:

  • name (String)

    The environment variable name. Must start with DAYTONA_.

Returns:

  • (String, nil)

    The value of the environment variable, or nil if not set.

Raises:

  • (ArgumentError)

    If name does not start with DAYTONA_.



139
140
141
# File 'lib/daytona/config.rb', line 139

def read_env(name)
  @env_reader.call(name)
end