Class: Daytona::ObjectStorage

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_url:, aws_access_key_id:, aws_secret_access_key:, aws_session_token:, bucket_name: DEFAULT_BUCKET_NAME, region: DEFAULT_REGION) ⇒ ObjectStorage

Initialize ObjectStorage with S3-compatible credentials

Parameters:

  • endpoint_url (String)

    The endpoint URL for the object storage service

  • aws_access_key_id (String)

    The access key ID for the object storage service

  • aws_secret_access_key (String)

    The secret access key for the object storage service

  • aws_session_token (String)

    The session token for the object storage service

  • bucket_name (String) (defaults to: DEFAULT_BUCKET_NAME)

    The name of the bucket to use (defaults to “daytona-volume-builds”)

  • region (String) (defaults to: DEFAULT_REGION)

    AWS region (defaults to us-east-1)



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/daytona/object_storage.rb', line 26

def initialize(endpoint_url:, aws_access_key_id:, aws_secret_access_key:, aws_session_token:, # rubocop:disable Metrics/ParameterLists
               bucket_name: DEFAULT_BUCKET_NAME, region: DEFAULT_REGION)
  @bucket_name = bucket_name
  @s3_client = Aws::S3::Client.new(
    region:,
    endpoint: endpoint_url,
    access_key_id: aws_access_key_id,
    secret_access_key: aws_secret_access_key,
    session_token: aws_session_token
  )
end

Instance Attribute Details

#bucket_nameString (readonly)

Returns The name of the S3 bucket used for object storage.

Returns:

  • (String)

    The name of the S3 bucket used for object storage



13
14
15
# File 'lib/daytona/object_storage.rb', line 13

def bucket_name
  @bucket_name
end

#s3_clientAws::S3::Client (readonly)

Returns The S3 client.

Returns:

  • (Aws::S3::Client)

    The S3 client



16
17
18
# File 'lib/daytona/object_storage.rb', line 16

def s3_client
  @s3_client
end

Class Method Details

.compute_archive_base_path(path_str) ⇒ String

Compute the base path for an archive. Returns normalized path without the root (drive letter or leading slash).

Parameters:

  • path_str (String)

    The path to compute the base path for

Returns:

  • (String)

    The base path for the given path



63
64
65
66
67
68
69
70
71
# File 'lib/daytona/object_storage.rb', line 63

def self.compute_archive_base_path(path_str)
  normalized_path = File.basename(path_str)

  # Remove drive letter for Windows paths (e.g., C:)
  path_without_drive = normalized_path.gsub(/^[A-Za-z]:/, '')

  # Remove leading separators (both / and \)
  path_without_drive.gsub(%r{^[/\\]+}, '')
end

Instance Method Details

#upload(path, organization_id, archive_base_path = nil) ⇒ String

Uploads a file to the object storage service

Parameters:

  • path (String)

    The path to the file to upload

  • organization_id (String)

    The organization ID to use

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

    The base path to use for the archive

Returns:

  • (String)

    The hash of the uploaded file

Raises:

  • (Errno::ENOENT)

    If the path does not exist



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/daytona/object_storage.rb', line 45

def upload(path, organization_id, archive_base_path = nil)
  raise Errno::ENOENT, "Path does not exist: #{path}" unless File.exist?(path)

  path_hash = compute_hash_for_path_md5(path, archive_base_path)
  s3_key = "#{organization_id}/#{path_hash}/context.tar"

  return path_hash if file_exists_in_s3(s3_key)

  upload_as_tar(s3_key, path, archive_base_path)

  path_hash
end