Class: Rexec::FileService

Inherits:
Object
  • Object
show all
Defined in:
lib/rexec/file_service.rb

Overview

Service for file operations in containers.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ FileService

Returns a new instance of FileService.



28
29
30
# File 'lib/rexec/file_service.rb', line 28

def initialize(client)
  @client = client
end

Instance Method Details

#delete(container_id, path) ⇒ Object

Delete a file or directory.

Parameters:

  • container_id (String)

    Container ID

  • path (String)

    Path to delete



66
67
68
69
70
# File 'lib/rexec/file_service.rb', line 66

def delete(container_id, path)
  encoded_path = URI.encode_www_form_component(path)
  @client.request(:delete, "/api/containers/#{container_id}/files?path=#{encoded_path}")
  nil
end

#download(container_id, path) ⇒ String

Download a file.

Parameters:

  • container_id (String)

    Container ID

  • path (String)

    File path

Returns:

  • (String)

    File contents



48
49
50
51
# File 'lib/rexec/file_service.rb', line 48

def download(container_id, path)
  encoded_path = URI.encode_www_form_component(path)
  @client.request_bytes(:get, "/api/containers/#{container_id}/files?path=#{encoded_path}")
end

#list(container_id, path = "/") ⇒ Array<FileInfo>

List files in a directory.

Parameters:

  • container_id (String)

    Container ID

  • path (String) (defaults to: "/")

    Directory path

Returns:



37
38
39
40
41
# File 'lib/rexec/file_service.rb', line 37

def list(container_id, path = "/")
  encoded_path = URI.encode_www_form_component(path)
  data = @client.request(:get, "/api/containers/#{container_id}/files/list?path=#{encoded_path}")
  data.map { |f| FileInfo.new(f) }
end

#mkdir(container_id, path) ⇒ Object

Create a directory.

Parameters:

  • container_id (String)

    Container ID

  • path (String)

    Directory path



57
58
59
60
# File 'lib/rexec/file_service.rb', line 57

def mkdir(container_id, path)
  @client.request(:post, "/api/containers/#{container_id}/files/mkdir", body: { path: path })
  nil
end