Class: Daytona::SecretService

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/daytona/secret_service.rb

Instance Method Summary collapse

Methods included from Instrumentation

included

Constructor Details

#initialize(secret_api, otel_state: nil) ⇒ SecretService

Service for managing organization-scoped Daytona Secrets. Can be used to list, get, create, update and delete Secrets.

A Secret stores a plaintext value that is never returned by the API. When a Secret is referenced while creating a Sandbox, the corresponding env var holds an opaque placeholder that is resolved to the real value only for the Secret’s allowed hosts.

Parameters:

  • secret_api (DaytonaApiClient::SecretApi)
  • otel_state (Daytona::OtelState, nil) (defaults to: nil)


19
20
21
22
# File 'lib/daytona/secret_service.rb', line 19

def initialize(secret_api, otel_state: nil)
  @secret_api = secret_api
  @otel_state = otel_state
end

Instance Method Details

#create(name, value, description: nil, hosts: nil) ⇒ Daytona::Secret

Create a new Secret.

Parameters:

  • name (String)

    Name of the Secret. Must match ^[a-zA-Z_]*$ and be unique within the organization (a duplicate name raises a 409 error).

  • value (String)

    Plaintext value of the Secret. Write-only; never returned by the API.

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

    Optional description of the Secret.

  • hosts (Array<String>, nil) (defaults to: nil)

    Allowed hosts this Secret may be sent to. Accepts exact hostnames and *. wildcards (no ports).

Returns:



33
34
35
36
37
# File 'lib/daytona/secret_service.rb', line 33

def create(name, value, description: nil, hosts: nil)
  Secret.new(secret_api.create_secret(
               DaytonaApiClient::CreateSecret.new(name:, value:, description:, hosts:)
             ))
end

#delete(secret_id) ⇒ void

This method returns an undefined value.

Delete a Secret.

Parameters:

  • secret_id (String)

Raises:

  • (DaytonaApiClient::ApiError)

    If no Secret with the given ID exists (404).



44
# File 'lib/daytona/secret_service.rb', line 44

def delete(secret_id) = secret_api.delete_secret(secret_id)

#get(secret_id) ⇒ Daytona::Secret

Get a Secret by ID.

Parameters:

  • secret_id (String)

Returns:

Raises:

  • (DaytonaApiClient::ApiError)

    If no Secret with the given ID exists (404).



51
# File 'lib/daytona/secret_service.rb', line 51

def get(secret_id) = Secret.new(secret_api.get_secret(secret_id))

#listArray<Daytona::Secret>

List all Secrets.

Returns:



56
57
58
# File 'lib/daytona/secret_service.rb', line 56

def list
  secret_api.list_secrets.map { |secret| Secret.new(secret) }
end

#update(secret_id, value: nil, description: nil, hosts: nil) ⇒ Daytona::Secret

Update a Secret.

Parameters:

  • secret_id (String)
  • value (String, nil) (defaults to: nil)

    New plaintext value. Write-only; never returned by the API.

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

    New description of the Secret.

  • hosts (Array<String>, nil) (defaults to: nil)

    Allowed hosts this Secret may be sent to. Accepts exact hostnames and *. wildcards (no ports).

Returns:

Raises:

  • (DaytonaApiClient::ApiError)

    If no Secret with the given ID exists (404).



69
70
71
72
73
74
# File 'lib/daytona/secret_service.rb', line 69

def update(secret_id, value: nil, description: nil, hosts: nil)
  Secret.new(secret_api.update_secret(
               secret_id,
               DaytonaApiClient::UpdateSecret.new(value:, description:, hosts:)
             ))
end