Class: Daytona::ObjectStorage
- Inherits:
-
Object
- Object
- Daytona::ObjectStorage
- Defined in:
- lib/daytona/object_storage.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ String
readonly
The name of the S3 bucket used for object storage.
-
#s3_client ⇒ Aws::S3::Client
readonly
The S3 client.
Class Method Summary collapse
-
.compute_archive_base_path(path_str) ⇒ String
Compute the base path for an archive.
Instance Method Summary collapse
-
#initialize(endpoint_url:, aws_access_key_id:, aws_secret_access_key:, aws_session_token:, bucket_name: DEFAULT_BUCKET_NAME, region: DEFAULT_REGION) ⇒ ObjectStorage
constructor
Initialize ObjectStorage with S3-compatible credentials.
-
#upload(path, organization_id, archive_base_path = nil) ⇒ String
Uploads a file to the object storage service.
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
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_name ⇒ String (readonly)
Returns 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_client ⇒ Aws::S3::Client (readonly)
Returns 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).
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
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 |